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: src/pages/tutorials/getting-started-with-spring-boot.md
+22-1Lines changed: 22 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -337,7 +337,28 @@ We only implement two `DataFetchers`. As mentioned above, if you don't specify o
337
337
338
338
A `PropertyDataFetcher` tries to lookup a property on a Java object in multiple ways. In case of a `java.util.Map` it simply looks up the property by key. This works perfectly fine for us because the keys of the book and author Maps are the same as the fields specified in the schema. For example in the schema we define for the Book type the field `pageCount` and the book `DataFetcher` returns a `Map` with a key `pageCount`. Because the field name is the same as the key in the `Map`("pageCount") the `PropertyDateFetcher` works for us.
339
339
340
-
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:
340
+
Lets assume for a second we have a mismatch and the book `Map` has a key `totalPages` instead of `pageCount`.
"name", "Harry Potter and the Philosopher's Stone",
348
+
"totalPages", "223",
349
+
"authorId", "author-1"),
350
+
ImmutableMap.of("id", "book-2",
351
+
"name", "Moby Dick",
352
+
"totalPages", "635",
353
+
"authorId", "author-2"),
354
+
ImmutableMap.of("id", "book-3",
355
+
"name", "Interview with the vampire",
356
+
"totalPages", "371",
357
+
"authorId", "author-3")
358
+
);
359
+
```
360
+
361
+
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:
0 commit comments