Pedantic fixes in angel_graphql

This commit is contained in:
Tobe O 2019-08-14 12:02:51 -04:00
parent 359919e8fd
commit 899fe0fe54
4 changed files with 21 additions and 27 deletions

View file

@ -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()),
],
),
],

View file

@ -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(
<script src="//unpkg.com/graphiql-subscriptions-fetcher@0.0.2/browser/client.js"></script>
''';
subscriptionsFetcher = '''
let subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient('$subscriptionsEndpoint', {
let subscriptionsClient = window.SubscriptionsTransportWs.SubscriptionClient('$subscriptionsEndpoint', {
reconnect: true
});
let $fetcherName = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher);

View file

@ -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 = <GraphQLExceptionError>[
new GraphQLExceptionError(e.message)
];
var errors = <GraphQLExceptionError>[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 = <GraphQLExceptionError>[
new GraphQLExceptionError(e.message)
];
var errors = <GraphQLExceptionError>[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();
}
};
}

View file

@ -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<String>());