@@ -42,19 +42,19 @@ It might look like the following :
4242
4343```java
4444DataFetcher 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);
5755 }
56+ return products;
57+ }
5858};
5959```
6060
@@ -80,25 +80,25 @@ argument. We can have the ProductDTO have logic that applies this date formatti
8080```java
8181class ProductDTO {
8282
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;
8989
90- // ...
90+ // ...
9191
92- public String getName() {
93- return name;
94- }
92+ public String getName() {
93+ return name;
94+ }
9595
96- // ...
96+ // ...
9797
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+ }
102102}
103103```
104104
@@ -147,7 +147,7 @@ and what arguments have been provided. Here are some of the more interesting pa
147147 of a field to control what values it returns.
148148
149149* ``<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
151151 when trying to get field data. For example the current user credentials or the database connection parameters could be contained
152152 with a context object so that data fetchers can make business layer calls. One of the key design decisions you have as a graphql
153153 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 {
182182 name
183183 description
184184 sellingLocations {
185- state
185+ state
186186 }
187187 }
188188}
0 commit comments