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

View file

@ -1,5 +1,6 @@
<component name="ProjectRunConfigurationManager">
<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="workingDirectory" value="$PROJECT_DIR$/example_star_wars" />
<method />

View file

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