Java Code Examples for graphql.schema.DataFetcher#get()
The following examples show how to use
graphql.schema.DataFetcher#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangeDirective.java From samples with MIT License | 6 votes |
private DataFetcher createDataFetcher(DataFetcher originalFetcher) { return (env) -> { List<GraphQLError> errors = new ArrayList<>(); env.getFieldDefinition().getArguments().stream().forEach(it -> { if (appliesTo(it)) { errors.addAll(apply(it, env, env.getArgument(it.getName()))); } GraphQLInputType unwrappedInputType = Util.unwrapNonNull(it.getType()); if (unwrappedInputType instanceof GraphQLInputObjectType) { GraphQLInputObjectType inputObjType = (GraphQLInputObjectType) unwrappedInputType; inputObjType.getFieldDefinitions().stream().filter(this::appliesTo).forEach(io -> { Map<String, Object> value = env.getArgument(it.getName()); errors.addAll(apply(io, env, value.get(io.getName()))); }); } }); Object returnValue = originalFetcher.get(env); if (errors.isEmpty()) { return returnValue; } return Util.mkDFRFromFetchedResult(errors, returnValue); }; }
Example 2
Source File: FuturesConverter.java From rejoiner with Apache License 2.0 | 6 votes |
public static Instrumentation apiFutureInstrumentation() { return new SimpleInstrumentation() { @Override public DataFetcher<?> instrumentDataFetcher( DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters) { return (DataFetcher<Object>) dataFetchingEnvironment -> { Object data = dataFetcher.get(dataFetchingEnvironment); if (data instanceof ApiFuture) { return FutureConverter.toCompletableFuture( apiFutureToListenableFuture((ApiFuture<?>) data)); } return data; }; } }; }
Example 3
Source File: GuavaListenableFutureSupport.java From rejoiner with Apache License 2.0 | 5 votes |
/** * Converts a {@link ListenableFuture} to a Java8 {@link java.util.concurrent.CompletableFuture}. * * <p>{@see CompletableFuture} is supported by the provided {@link * graphql.execution.AsyncExecutionStrategy}. * * <p>Note: This should be installed before any other instrumentation. */ public static Instrumentation listenableFutureInstrumentation(Executor executor) { return new SimpleInstrumentation() { @Override public DataFetcher<?> instrumentDataFetcher( DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters) { return (DataFetcher<Object>) dataFetchingEnvironment -> { Object data = dataFetcher.get(dataFetchingEnvironment); if (data instanceof ListenableFuture) { ListenableFuture<Object> listenableFuture = (ListenableFuture<Object>) data; CompletableFuture<Object> completableFuture = new CompletableFuture<>(); Futures.addCallback( listenableFuture, new FutureCallback<Object>() { @Override public void onSuccess(Object result) { completableFuture.complete(result); } @Override public void onFailure(Throwable t) { completableFuture.completeExceptionally(t); } }, executor); return completableFuture; } return data; }; } }; }
Example 4
Source File: AbstractCompositeDataFetcher.java From glitr with MIT License | 5 votes |
@Override public Object get(DataFetchingEnvironment environment) throws Exception { for (DataFetcher fetcher : fetchers) { Object result = fetcher.get(environment); if (result != null) { return result; } } return null; }