You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/blog/getting-started-with-spring-boot.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,7 @@ date = 2019-01-23
7
7
toc = "true"
8
8
+++
9
9
10
-
This is a tutorial for people who have never development a GraphQL server with Java. Some Spring Boot and Java knowledge is required. While we give a brief introduction into GraphQL, the focus of this tutorial is on developing a GraphQL server in Java.
11
-
10
+
This is a tutorial for people who want to create a GraphQL server in Java. It requires some Spring Boot and Java knowledge and while we give a brief introduction into GraphQL, the focus of this tutorial is on developing a GraphQL server in Java.
12
11
13
12
# GraphQL in 3 minutes
14
13
@@ -32,7 +31,7 @@ With GraphQL you send the following query to server to get the details for the b
32
31
}
33
32
{{< / highlight >}}
34
33
35
-
This is not JSON (even if it looks remotely similar), it is a GraphQL query.
34
+
This is not JSON (even though it looks deliberately similar), it is a GraphQL query.
36
35
It basically says:
37
36
38
37
- query a book with a specific id
@@ -55,7 +54,7 @@ The response is normal JSON:
55
54
}
56
55
{{< / highlight >}}
57
56
58
-
One very important property of GraphQL is that it is statically typed: the server knows exactly of the shape of every object you can query and any client can actually "inspect" the server and ask for the so called "schema". The schema describes what queries are possible and what fields you can get back. (Note: when we refer to schema here, we always refer to a "GraphQL Schema", which is not related to other schemas like "JSON Schema")
57
+
One very important property of GraphQL is that it is statically typed: the server knows exactly the shape of every object you can query and any client can actually "introspect" the server and ask for the so called "schema". The schema describes what queries are possible and what fields you can get back. (Note: when we refer to schema here, we always refer to a "GraphQL Schema", which is not related to other schemas like "JSON Schema" or "Database Schema")
59
58
60
59
The schema for the above query looks like this:
61
60
@@ -92,7 +91,7 @@ GraphQL Java Engine itself is only concerned with executing queries. It doesn't
92
91
The main steps of creating a GraphQL Java server are:
93
92
94
93
1. Defining a GraphQL Schema.
95
-
2.Defining on how the actual data for a query is fetched.
94
+
2.Deciding on how the actual data for a query is fetched.
96
95
97
96
# Our example API: getting book details
98
97
@@ -166,7 +165,7 @@ It also defines the type `Book` which has the fields: `id`, `name`, `pageCount`
166
165
167
166
> The Domain Specific Language shown above which is used to describe a schema is called Schema Definition Language or SDL. More details about it can be found [here](https://graphql.org/learn/schema/).
168
167
169
-
But so far this is just normal text. We need to "bring it to live" by reading the file and parsing it.
168
+
Once we have this file we need to "bring it to life" by reading the file and parsing it and adding code to fetch data for it.
170
169
171
170
We create a new `GraphQLProvider` class in the package `com.graphqljava.tutorial.bookdetails` with an `init` method which will create a `GraphQL` instance:
172
171
@@ -191,15 +190,16 @@ public class GraphQLProvider {
191
190
}
192
191
193
192
private GraphQLSchema buildSchema(String sdl) {
194
-
//TODO
193
+
//TODO: we will create the schema here later
195
194
}
196
195
}
197
196
{{< / highlight >}}
198
197
<p/>
199
198
200
-
We use Guava to read the file at runtime from our classpath, then create a `GraphQLSchema` and `GraphQL` instance. This `GraphQL` instance is exposed as a Spring Bean. The GraphQL Java Spring adapter will use that `GraphQL` instance to make our schema available via HTTP on the default url `/graphql`.
199
+
We use Guava `Resources` to read the file from our classpath, then create a `GraphQLSchema` and `GraphQL` instance. This `GraphQL` instance is exposed as a Spring Bean. The GraphQL Java Spring adapter will use that `GraphQL` instance to make our schema available via HTTP on the default url `/graphql`.
200
+
201
+
What we still need to do is to implement the `buildSchema` method which creates the `GraphQLSchema` instance and wires in code to fetch data:
201
202
202
-
What we still need to do is to implement the `buildSchema` method which creates the `GraphQLSchema` instance:
203
203
204
204
{{< highlight java "linenos=table" >}}
205
205
@Autowired
@@ -225,7 +225,7 @@ What we still need to do is to implement the `buildSchema` method which creates
225
225
226
226
`TypeDefinitionRegistry` is the parsed version of our schema file. `SchemaGenerator` combines the `TypeDefinitionRegistry` with `RuntimeWiring` to actually make the `GraphQLSchema`.
227
227
228
-
`buildRuntimeWiring` uses the `graphQLDataFetchers` bean to actually register two `DataFetcher`:
228
+
`buildRuntimeWiring` uses the `graphQLDataFetchers` bean to actually register two `DataFetcher`s:
229
229
230
230
- One to retrieve a book with a specific ID
231
231
- One to get the author for a specific book.
@@ -252,7 +252,7 @@ Important: **Every** field from the schema has a `DataFetcher` associated with.
252
252
253
253
We are creating a new class `GraphQLDataFetchers` which contains a sample list of books and authors.
254
254
255
-
The full implementation looks like that and we will look at it in detail:
255
+
The full implementation looks like this which we will look at it in detail soon:
0 commit comments