@@ -42,19 +42,19 @@ It might look like the following :
42
42
43
43
```java
44
44
DataFetcher productsDataFetcher = new DataFetcher<List<ProductDTO>>() {
45
- @Override
46
- public List<ProductDTO> get(DataFetchingEnvironment environment) {
47
- DatabaseSecurityCtx ctx = environment.getGraphQlContext().get(" databaseSecurityCtx");
48
-
49
- List<ProductDTO> products;
50
- String match = environment.getArgument(" match");
51
- if (match != null) {
52
- products = fetchProductsFromDatabaseWithMatching(ctx, match);
53
- } else {
54
- products = fetchAllProductsFromDatabase(ctx);
55
- }
56
- return products;
45
+ @Override
46
+ public List<ProductDTO> get(DataFetchingEnvironment environment) {
47
+ DatabaseSecurityCtx ctx = environment.getGraphQlContext().get(" databaseSecurityCtx");
48
+
49
+ List<ProductDTO> products;
50
+ String match = environment.getArgument(" match");
51
+ if (match != null) {
52
+ products = fetchProductsFromDatabaseWithMatching(ctx, match);
53
+ } else {
54
+ products = fetchAllProductsFromDatabase(ctx);
57
55
}
56
+ return products;
57
+ }
58
58
};
59
59
```
60
60
@@ -80,25 +80,25 @@ argument. We can have the ProductDTO have logic that applies this date formatti
80
80
```java
81
81
class ProductDTO {
82
82
83
- private ID id;
84
- private String name;
85
- private String description;
86
- private Double cost;
87
- private Double tax;
88
- private LocalDateTime launchDate;
83
+ private ID id;
84
+ private String name;
85
+ private String description;
86
+ private Double cost;
87
+ private Double tax;
88
+ private LocalDateTime launchDate;
89
89
90
- // ...
90
+ // ...
91
91
92
- public String getName() {
93
- return name;
94
- }
92
+ public String getName() {
93
+ return name;
94
+ }
95
95
96
- // ...
96
+ // ...
97
97
98
- public String getLaunchDate(DataFetchingEnvironment environment) {
99
- String dateFormat = environment.getArgument(" dateFormat");
100
- return yodaTimeFormatter(launchDate,dateFormat);
101
- }
98
+ public String getLaunchDate(DataFetchingEnvironment environment) {
99
+ String dateFormat = environment.getArgument(" dateFormat");
100
+ return yodaTimeFormatter(launchDate,dateFormat);
101
+ }
102
102
}
103
103
```
104
104
@@ -147,7 +147,7 @@ and what arguments have been provided. Here are some of the more interesting pa
147
147
of a field to control what values it returns.
148
148
149
149
* ``<T> T getGraphQLContext()`` - the context object is set up when the query is first executed and stays the same over the lifetime
150
- of the query. The context can be any value and is typically used to give each data fetcher some calling context needed
150
+ of the query. The context is a map that can contain any value and is typically used to give each data fetcher some calling context needed
151
151
when trying to get field data. For example the current user credentials or the database connection parameters could be contained
152
152
with a context object so that data fetchers can make business layer calls. One of the key design decisions you have as a graphql
153
153
system designer is how you will use context in your fetchers if at all. Some people use a dependency framework that injects context into
@@ -182,7 +182,7 @@ query {
182
182
name
183
183
description
184
184
sellingLocations {
185
- state
185
+ state
186
186
}
187
187
}
188
188
}
0 commit comments