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
+16-11Lines changed: 16 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,15 +75,17 @@ We barely touched GraphQL. Further information can be found on the official page
75
75
76
76
# GraphQL Java Overview
77
77
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.
79
82
80
83
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).
81
84
82
85
The main steps of creating a GraphQL Java server are:
83
86
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.
87
89
88
90
89
91
# 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:
98
100
99
101
1. get a list of available books
100
102
1. get specific book details
101
-
1. order a book
102
103
103
104
We will incrementally build our app.
104
105
@@ -114,7 +115,7 @@ Select:
114
115
115
116
- Gradle Project
116
117
- Java
117
-
- Spring Boot 2.x
118
+
- Spring Boot 2.1.x
118
119
119
120
For the project metadata we use:
120
121
@@ -126,25 +127,27 @@ As dependency we just select `Web`.
126
127
A click on `Generate Project` will give you a ready to use Spring Boot app.
127
128
All subsequently mentioned files and paths will be relative to this generated project.
128
129
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`:
130
131
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.
We are creating a new file `schema.graphqls` in `src/main/resources` with the following content:
144
146
145
147
{{< highlight graphql "linenos=table" >}}
146
148
type Query {
147
149
books: [Books]
150
+
bookById(id: ID!): Book
148
151
}
149
152
150
153
type Book {
@@ -154,7 +157,9 @@ type Book {
154
157
155
158
{{< / highlight >}}
156
159
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`.
158
163
159
164
> The Domain Specific Language shown above which is used to describe a schema is called Schema Definition Language or SDL.
160
165
@@ -197,6 +202,6 @@ Our code looks like this:
197
202
{{< / highlight >}}
198
203
199
204
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`.
0 commit comments