All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.execution.batched.Batched Maven / Gradle / Ivy

package graphql.execution.batched;

import graphql.schema.DataFetchingEnvironment;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


/**
 * 

* When placed on {@link graphql.schema.DataFetcher#get(DataFetchingEnvironment)}, indicates that this DataFetcher is batched. * This annotation must be used in conjunction with {@link BatchedExecutionStrategy}. Batching is valuable in many * situations, such as when a {@link graphql.schema.DataFetcher} must make a network or file system request. *

*

* When a {@link graphql.schema.DataFetcher} is batched, the {@link DataFetchingEnvironment#getSource()} method is * guaranteed to return a {@link java.util.List}. The {@link graphql.schema.DataFetcher#get(DataFetchingEnvironment)} * method MUST return a parallel {@link java.util.List} which is equivalent to running a {@link graphql.schema.DataFetcher} * over each input element individually. *

*

* Using the {@link Batched} annotation is equivalent to implementing {@link BatchedDataFetcher} instead of {@link graphql.schema.DataFetcher}. * It is preferred to use the {@link Batched} annotation. *

* For example, the following two {@link graphql.schema.DataFetcher} objects are interchangeable if used with a * {@link BatchedExecutionStrategy}. *
 * 
 * new DataFetcher() {
 *   {@literal @}Override
 *   {@literal @}Batched
 *   public Object get(DataFetchingEnvironment environment) {
 *     {@literal List retVal = new ArrayList<>();}
 *     {@literal for (String s: (List) environment.getSource()) {}
 *       retVal.add(s + environment.getArgument("text"));
 *     }
 *     return retVal;
 *   }
 * }
 * 
 * 
*
 * 
 * new DataFetcher() {
 *   {@literal @}Override
 *   public Object get(DataFetchingEnvironment e) {
 *     return ((String)e.getSource()) + e.getArgument("text");
 *   }
 * }
 * 
 * 
*/ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Batched { }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy