Last active
November 20, 2017 04:38
-
-
Save nwillc/0011a1ec14620daa635676938f5d5060 to your computer and use it in GitHub Desktop.
Associating the wiring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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