diff --git a/angel_graphql/README.md b/angel_graphql/README.md index 74683163..bbb1f67c 100644 --- a/angel_graphql/README.md +++ b/angel_graphql/README.md @@ -74,7 +74,7 @@ Future configureServer(Angel app) async { convertDartType(Todo), resolve: resolveViaServiceRead(todoService), inputs: [ - new GraphQLFieldInput('id', graphQLId.nonNullable()), + GraphQLFieldInput('id', graphQLId.nonNullable()), ], ), ], @@ -107,7 +107,7 @@ In *development*, it's also highly recommended to mount the interface, for easy querying and feedback. ```dart -app.all('/graphql', graphQLHttp(new GraphQL(schema))); +app.all('/graphql', graphQLHttp(GraphQL(schema))); app.get('/graphiql', graphiQL()); ``` @@ -116,7 +116,7 @@ All that's left now is just to start the server! ```dart var server = await http.startServer('127.0.0.1', 3000); var uri = - new Uri(scheme: 'http', host: server.address.address, port: server.port); + Uri(scheme: 'http', host: server.address.address, port: server.port); var graphiqlUri = uri.replace(path: 'graphiql'); print('Listening at $uri'); print('Access graphiql at $graphiqlUri'); @@ -214,7 +214,7 @@ var queryType = objectType( convertDartType(Todo), resolve: resolveViaServiceRead(todoService), inputs: [ - new GraphQLFieldInput('id', graphQLId.nonNullable()), + GraphQLFieldInput('id', graphQLId.nonNullable()), ], ), ], diff --git a/angel_graphql/lib/src/graphiql.dart b/angel_graphql/lib/src/graphiql.dart index 6483a768..d64b8b4d 100644 --- a/angel_graphql/lib/src/graphiql.dart +++ b/angel_graphql/lib/src/graphiql.dart @@ -9,7 +9,7 @@ RequestHandler graphiQL( {String graphQLEndpoint = '/graphql', String subscriptionsEndpoint}) { return (req, res) { res - ..contentType = new MediaType('text', 'html') + ..contentType = MediaType('text', 'html') ..write(renderGraphiql( graphqlEndpoint: graphQLEndpoint, subscriptionsEndpoint: subscriptionsEndpoint)) @@ -30,7 +30,7 @@ String renderGraphiql( '''; subscriptionsFetcher = ''' - let subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient('$subscriptionsEndpoint', { + let subscriptionsClient = window.SubscriptionsTransportWs.SubscriptionClient('$subscriptionsEndpoint', { reconnect: true }); let $fetcherName = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher); diff --git a/angel_graphql/lib/src/graphql_http.dart b/angel_graphql/lib/src/graphql_http.dart index 5f71a031..59f787d2 100644 --- a/angel_graphql/lib/src/graphql_http.dart +++ b/angel_graphql/lib/src/graphql_http.dart @@ -7,10 +7,9 @@ import 'package:graphql_parser/graphql_parser.dart'; import 'package:graphql_schema/graphql_schema.dart'; import 'package:graphql_server/graphql_server.dart'; -final ContentType graphQlContentType = - new ContentType('application', 'graphql'); +final ContentType graphQlContentType = ContentType('application', 'graphql'); -final Validator graphQlPostBody = new Validator({ +final Validator graphQlPostBody = Validator({ 'query*': isNonEmptyString, 'operation_name': isNonEmptyString, 'variables': predicate((v) => v == null || v is String || v is Map), @@ -151,29 +150,23 @@ RequestHandler graphQLHttp(GraphQL graphQL, globalVariables: variables, )); } else { - throw new AngelHttpException.badRequest(); + throw AngelHttpException.badRequest(); } } else { - throw new AngelHttpException.badRequest(); + throw AngelHttpException.badRequest(); } } on ValidationException catch (e) { - var errors = [ - new GraphQLExceptionError(e.message) - ]; + var errors = [GraphQLExceptionError(e.message)]; - errors - .addAll(e.errors.map((ee) => new GraphQLExceptionError(ee)).toList()); - return new GraphQLException(errors).toJson(); + errors.addAll(e.errors.map((ee) => GraphQLExceptionError(ee)).toList()); + return GraphQLException(errors).toJson(); } on AngelHttpException catch (e) { - var errors = [ - new GraphQLExceptionError(e.message) - ]; + var errors = [GraphQLExceptionError(e.message)]; - errors - .addAll(e.errors.map((ee) => new GraphQLExceptionError(ee)).toList()); - return new GraphQLException(errors).toJson(); + errors.addAll(e.errors.map((ee) => GraphQLExceptionError(ee)).toList()); + return GraphQLException(errors).toJson(); } on SyntaxError catch (e) { - return new GraphQLException.fromSourceSpan(e.message, e.span); + return GraphQLException.fromSourceSpan(e.message, e.span); } on GraphQLException catch (e) { return e.toJson(); } catch (e, st) { @@ -184,7 +177,7 @@ RequestHandler graphQLHttp(GraphQL graphQL, st); } - return new GraphQLException.fromMessage(e.toString()).toJson(); + return GraphQLException.fromMessage(e.toString()).toJson(); } }; } diff --git a/angel_graphql/lib/src/graphql_ws.dart b/angel_graphql/lib/src/graphql_ws.dart index 0698b65c..89201468 100644 --- a/angel_graphql/lib/src/graphql_ws.dart +++ b/angel_graphql/lib/src/graphql_ws.dart @@ -22,11 +22,12 @@ RequestHandler graphQLWS(GraphQL graphQL, {Duration keepAliveInterval}) { await res.detach(); var socket = await WebSocketTransformer.upgrade(req.rawRequest, protocolSelector: (protocols) { - if (protocols.contains('graphql-ws')) + if (protocols.contains('graphql-ws')) { return 'graphql-ws'; - else + } else { throw AngelHttpException.badRequest( message: 'Only the "graphql-ws" protocol is allowed.'); + } }); var channel = IOWebSocketChannel(socket); var client = stw.RemoteClient(channel.cast());