Skip to content

Commit 76a10d0

Browse files
dupskibbakerman
authored andcommitted
Updated Programmatic Schemas section
Added notes on how to make a programmatically-generated schema executable
1 parent d1d1a24 commit 76a10d0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

content/documentation/master/schema.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,25 @@ Example:
274274

275275
{{< / highlight >}}
276276

277+
To make a programmatically-generated schema executable, you can just instantiate a `GraphQLSchema` object directly, and pass in your root `Query` (and `Mutation`) `GraphQLObjectType` objects, as shown in the example below:
277278

279+
{{< highlight java "linenos=table" >}}
280+
281+
282+
GraphQLObjectType queryType = newObject()
283+
.name("QueryType")
284+
.field(newFieldDefinition()
285+
.name("hello")
286+
.type(GraphQLString)
287+
.dataFetcher(new StaticDataFetcher("world!"))
288+
.build();
289+
290+
GraphQLSchema schema = new GraphQLSchema(queryType);
291+
292+
// Make the schema executable
293+
GraphQL executor = GraphQL.newGraphQL(graphQLSchema).build()
294+
ExecutionResult executionResult = executor.execute("{hello}");
295+
{{< / highlight >}}
278296

279297
## Types
280298

0 commit comments

Comments
 (0)