@@ -35,7 +35,7 @@ You will learn how to build and use a simple GraphQL service with
35
35
https://openliberty.io/docs/latest/reference/feature/mpGraphQL-1.0.html[MicroProfile GraphQL^].
36
36
37
37
GraphQL is an open source data query language.
38
- Unlike REST APIs, each `POST` request that is sent to a GraphQL service goes to a single HTTP endpoint.
38
+ Unlike REST APIs, each HTTP request that is sent to a GraphQL service goes to a single HTTP endpoint.
39
39
Create, read, update, and delete operations and their details are differentiated by the contents of the request.
40
40
If the operation returns data, the user specifies what properties of the data that they want returned.
41
41
For read operations, a JSON object is returned that contains only the data and properties that are specified.
@@ -53,6 +53,11 @@ It can then collate this data into a single object for the user.
53
53
This simplifies data retrieval as the user only makes a single request to the GraphQL service,
54
54
instead of multiple requests to the individual data sources.
55
55
56
+ All of the available operations to retrieve or modify data are available in a single GraphQL schema.
57
+ The GraphQL schema describes all the data types used in the GraphQL service.
58
+ The schema also describes all of the available operations.
59
+ As well, you can add names and text descriptions to the various object types and operations in the schema.
60
+
56
61
You can learn more about GraphQL at the https://graphql.org/[GraphQL website^].
57
62
58
63
You'll create a GraphQL application that retrieves data from multiple `system` services.
@@ -63,14 +68,14 @@ image::architecture.png[GraphQL architecture where multiple system microservices
63
68
64
69
The guide application includes an interactive GraphQL tool called
65
70
https://github.com/graphql/graphiql/tree/main/packages/graphiql[GraphiQL^].
66
- GraphiQL helps you make queries to a GraphQL service.
71
+ GraphiQL helps you make queries to a GraphQL service.
67
72
In the GraphiQL UI, you need to type only the body of the query for the purposes of manual tests and examples.
68
73
69
74
== Additional prerequisites
70
75
71
76
Before you begin, Docker needs to be installed.
72
77
For installation instructions, refer to the https://docs.docker.com/get-docker/[official Docker documentation^].
73
- You will build and run the application in Docker containers.
78
+ You'll build and run the application in Docker containers.
74
79
75
80
Make sure to start your Docker daemon before you proceed.
76
81
@@ -89,7 +94,7 @@ Navigate to the `start` directory to begin.
89
94
90
95
Object types define the structure of the data returned by GraphQL.
91
96
Annotations that are applied to the declaration and properties of Java classes define object types.
92
- The object types are defined in their own Maven module which is included in the other modules.
97
+ The object types are defined in their own Maven module that is included in the other modules.
93
98
94
99
[role="code_command hotspot file=0", subs="quotes"]
95
100
----
@@ -147,8 +152,8 @@ To save time, the [hotspot=class file=3]`SystemLoad` class and
147
152
The `SystemLoad` class maps to the [hotspot=type file=3]`systemLoad`
148
153
object type, which describes the resource usage of a `system` service.
149
154
The `SystemLoadData` class maps to the [hotspot=type file=4]`loadData` object type.
150
- This will be a nested object inside the `systemLoad` object type.
151
- Together, these will contain the details of the resource usage of a `system` service.
155
+ The `loadData` object will be a nested object inside the `systemLoad` object type.
156
+ Together, these objects will contain the details of the resource usage of a `system` service.
152
157
153
158
// file 0
154
159
JavaInfo.java
@@ -187,7 +192,12 @@ include::finish/models/src/main/java/io/openliberty/guides/graphql/models/System
187
192
188
193
== Implementing system service
189
194
190
- GraphQL needs a way to access information about the `system` microservices for this example.
195
+ The `system` microservices are backend services using JAX-RS.
196
+ For more details on using JAX-RS, see our
197
+ https://www.openliberty.io/guides/rest-intro.html[Creating a RESTful web service guide^].
198
+ This `system` microservices report system properties.
199
+ Multiple instances of them will be accessed and their information will be collated by GraphQL.
200
+ In a real scenario, GraphQL might access multiple different databases or other services.
191
201
192
202
[role="code_command hotspot file=0" ,subs="quotes"]
193
203
----
@@ -206,7 +216,7 @@ The [hotspot=note file=0]`note` endpoint is used to write a note into the system
206
216
`system/src/main/java/io/openliberty/guides/system/SystemManagementResource.java`
207
217
----
208
218
209
- The [hotspot file=1]`SystemMangaementResource ` class provides information on the system's operating system and resource management.
219
+ The [hotspot file=1]`SystemManagementResource ` class provides information on the system's operating system and resource management.
210
220
The [hotspot=operatingSystem file=1]`operatingSystem` endpoint assembles and returns an object describing the operating system.
211
221
The [hotspot=systemLoad file=1]`systemLoad` endpoint assembles and returns an object describing the system load.
212
222
It will include the JVM heap load and processor load.
@@ -250,10 +260,10 @@ This request is handled by the [hotspot=getSystemInfo file=0]`getSystemInfo()` f
250
260
It retrieves and bundles system information into a `SystemInfo` object that is returned.
251
261
252
262
It uses an [hotspot=getSystemInfoHeader file=0]`@Name` on one of its input parameters.
253
- The `@Name` annotation has different functions depending on the context in which it is used.
263
+ The `@Name` annotation has different functions depending on the context in which it's used.
254
264
In this context, it denotes input parameters for GraphQL operations.
255
265
For the [hotspot=getSystemInfo file=0]`getSystemInfo()` function,
256
- it is used to input the `hostname` for the system you want to look up information for.
266
+ it's used to input the `hostname` for the system you want to look up information for.
257
267
258
268
Recall that the `SystemInfo` class contained nested objects.
259
269
It contained a `JavaInfo` and an `OperatingSystem` object.
@@ -276,7 +286,7 @@ Operations of the `mutation` type are be used to edit data.
276
286
They can create, update, or delete data.
277
287
They're defined by using the [hotspot=mutation file=0]`@Mutation` annotation.
278
288
279
- There is one `mutation` operation in this application - the `editNote` request.
289
+ There's one `mutation` operation in this application - the `editNote` request.
280
290
This request is handled by the [hotspot=editNoteFunction file=0]`editNote()` function.
281
291
This request is used to write a note into the properties of a given system.
282
292
There are inputs for the system you want to write into, and the note you want to write.
@@ -316,6 +326,8 @@ The Open Liberty server needs to be configured to support the GraphQL query lang
316
326
The [hotspot=graphql file=1]`mpGraphQL-1.0` feature that is added to the [hotspot file=1]`server.xml`
317
327
enables the use of the https://openliberty.io/docs/latest/reference/feature/mpGraphQL-1.0.html[MicroProfile GraphQL^]
318
328
feature in Open Liberty.
329
+ Open Liberty's MicroProfile GraphQL feature includes GraphiQL.
330
+ Enable it by setting the [hotspot=enableGraphiql file=1]`io.openliberty.enableGraphQLUI` variable to `true`.
319
331
320
332
// file 0
321
333
pom.xml
@@ -384,13 +396,10 @@ The containers may take some time to become available.
384
396
== Running GraphQL queries
385
397
386
398
Before making any requests, visit the http://localhost:9082/graphql/schema.graphql[^] URL.
387
- This URL contains the schema, which describes the GraphQL service.
388
- The schema details what operations are available and any object types that are returned.
389
- Object types described will have their fields and their types listed.
390
- If defined, descriptions of object types and operations will also be included.
399
+ This URL returns the schema to describe the GraphQL service.
391
400
392
401
To access the GraphQL service, GraphiQL has already been set up and included for you.
393
- Access GraphiQL at the http://localhost:9082/graphiql.html [^] URL.
402
+ Access GraphiQL at the http://localhost:9082/graphql-ui [^] URL.
394
403
Queries that are made through GraphiQL are the same as queries that are made through HTTP requests.
395
404
You can also view the schema through GraphiQL by clicking the `Docs` button on the menu bar.
396
405
@@ -454,7 +463,7 @@ mutation {
454
463
455
464
You receive a response containing the Boolean `true` to let you know that the request was successfully processed.
456
465
You can see the note that you added by running the following query operation.
457
- Notice that there is no need to run a full query, as you only want the `note` property.
466
+ Notice that there's no need to run a full query, as you only want the `note` property.
458
467
Thus, the request only contains the `note` property.
459
468
460
469
[role='command']
0 commit comments