Skip to content

Commit 4496ee7

Browse files
committed
pr feedback
1 parent d78a7de commit 4496ee7

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public class GraphQLProvider {
177177
private GraphQL graphQL;
178178

179179
@Bean
180-
public GraphQL graphQL() {
180+
public GraphQL graphQL() {
181181
return graphQL;
182182
}
183183

@@ -230,7 +230,11 @@ What we still need to do is to implement the `buildSchema` method which creates
230230
- One to retrieve a book with a specific ID
231231
- One to get the author for a specific book.
232232

233-
`DataFetcher` and how to implement the `GraphQLDataFetcher` bean is explained in the next section.
233+
`DataFetcher` and how to implement the `GraphQLDataFetchers` bean is explained in the next section.
234+
235+
Overall the process of creating a `GraphQL` and `GraphQLSchema` instance looks like this:
236+
237+
![Creating GraphQL](/images/graphql_creation.png)
234238

235239
# DataFetchers
236240

@@ -345,7 +349,21 @@ A `PropertyDataFetcher` tries to lookup a property on a Java object in multiple
345349
Lets assume for a second we have a mismatch and the book `Map` has a key `totalPages` instead of `pageCount`. This would result in a `null` value for `pageCount` for every book, because the `PropertyDataFetcher` can't fetch the right value. In order to fix that you would have to register a new `DataFetcher` for `Book.pageCount` which looks like this:
346350

347351
{{< highlight java "linenos=table" >}}
348-
...
352+
353+
// In the GraphQLProvider class
354+
private RuntimeWiring buildWiring() {
355+
return RuntimeWiring.newRuntimeWiring()
356+
.type(newTypeWiring("Query")
357+
.dataFetcher("bookById", graphQLDataFetchers.getBookByIdDataFetcher()))
358+
.type(newTypeWiring("Book")
359+
.dataFetcher("author", graphQLDataFetchers.getAuthorDataFetcher())
360+
// This line is new: we need to register the additional DataFetcher
361+
.dataFetcher("pageCount", graphQLDataFetchers.getPageCountDataFetcher()))
362+
.build();
363+
}
364+
365+
// In the GraphQLDataFetchers class
366+
// Implement the DataFetcher
349367
public DataFetcher getPageCountDataFetcher() {
350368
return dataFetchingEnvironment -> {
351369
Map<String,String> book = dataFetchingEnvironment.getSource();
@@ -357,7 +375,7 @@ Lets assume for a second we have a mismatch and the book `Map` has a key `totalP
357375

358376
<p/>
359377
This `DataFetcher` would fix that problem by looking up the right key in the book `Map`.
360-
(Again: we don't need that for our example, because we don't have naming mismatch)
378+
(Again: we don't need that for our example, because we don't have a naming mismatch)
361379

362380

363381
# Try out the API
@@ -379,4 +397,6 @@ More information about GraphQL Java can be found in the [documentation](https://
379397

380398
We also have [spectrum chat](https://spectrum.chat/graphql-java) for any question or problems.
381399

400+
For direct feedback you can also ping us on our [Twitter GraphQL Java account](https://twitter.com/graphql_java).
401+
382402

static/images/graphql_creation.png

19.3 KB
Loading

0 commit comments

Comments
 (0)