Skip to content

Commit 96106a6

Browse files
committed
toc
1 parent 42a27e1 commit 96106a6

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ author = "Andreas Marek"
44
tags = []
55
categories = []
66
date = 2018-10-22T01:00:00+10:00
7+
toc = "true"
78
+++
89

910
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:
8889
2. Defining on how the actual data for a query is fetched.
8990

9091

91-
# Our example app: an online store for books
92+
# Our example API: getting book details
9293

9394
Our example app we will build is a simple online store for books.
9495
We assume the very simple user flow:
@@ -107,7 +108,7 @@ We will incrementally build our app.
107108
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.
108109

109110

110-
# Step 1: Create a Spring Boot app
111+
# Create a Spring Boot app
111112

112113
The easiest way to create a Spring Boot app is to use the initializr at https://start.spring.io/.
113114

@@ -140,7 +141,7 @@ dependencies {
140141
}
141142
{{< / highlight >}}
142143

143-
## Defining the schema
144+
# Defining the schema
144145

145146
We are creating a new file `schema.graphqls` in `src/main/resources` with the following content:
146147

@@ -185,9 +186,9 @@ This `TypeDefinitionRegistry` is just a parsed version of the schema definition
185186
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.
186187

187188

188-
### DataFetcher
189+
# DataFetchers
189190

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`:
191192
A `DataFetcher` fetches the Data for one field while the query is executed.
192193

193194
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
198199
Our code looks like this:
199200

200201
{{< highlight java "linenos=table" >}}
201-
....
202+
202203
{{< / highlight >}}
203204

204205

205206
Important: **Every** field from the schema has a `DataFetcher` associated with. Most of them have the a default `DataFetcher` of type `PropertyDataFetcher`.
206207

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.
213+
214+
215+
{{< highlight java "linenos=table" >}}
216+
217+
{{< / highlight >}}
218+
219+
220+
# Full source code
207221

themes/hugo-sustain/layouts/_default/single.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ <h1 class="title">
1111
<div class="panel panel-default">
1212
<div class="panel-body">
1313
<div class="blogpost">
14+
{{ if (eq .Params.toc "true") }}
15+
{{.TableOfContents}}
16+
{{ end }}
1417
{{ .Content }}
1518
</div>
1619
</div>

0 commit comments

Comments
 (0)