Skip to content

Instantly share code, notes, and snippets.

@nwillc
Last active November 20, 2017 04:38
Show Gist options
  • Save nwillc/0011a1ec14620daa635676938f5d5060 to your computer and use it in GitHub Desktop.
Save nwillc/0011a1ec14620daa635676938f5d5060 to your computer and use it in GitHub Desktop.
Associating the wiring
// Load Schema
final SchemaParser schemaParser = new SchemaParser();
final TypeDefinitionRegistry registry;
try (final InputStream inputStream =
getClass().getClassLoader().getResourceAsStream("schema.graphqls");
final InputStreamReader streamReader = new InputStreamReader(inputStream)) {
registry = schemaParser.parse(streamReader);
} catch (Exception e) {
throw new IllegalStateException("Could not parse graphql schema", e);
}
// Create Wiring
final RuntimeWiring wiring = RuntimeWiring.newRuntimeWiring()
.type("QueryType", wiring -> wiring
.dataFetcher("company", new CompanyQuery(companies))
.dataFetcher("companies", new CompaniesQuery(companies))
)
.type("MutationType", wiring -> wiring
.dataFetcher("company", new CompanyMutation(companies))
.dataFetcher("companyDelete", new CompanyDelete(companies))
)
.build();
// Associate...
SchemaGenerator schemaGenerator = new SchemaGenerator();
graphql = GraphQL.newGraphQL(schemaGenerator.makeExecutableSchema(registry, wiring)).build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment