Create Star Wars example

This commit is contained in:
Tobe O 2018-08-03 23:13:33 -04:00
parent cf9d94d123
commit 1db4a33e05
2 changed files with 23 additions and 9 deletions
.idea/runConfigurations
example_star_wars/lib

View file

@ -1,5 +1,6 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="server.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true" nameIsGenerated="true"> <configuration default="false" name="server.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true" nameIsGenerated="true">
<option name="VMOptions" value="--observe" />
<option name="filePath" value="$PROJECT_DIR$/example_star_wars/bin/server.dart" /> <option name="filePath" value="$PROJECT_DIR$/example_star_wars/bin/server.dart" />
<option name="workingDirectory" value="$PROJECT_DIR$/example_star_wars" /> <option name="workingDirectory" value="$PROJECT_DIR$/example_star_wars" />
<method /> <method />

View file

@ -17,21 +17,34 @@ Future configureServer(Angel app) async {
// Create the GraphQL schema. // Create the GraphQL schema.
// This code uses dart:mirrors to easily create GraphQL types from Dart PODO's. // This code uses dart:mirrors to easily create GraphQL types from Dart PODO's.
//var droidType = convertDartType(Droid); var droidType = convertDartType(Droid);
//var episodeType = convertDartType(Episode); var episodeType = convertDartType(Episode);
var humanType = convertDartType(Human); var humanType = convertDartType(Human);
var starshipType = convertDartType(Starship);
// Create the query type. // Create the query type.
// //
// Use the `resolveViaServiceIndex` helper to load data directly from an // Use the `resolveViaServiceIndex` helper to load data directly from an
// Angel service. // Angel service.
var queryType = objectType('StarWarsQuery', fields: [ var queryType = objectType('StarWarsQuery',
field( description: 'A long time ago, in a galaxy far, far away...',
'humans', fields: [
type: listType(humanType.nonNullable()), field(
resolve: resolveViaServiceIndex(humansService), 'droids',
), type: listType(droidType.nonNullable()),
]); resolve: resolveViaServiceIndex(droidService),
),
field(
'humans',
type: listType(humanType.nonNullable()),
resolve: resolveViaServiceIndex(humansService),
),
field(
'starships',
type: listType(starshipType.nonNullable()),
resolve: resolveViaServiceIndex(starshipService),
),
]);
// Finally, create the schema. // Finally, create the schema.
var schema = graphQLSchema(query: queryType); var schema = graphQLSchema(query: queryType);