|
1 | 1 | package graphql.execution.batched; |
2 | 2 |
|
3 | 3 | import graphql.schema.DataFetchingEnvironment; |
| 4 | + |
4 | 5 | import java.lang.annotation.ElementType; |
5 | 6 | import java.lang.annotation.Retention; |
6 | 7 | import java.lang.annotation.RetentionPolicy; |
|
13 | 14 | * This annotation must be used in conjunction with {@link BatchedExecutionStrategy}. Batching is valuable in many |
14 | 15 | * situations, such as when a {@link graphql.schema.DataFetcher} must make a network or file system request. |
15 | 16 | * </p> |
16 | | - * |
| 17 | + * <p/> |
17 | 18 | * <p> |
18 | 19 | * When a {@link graphql.schema.DataFetcher} is batched, the {@link DataFetchingEnvironment#getSource()} method is |
19 | 20 | * guaranteed to return a {@link java.util.List}. The {@link graphql.schema.DataFetcher#get(DataFetchingEnvironment)} |
20 | 21 | * method MUST return a parallel {@link java.util.List} which is equivalent to running a {@link graphql.schema.DataFetcher} |
21 | 22 | * over each input element individually. |
22 | 23 | * </p> |
23 | | - * |
| 24 | + * <p/> |
24 | 25 | * <p> |
25 | | - * Using the {@link Batched} annotation is equivalent to implementing {@link BatchedDataFetcher} instead of {@link graphql.schema.DataFetcher}. |
26 | | - * It is preferred to use the {@link Batched} annotation. |
| 26 | + * Using the {@link Batched} annotation is equivalent to implementing {@link BatchedDataFetcher} instead of {@link graphql.schema.DataFetcher}. |
| 27 | + * It is preferred to use the {@link Batched} annotation. |
27 | 28 | * </p> |
28 | | - * |
| 29 | + * <p/> |
29 | 30 | * For example, the following two {@link graphql.schema.DataFetcher} objects are interchangeable if used with a |
30 | 31 | * {@link BatchedExecutionStrategy}. |
31 | | - <pre> |
32 | | - <code> |
33 | | - new DataFetcher() { |
34 | | - {@literal @}Override |
35 | | - {@literal @}Batched |
36 | | - public Object get(DataFetchingEnvironment environment) { |
37 | | - {@code List<String> retVal = new ArrayList<>();} |
38 | | - {@code for (String s: (List<String>) environment.getSource())} { |
39 | | - retVal.add(s + environment.getArgument("text")); |
40 | | - } |
41 | | - return retVal; |
42 | | - } |
43 | | - } |
44 | | - </code> |
45 | | - </pre> |
46 | | - * |
47 | 32 | * <pre> |
48 | 33 | * <code> |
49 | | - new DataFetcher() { |
50 | | - {@literal @}Override |
51 | | - public Object get(DataFetchingEnvironment e) { |
52 | | - return ((String)e.getSource()) + e.getArgument("text"); |
53 | | - } |
54 | | - } |
55 | | -</code> |
| 34 | + * new DataFetcher() { |
| 35 | + * {@literal @}Override |
| 36 | + * {@literal @}Batched |
| 37 | + * public Object get(DataFetchingEnvironment environment) { |
| 38 | + * {@code List<String> retVal = new ArrayList<>();} |
| 39 | + * {@code for (String s: (List<String>) environment.getSource())} { |
| 40 | + * retVal.add(s + environment.getArgument("text")); |
| 41 | + * } |
| 42 | + * return retVal; |
| 43 | + * } |
| 44 | + * } |
| 45 | + * </code> |
| 46 | + * </pre> |
| 47 | + * <p/> |
| 48 | + * <pre> |
| 49 | + * <code> |
| 50 | + * new DataFetcher() { |
| 51 | + * {@literal @}Override |
| 52 | + * public Object get(DataFetchingEnvironment e) { |
| 53 | + * return ((String)e.getSource()) + e.getArgument("text"); |
| 54 | + * } |
| 55 | + * } |
| 56 | + * </code> |
56 | 57 | * </pre> |
57 | | - * |
58 | 58 | */ |
59 | 59 | @Target(ElementType.METHOD) |
60 | 60 | @Retention(RetentionPolicy.RUNTIME) |
|
0 commit comments