Pedantic fixes in angel_graphql
This commit is contained in:
parent
359919e8fd
commit
899fe0fe54
4 changed files with 21 additions and 27 deletions
|
@ -74,7 +74,7 @@ Future configureServer(Angel app) async {
|
||||||
convertDartType(Todo),
|
convertDartType(Todo),
|
||||||
resolve: resolveViaServiceRead(todoService),
|
resolve: resolveViaServiceRead(todoService),
|
||||||
inputs: [
|
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.
|
interface, for easy querying and feedback.
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
app.all('/graphql', graphQLHttp(new GraphQL(schema)));
|
app.all('/graphql', graphQLHttp(GraphQL(schema)));
|
||||||
app.get('/graphiql', graphiQL());
|
app.get('/graphiql', graphiQL());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ All that's left now is just to start the server!
|
||||||
```dart
|
```dart
|
||||||
var server = await http.startServer('127.0.0.1', 3000);
|
var server = await http.startServer('127.0.0.1', 3000);
|
||||||
var uri =
|
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');
|
var graphiqlUri = uri.replace(path: 'graphiql');
|
||||||
print('Listening at $uri');
|
print('Listening at $uri');
|
||||||
print('Access graphiql at $graphiqlUri');
|
print('Access graphiql at $graphiqlUri');
|
||||||
|
@ -214,7 +214,7 @@ var queryType = objectType(
|
||||||
convertDartType(Todo),
|
convertDartType(Todo),
|
||||||
resolve: resolveViaServiceRead(todoService),
|
resolve: resolveViaServiceRead(todoService),
|
||||||
inputs: [
|
inputs: [
|
||||||
new GraphQLFieldInput('id', graphQLId.nonNullable()),
|
GraphQLFieldInput('id', graphQLId.nonNullable()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -9,7 +9,7 @@ RequestHandler graphiQL(
|
||||||
{String graphQLEndpoint = '/graphql', String subscriptionsEndpoint}) {
|
{String graphQLEndpoint = '/graphql', String subscriptionsEndpoint}) {
|
||||||
return (req, res) {
|
return (req, res) {
|
||||||
res
|
res
|
||||||
..contentType = new MediaType('text', 'html')
|
..contentType = MediaType('text', 'html')
|
||||||
..write(renderGraphiql(
|
..write(renderGraphiql(
|
||||||
graphqlEndpoint: graphQLEndpoint,
|
graphqlEndpoint: graphQLEndpoint,
|
||||||
subscriptionsEndpoint: subscriptionsEndpoint))
|
subscriptionsEndpoint: subscriptionsEndpoint))
|
||||||
|
@ -30,7 +30,7 @@ String renderGraphiql(
|
||||||
<script src="//unpkg.com/graphiql-subscriptions-fetcher@0.0.2/browser/client.js"></script>
|
<script src="//unpkg.com/graphiql-subscriptions-fetcher@0.0.2/browser/client.js"></script>
|
||||||
''';
|
''';
|
||||||
subscriptionsFetcher = '''
|
subscriptionsFetcher = '''
|
||||||
let subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient('$subscriptionsEndpoint', {
|
let subscriptionsClient = window.SubscriptionsTransportWs.SubscriptionClient('$subscriptionsEndpoint', {
|
||||||
reconnect: true
|
reconnect: true
|
||||||
});
|
});
|
||||||
let $fetcherName = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher);
|
let $fetcherName = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher);
|
||||||
|
|
|
@ -7,10 +7,9 @@ import 'package:graphql_parser/graphql_parser.dart';
|
||||||
import 'package:graphql_schema/graphql_schema.dart';
|
import 'package:graphql_schema/graphql_schema.dart';
|
||||||
import 'package:graphql_server/graphql_server.dart';
|
import 'package:graphql_server/graphql_server.dart';
|
||||||
|
|
||||||
final ContentType graphQlContentType =
|
final ContentType graphQlContentType = ContentType('application', 'graphql');
|
||||||
new ContentType('application', 'graphql');
|
|
||||||
|
|
||||||
final Validator graphQlPostBody = new Validator({
|
final Validator graphQlPostBody = Validator({
|
||||||
'query*': isNonEmptyString,
|
'query*': isNonEmptyString,
|
||||||
'operation_name': isNonEmptyString,
|
'operation_name': isNonEmptyString,
|
||||||
'variables': predicate((v) => v == null || v is String || v is Map),
|
'variables': predicate((v) => v == null || v is String || v is Map),
|
||||||
|
@ -151,29 +150,23 @@ RequestHandler graphQLHttp(GraphQL graphQL,
|
||||||
globalVariables: variables,
|
globalVariables: variables,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
throw new AngelHttpException.badRequest();
|
throw AngelHttpException.badRequest();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new AngelHttpException.badRequest();
|
throw AngelHttpException.badRequest();
|
||||||
}
|
}
|
||||||
} on ValidationException catch (e) {
|
} on ValidationException catch (e) {
|
||||||
var errors = <GraphQLExceptionError>[
|
var errors = <GraphQLExceptionError>[GraphQLExceptionError(e.message)];
|
||||||
new GraphQLExceptionError(e.message)
|
|
||||||
];
|
|
||||||
|
|
||||||
errors
|
errors.addAll(e.errors.map((ee) => GraphQLExceptionError(ee)).toList());
|
||||||
.addAll(e.errors.map((ee) => new GraphQLExceptionError(ee)).toList());
|
return GraphQLException(errors).toJson();
|
||||||
return new GraphQLException(errors).toJson();
|
|
||||||
} on AngelHttpException catch (e) {
|
} on AngelHttpException catch (e) {
|
||||||
var errors = <GraphQLExceptionError>[
|
var errors = <GraphQLExceptionError>[GraphQLExceptionError(e.message)];
|
||||||
new GraphQLExceptionError(e.message)
|
|
||||||
];
|
|
||||||
|
|
||||||
errors
|
errors.addAll(e.errors.map((ee) => GraphQLExceptionError(ee)).toList());
|
||||||
.addAll(e.errors.map((ee) => new GraphQLExceptionError(ee)).toList());
|
return GraphQLException(errors).toJson();
|
||||||
return new GraphQLException(errors).toJson();
|
|
||||||
} on SyntaxError catch (e) {
|
} on SyntaxError catch (e) {
|
||||||
return new GraphQLException.fromSourceSpan(e.message, e.span);
|
return GraphQLException.fromSourceSpan(e.message, e.span);
|
||||||
} on GraphQLException catch (e) {
|
} on GraphQLException catch (e) {
|
||||||
return e.toJson();
|
return e.toJson();
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
|
@ -184,7 +177,7 @@ RequestHandler graphQLHttp(GraphQL graphQL,
|
||||||
st);
|
st);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GraphQLException.fromMessage(e.toString()).toJson();
|
return GraphQLException.fromMessage(e.toString()).toJson();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,12 @@ RequestHandler graphQLWS(GraphQL graphQL, {Duration keepAliveInterval}) {
|
||||||
await res.detach();
|
await res.detach();
|
||||||
var socket = await WebSocketTransformer.upgrade(req.rawRequest,
|
var socket = await WebSocketTransformer.upgrade(req.rawRequest,
|
||||||
protocolSelector: (protocols) {
|
protocolSelector: (protocols) {
|
||||||
if (protocols.contains('graphql-ws'))
|
if (protocols.contains('graphql-ws')) {
|
||||||
return 'graphql-ws';
|
return 'graphql-ws';
|
||||||
else
|
} else {
|
||||||
throw AngelHttpException.badRequest(
|
throw AngelHttpException.badRequest(
|
||||||
message: 'Only the "graphql-ws" protocol is allowed.');
|
message: 'Only the "graphql-ws" protocol is allowed.');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var channel = IOWebSocketChannel(socket);
|
var channel = IOWebSocketChannel(socket);
|
||||||
var client = stw.RemoteClient(channel.cast<String>());
|
var client = stw.RemoteClient(channel.cast<String>());
|
||||||
|
|
Loading…
Reference in a new issue