graphql_server@1.0.0

This commit is contained in:
Tobe O 2019-04-24 13:39:23 -04:00
parent b244335c92
commit fdf7d21a76
4 changed files with 87 additions and 1 deletions

View file

@ -1,3 +1,7 @@
# 1.0.0
* Finish testing.
* Add `package:pedantic` fixes.
# 1.0.0-rc.0
* Get the Apollo support working with the latest version of `subscriptions-transport-ws`.

View file

@ -1,4 +1,7 @@
# graphql_server
[![Pub](https://img.shields.io/pub/v/graphql_server.svg)](https://pub.dartlang.org/packages/graphql_server)
[![build status](https://travis-ci.org/angel-dart/graphql.svg)](https://travis-ci.org/angel-dart/graphql)
Base package for implementing GraphQL servers.
You might prefer [`package:angel_graphql`](https://github.com/angel-dart/graphql),
the fastest way to implement GraphQL backends in Dart.
@ -44,6 +47,34 @@ a `Stream`. Ultimately, the transport for relaying subscription
events to clients is not specified in the GraphQL spec, so it's
up to you.
Note that in a schema like this:
```graphql
type TodoSubscription {
onTodo: TodoAdded!
}
type TodoAdded {
id: ID!
text: String!
isComplete: Bool
}
```
Your Dart schema's resolver for `onTodo` should be
a `Map` *containing an `onTodo` key*:
```dart
field(
'onTodo',
todoAddedType,
resolve: (_, __) {
return someStreamOfTodos()
.map((todo) => {'onTodo': todo});
},
);
```
For the purposes of reusing existing tooling (i.e. JS clients, etc.),
`package:graphql_server` rolls with an implementation of Apollo's
`subscriptions-transport-ws` spec.

View file

@ -1,5 +1,5 @@
name: graphql_server
version: 1.0.0-rc.0
version: 1.0.0
author: Tobe O <thosakwe@gmail.com>
description: Base package for implementing GraphQL servers. You might prefer `package:angel_graphql`, the fastest way to implement GraphQL backends in Dart.
homepage: https://github.com/angel-dart/graphql

View file

@ -0,0 +1,51 @@
import 'dart:async';
import 'package:graphql_schema/graphql_schema.dart';
import 'package:graphql_server/graphql_server.dart';
import 'package:test/test.dart';
void main() {
var episodes = [
{'name': 'The Phantom Menace'},
{'name': 'Attack of the Clones'},
{'name': 'Attack of the Clones'}
];
var episodesAsData = episodes.map((ep) {
return {
'data': {'prequels': ep}
};
});
Stream<Map<String, dynamic>> resolveEpisodes(_, __) =>
Stream.fromIterable(episodes)
.map((ep) => {'prequels': ep, 'not_selected': 1337});
var episodeType = objectType('Episode', fields: [
field('name', graphQLString.nonNullable()),
field('not_selected', graphQLInt),
]);
var schema = graphQLSchema(
queryType: objectType('TestQuery', fields: [
field('episodes', graphQLInt, resolve: (_, __) => episodes),
]),
subscriptionType: objectType('TestSubscription', fields: [
field('prequels', episodeType, resolve: resolveEpisodes),
]),
);
var graphQL = GraphQL(schema);
test('subscribe with selection', () async {
var stream = await graphQL.parseAndExecute('''
subscription {
prequels {
name
}
}
''') as Stream<Map<String, dynamic>>;
var asList = await stream.toList();
print(asList);
expect(asList, episodesAsData);
});
}