File tree Expand file tree Collapse file tree 1 file changed +30
-12
lines changed Expand file tree Collapse file tree 1 file changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -150,24 +150,42 @@ type Query {
150150type Book {
151151 id: ID
152152 name: String
153- price: Price
154- availableCopies: Int
155- pageCount: Int
156- author: Person
157153}
158154
159- type Price {
160- price: String
161- currency: String
162- }
155+ {{< / highlight >}}
163156
164- type Person {
165- firstName: String
166- lastName: String
167- }
157+ This schema defines one query: ` books ` which results a list of ` Book ` s. It also defines the type ` Book ` which has two fields: ` id ` and ` name ` .
158+
159+ > The Domain Specific Language shown above which is used to describe a schema is called Schema Definition Language or SDL.
160+
161+ But so far it is just a normal text. We need to "bring it to live" by reading the file and parsing it.
162+ We are using Guava to read the file at runtime from our classpath:
168163
164+ {{< highlight java "linenos=table" >}}
165+ URL url = Resources.getResource("schema.graphql");
166+ String sdl = Resources.toString(url, Charsets.UTF_8);
169167{{< / highlight >}}
170168
169+ We now using GraphQL Java for the first time: We are transforming the ` sdl ` into a ` TypeDefinitionRegistry ` :
170+
171+
172+ {{< highlight java "linenos=table" >}}
173+ TypeDefinitionRegistry typeRegistry = new SchemaParser().parse(sdl);
174+ {{< / highlight >}}
175+
176+ This ` TypeDefinitionRegistry ` is just a parsed version of the schema definition file.
177+
178+ ## Creating a GraphQLSchema
179+
180+ The ` typeRegistry ` defined above is just types: it describes how the schema looks like, but not how it actually works when a query is executed.
181+
182+
183+ ### DataFetcher
184+
185+ Probably the most important concept of a GraphQL Java server is a ` DataFetcher ` :
186+ A ` DataFetcher ` fetches the Data for one field while the query is executed.
187+
188+ While GraphQL Java is executing a query it calls the appropriate ` DataFetcher ` for each field it encounters in query.
171189
172190
173191
You can’t perform that action at this time.
0 commit comments