public InstrumentationFieldFetchParameters(ExecutionContext getExecutionContext, GraphQLFieldDefinition fieldDef, DataFetchingEnvironment environment, ExecutionStrategyParameters executionStrategyParameters, boolean trivialDataFetcher) { super(getExecutionContext, fieldDef, environment.getExecutionStepInfo()); this.environment = environment; this.executionStrategyParameters = executionStrategyParameters; this.trivialDataFetcher = trivialDataFetcher; }
private InstrumentationFieldFetchParameters(ExecutionContext getExecutionContext, GraphQLFieldDefinition fieldDef, DataFetchingEnvironment environment, InstrumentationState instrumentationState, ExecutionStrategyParameters executionStrategyParameters, boolean trivialDataFetcher) { super(getExecutionContext, fieldDef, environment.getExecutionStepInfo(), instrumentationState); this.environment = environment; this.executionStrategyParameters = executionStrategyParameters; this.trivialDataFetcher = trivialDataFetcher; }
public ExecutionPath getPath() { return dataFetchingEnvironment.getExecutionStepInfo().getPath(); }
long duration = now - startFieldFetch; long startOffset = startFieldFetch - startRequestNanos; ExecutionStepInfo executionStepInfo = dataFetchingEnvironment.getExecutionStepInfo();
public InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters) { CallStack callStack = parameters.getInstrumentationState(); ExecutionPath path = parameters.getEnvironment().getExecutionStepInfo().getPath(); int level = path.getLevel(); return new InstrumentationContext<Object>() { @Override public void onDispatched(CompletableFuture result) { boolean dispatchNeeded; synchronized (callStack) { callStack.increaseFetchCount(level); dispatchNeeded = dispatchIfNeeded(callStack, level); } if (dispatchNeeded) { dispatch(); } } @Override public void onCompleted(Object result, Throwable t) { } }; }
public InstrumentationFieldFetchParameters(ExecutionContext getExecutionContext, GraphQLFieldDefinition fieldDef, DataFetchingEnvironment environment, ExecutionStrategyParameters executionStrategyParameters, boolean trivialDataFetcher) { super(getExecutionContext, fieldDef, environment.getExecutionStepInfo()); this.environment = environment; this.executionStrategyParameters = executionStrategyParameters; this.trivialDataFetcher = trivialDataFetcher; }
private InstrumentationFieldFetchParameters(ExecutionContext getExecutionContext, GraphQLFieldDefinition fieldDef, DataFetchingEnvironment environment, InstrumentationState instrumentationState, ExecutionStrategyParameters executionStrategyParameters, boolean trivialDataFetcher) { super(getExecutionContext, fieldDef, environment.getExecutionStepInfo(), instrumentationState); this.environment = environment; this.executionStrategyParameters = executionStrategyParameters; this.trivialDataFetcher = trivialDataFetcher; }
@Override public ExecutionStepInfo getExecutionStepInfo() { return delegate.getExecutionStepInfo(); }
@SuppressWarnings("WeakerAccess") protected Object convertOutputForNonSubscription(Publisher<T> original, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) { return collect(original, resolutionEnvironment.dataFetchingEnvironment.getExecutionStepInfo()); }
public ExecutionPath getPath() { return dataFetchingEnvironment.getExecutionStepInfo().getPath(); }
private EntityType getEntityTypeForQuery(DataFetchingEnvironment graphEnv) { String entityName = graphEnv.getExecutionStepInfo().getType().getName(); if (entityName == null) { entityName = graphEnv.getExecutionStepInfo().getType().getChildren().get(0).getName(); } EntityType et = env.getDefinitionsSet().getFirstEntityTypeByInterfaceName(namespace + ".model." + entityName); requireNonNull(et, "EntityType must exist"); return et; }
public InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters) { CallStack callStack = parameters.getInstrumentationState(); ExecutionPath path = parameters.getEnvironment().getExecutionStepInfo().getPath(); int level = path.getLevel(); return new InstrumentationContext<Object>() { @Override public void onDispatched(CompletableFuture result) { boolean dispatchNeeded; synchronized (callStack) { callStack.increaseFetchCount(level); dispatchNeeded = dispatchIfNeeded(callStack, level); } if (dispatchNeeded) { dispatch(); } } @Override public void onCompleted(Object result, Throwable t) { } }; }
/** * This will set up the {@link GraphQLError#getLocations()} and {@link graphql.GraphQLError#getPath()} for you from the * fetching environment. * * @param dataFetchingEnvironment the data fetching environment * * @return a builder of {@link graphql.GraphQLError}s */ public static GraphqlErrorBuilder newError(DataFetchingEnvironment dataFetchingEnvironment) { return new GraphqlErrorBuilder() .location(dataFetchingEnvironment.getField().getSourceLocation()) .path(dataFetchingEnvironment.getExecutionStepInfo().getPath()); }
@Override public Object get(DataFetchingEnvironment graphEnv) throws Exception { EntityContext ctx = new EntityContext(env, namespace); QueryObject<Object> query = null; if (customQueries != null) { query = (QueryObject<Object>)customQueries.getQuery(graphEnv.getField().getName()); } if (query == null) { EntityType entityType = getEntityTypeForQuery(graphEnv); query = buildQuery(graphEnv, entityType); } else { buildQuery(graphEnv, query); } List<Entity> result = ctx.performQuery(query).getEntityList(); LOG.debug("Processed {} rows", ctx.getStatistics().getNumberOfRowsRead()); if (graphEnv.getExecutionStepInfo().getType() instanceof GraphQLList) { return Entity2Map.toListOfMaps(result); } else if (result.size() == 1) { return Entity2Map.toMap(result.get(0)); } throw new IllegalStateException("too many results"); }
@Override public T get(DataFetchingEnvironment environment) throws Exception { Object source = environment.getSource(); if (source != null && (!declaringClass.isInstance(source)) && !(source instanceof Map)) { environment = new DataFetchingEnvironmentImpl(newInstance(declaringClass, source), environment.getArguments(), environment.getContext(), environment.getRoot(), environment.getFieldDefinition(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getExecutionStepInfo(), environment.getExecutionContext()); } return dataFetcher.get(environment); }
public WherePredicateEnvironment(DataFetchingEnvironment environment, GraphQLFieldDefinition fieldDefinition, Map<String, Object> arguments) { super( environment.getSource(), arguments, environment.getContext(), environment.getRoot(), fieldDefinition, //environment.getFieldDefinition(), environment.getFields(), fieldDefinition.getType(), // environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getExecutionStepInfo(), environment.getExecutionContext() ); } }
public ArgumentEnvironment(DataFetchingEnvironment environment, String argumentName) { super( environment.getSource(), environment.getArgument(argumentName), environment.getContext(), environment.getRoot(), environment.getFieldDefinition(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getExecutionStepInfo(), environment.getExecutionContext() ); } }
@SuppressWarnings( "serial" ) protected Predicate getWherePredicate(CriteriaBuilder cb, Root<?> root, From<?,?> path, DataFetchingEnvironment environment, Argument argument) { ObjectValue whereValue = getValue(argument); if(whereValue.getChildren().isEmpty()) return cb.conjunction(); return getArgumentPredicate(cb, (path != null) ? path : root, new DataFetchingEnvironmentImpl( environment.getSource(), new LinkedHashMap<String,Object>() {{ put(Logical.AND.name(), environment.getArguments()); }}, environment.getContext(), environment.getRoot(), environment.getFieldDefinition(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getExecutionStepInfo(), environment.getExecutionContext() ), new Argument(Logical.AND.name(), whereValue) ); }
@SuppressWarnings("serial") private PredicateFilter getPredicateFilter(ObjectField objectField, DataFetchingEnvironment environment, Argument argument) { EnumSet<PredicateFilter.Criteria> options = EnumSet.of(PredicateFilter.Criteria.valueOf(argument.getName())); Object filterValue = convertValue( new DataFetchingEnvironmentImpl( environment.getSource(), new LinkedHashMap<String,Object>() {{ put(objectField.getName(), environment.getArgument(argument.getName())); }}, environment.getContext(), environment.getRoot(), environment.getFieldDefinition(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getExecutionStepInfo(), environment.getExecutionContext() ), new Argument(objectField.getName(), argument.getValue()), argument.getValue() ); return new PredicateFilter(objectField.getName(), filterValue, options ); }
public static FragmentDirectiveCollector collect(DataFetchingEnvironment env, ExecutionStepInfo step) { FragmentDirectiveCollector fragmentDirectiveCollector = new FragmentDirectiveCollector(env); // This is safe because top-level fields don't get to here and all deeper fields at least have a parent (source object) and a grand-parent (query root) ExecutionStepInfo rootStep = step.getParent().getParent(); if (rootStep == null) { //Should never be possible, see above return fragmentDirectiveCollector; } GraphQLType rootParentType = GraphQLUtils.unwrapNonNull(rootStep.getType()); while(!(rootParentType instanceof GraphQLObjectType)) { rootStep = rootStep.getParent(); rootParentType = GraphQLUtils.unwrapNonNull(rootStep.getType()); } QueryTraversal traversal = QueryTraversal.newQueryTraversal() .fragmentsByName(env.getExecutionContext().getFragmentsByName()) .schema(env.getGraphQLSchema()) .variables(env.getExecutionContext().getVariables()) .root(env.getExecutionStepInfo().getParent().getField()) .rootParentType((GraphQLObjectType) rootParentType) .build(); traversal.visitPostOrder(fragmentDirectiveCollector); return fragmentDirectiveCollector; }