Skip to content

Commit 42a27e1

Browse files
committed
tutorial wip
1 parent 16053c9 commit 42a27e1

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,17 @@ We barely touched GraphQL. Further information can be found on the official page
7575

7676
# GraphQL Java Overview
7777

78-
[GraphQL Java](https://www.graphql-java.com) is the Java (server) implementation for GraphQL. The [GraphQL Java Github Repo](https://github.com/graphql-java/graphql-java) contains the actual source code.
78+
[GraphQL Java](https://www.graphql-java.com) is the Java (server) implementation for GraphQL.
79+
The are several repositories in the GraphQL Java Github org. The most important one is the [GraphQL Java Engine](https://github.com/graphql-java/graphql-java) which is basis for everything else.
80+
81+
We will also use the [GraphQL Java Spring Boot](https://github.com/graphql-java/graphql-java-spring) adapter, which takes care of exposing your GraphQL API via HTTP.
7982

8083
GraphQL Java itself is only concerned with executing queries. It doesn't deal with any HTTP or JSON related topics. For these aspects we will use [Spring Boot](https://spring.io/projects/spring-boot).
8184

8285
The main steps of creating a GraphQL Java server are:
8386

84-
- Defining a GraphQL Schema.
85-
- Defining on how the actual data for a query is fetched.
86-
- Exposing the server via HTTP (via Spring Boot).
87+
1. Defining a GraphQL Schema.
88+
2. Defining on how the actual data for a query is fetched.
8789

8890

8991
# Our example app: an online store for books
@@ -98,7 +100,6 @@ We will build a GraphQL server which will cover the following use cases:
98100

99101
1. get a list of available books
100102
1. get specific book details
101-
1. order a book
102103

103104
We will incrementally build our app.
104105

@@ -114,7 +115,7 @@ Select:
114115

115116
- Gradle Project
116117
- Java
117-
- Spring Boot 2.x
118+
- Spring Boot 2.1.x
118119

119120
For the project metadata we use:
120121

@@ -126,25 +127,27 @@ As dependency we just select `Web`.
126127
A click on `Generate Project` will give you a ready to use Spring Boot app.
127128
All subsequently mentioned files and paths will be relative to this generated project.
128129

129-
We are adding two dependency to our project inside the `dependencies` section of `build.gradle`:
130+
We are adding three dependencies to our project inside the `dependencies` section of `build.gradle`:
130131

131-
the first one is GraphQL Java itself and the second one is [Google Guava](https://github.com/google/guava). Guava is not strictly needed but it will make our life easier.
132+
the first two are GraphQL Java and GraphQL Java Spring and then we also add [Google Guava](https://github.com/google/guava). Guava is not strictly needed but it will make our life a little bit easier.
132133

133134
{{< highlight groovy "linenos=table" >}}
134135
dependencies {
135136
...
136137
implementation('com.graphql-java:graphql-java:11.0')
138+
implementation "com.graphql-java:graphql-java-spring-boot-starter-webmvc:1.0"
137139
implementation('com.google.guava:guava:26.0-jre')
138140
}
139141
{{< / highlight >}}
140142

141-
## Defining our first schema
143+
## Defining the schema
142144

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

145147
{{< highlight graphql "linenos=table" >}}
146148
type Query {
147149
books: [Books]
150+
bookById(id: ID!): Book
148151
}
149152

150153
type Book {
@@ -154,7 +157,9 @@ type Book {
154157

155158
{{< / highlight >}}
156159

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`.
160+
This schema defines two top level fields (fields in the type `Query`): `books` which results in a list of `Book`s and a `bookById` to query a specific Book by id.
161+
162+
It also defines the type `Book` which has two fields: `id` and `name`.
158163

159164
> The Domain Specific Language shown above which is used to describe a schema is called Schema Definition Language or SDL.
160165
@@ -197,6 +202,6 @@ Our code looks like this:
197202
{{< / highlight >}}
198203

199204

200-
Important: **Every** field from the schema has a `DataFetcher` associated with. Most of them have a actually the defaultData
205+
Important: **Every** field from the schema has a `DataFetcher` associated with. Most of them have the a default `DataFetcher` of type `PropertyDataFetcher`.
201206

202207

0 commit comments

Comments
 (0)