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
+20-6Lines changed: 20 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ author = "Andreas Marek"
4
4
tags = []
5
5
categories = []
6
6
date = 2018-10-22T01:00:00+10:00
7
+
toc = "true"
7
8
+++
8
9
9
10
This is a tutorial for people who 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.
@@ -88,7 +89,7 @@ The main steps of creating a GraphQL Java server are:
88
89
2. Defining on how the actual data for a query is fetched.
89
90
90
91
91
-
# Our example app: an online store for books
92
+
# Our example API: getting book details
92
93
93
94
Our example app we will build is a simple online store for books.
94
95
We assume the very simple user flow:
@@ -107,7 +108,7 @@ We will incrementally build our app.
107
108
Schema and API design itself is interesting and challenging but we will focus on implementing the server and not discuss the actual schema design choices.
108
109
109
110
110
-
# Step 1: Create a Spring Boot app
111
+
# Create a Spring Boot app
111
112
112
113
The easiest way to create a Spring Boot app is to use the initializr at https://start.spring.io/.
113
114
@@ -140,7 +141,7 @@ dependencies {
140
141
}
141
142
{{< / highlight >}}
142
143
143
-
##Defining the schema
144
+
# Defining the schema
144
145
145
146
We are creating a new file `schema.graphqls` in `src/main/resources` with the following content:
146
147
@@ -185,9 +186,9 @@ This `TypeDefinitionRegistry` is just a parsed version of the schema definition
185
186
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.
186
187
187
188
188
-
### DataFetcher
189
+
#DataFetchers
189
190
190
-
Probably the most important concept for a GraphQL Java server is a `DataFetcher`:
191
+
Probably the most important concept for a GraphQL Java server is a `DataFetcher`:
191
192
A `DataFetcher` fetches the Data for one field while the query is executed.
192
193
193
194
While GraphQL Java is executing a query it calls the appropriate `DataFetcher` for each field it encounters in query.
@@ -198,10 +199,23 @@ For our first iteration we are doing the simplest possible thing that works: we
198
199
Our code looks like this:
199
200
200
201
{{< highlight java "linenos=table" >}}
201
-
....
202
+
202
203
{{< / highlight >}}
203
204
204
205
205
206
Important: **Every** field from the schema has a `DataFetcher` associated with. Most of them have the a default `DataFetcher` of type `PropertyDataFetcher`.
206
207
208
+
# Exposing the schema via HTTP
209
+
210
+
The last step is to actually expose the GraphQL schema via HTTP. This is done via the GraphQL Java Spring adapter.
211
+
212
+
The only thing you have todo is to actually define a `Bean` of type `GraphQL` in you Spring Boot app.
0 commit comments