Skip to content

Commit 335df2f

Browse files
andimarek-atlassianandimarek
authored andcommitted
wip
1 parent 209a158 commit 335df2f

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

content/blog/getting-started-with-spring-boot.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,42 @@ type Query {
150150
type 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

0 commit comments

Comments
 (0)