private DataFetchingFieldSelectionSetImpl(ExecutionContext executionContext, GraphQLFieldsContainer parentFieldType, MergedField parentFields) { this(parentFields, parentFieldType, executionContext.getGraphQLSchema(), executionContext.getVariables(), executionContext.getFragmentsByName()); }
@Internal ExecutionContextBuilder(ExecutionContext other) { instrumentation = other.getInstrumentation(); executionId = other.getExecutionId(); instrumentationState = other.getInstrumentationState(); graphQLSchema = other.getGraphQLSchema(); queryStrategy = other.getQueryStrategy(); mutationStrategy = other.getMutationStrategy(); subscriptionStrategy = other.getSubscriptionStrategy(); context = other.getContext(); root = other.getRoot(); document = other.getDocument(); operationDefinition = other.getOperationDefinition(); variables = new HashMap<>(other.getVariables()); fragmentsByName = new HashMap<>(other.getFragmentsByName()); dataLoaderRegistry = other.getDataLoaderRegistry(); errors = new ArrayList<>(other.getErrors()); }
private MergedSelectionSet getChildFields(ExecutionContext executionContext, GraphQLObjectType resolvedType, MergedField fields) { FieldCollectorParameters collectorParameters = newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(resolvedType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); return fieldCollector.collectFields(collectorParameters, fields); }
.schema(executionContext.getGraphQLSchema()) .objectType(operationRootType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build();
public static Builder newDataFetchingEnvironment(ExecutionContext executionContext) { return new Builder() .context(executionContext.getContext()) .root(executionContext.getRoot()) .graphQLSchema(executionContext.getGraphQLSchema()) .fragmentsByName(executionContext.getFragmentsByName()) .dataLoaderRegistry(executionContext.getDataLoaderRegistry()) .document(executionContext.getDocument()) .operationDefinition(executionContext.getOperationDefinition()) .variables(executionContext.getVariables()) .executionId(executionContext.getExecutionId()); }
/** * Called to turn an java object value into an graphql object value * * @param executionContext contains the top level execution parameters * @param parameters contains the parameters holding the fields to be executed and source object * @param resolvedObjectType the resolved object type * @param result the result to be coerced * * @return a promise to an {@link ExecutionResult} */ protected CompletableFuture<ExecutionResult> completeValueForObject(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLObjectType resolvedObjectType, Object result) { ExecutionStepInfo executionStepInfo = parameters.getExecutionStepInfo(); FieldCollectorParameters collectorParameters = newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(resolvedObjectType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, parameters.getField()); ExecutionStepInfo newExecutionStepInfo = executionStepInfo.changeTypeWithPreservedNonNull(resolvedObjectType); NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator(executionContext, newExecutionStepInfo); ExecutionStrategyParameters newParameters = parameters.transform(builder -> builder.executionStepInfo(newExecutionStepInfo) .fields(subFields) .nonNullFieldValidator(nonNullableFieldValidator) .source(result) ); // Calling this from the executionContext to ensure we shift back from mutation strategy to the query strategy. return executionContext.getQueryStrategy().execute(executionContext, newParameters); }
public FieldSubSelection createFieldSubSelection(ExecutionContext executionContext, FetchedValueAnalysis analysis) { ExecutionStepInfo executionInfo = analysis.getExecutionStepInfo(); MergedField field = analysis.getField(); Object source = analysis.getCompletedValue(); Object localContext = analysis.getFetchedValue().getLocalContext(); GraphQLOutputType sourceType = executionInfo.getUnwrappedNonNullType(); GraphQLObjectType resolvedObjectType = resolveType.resolveType(executionContext, field, source, executionInfo.getArguments(), sourceType); FieldCollectorParameters collectorParameters = newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(resolvedObjectType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, executionInfo.getField()); // it is not really a new step but rather a refinement ExecutionStepInfo newExecutionStepInfoWithResolvedType = executionInfo.changeTypeWithPreservedNonNull(resolvedObjectType); return FieldSubSelection.newFieldSubSelection() .source(source) .localContext(localContext) .mergedSelectionSet(subFields) .executionInfo(newExecutionStepInfoWithResolvedType) .build(); }
.schema(executionContext.getGraphQLSchema()) .objectType(operationRootType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build();
public Map<String, FragmentDefinition> getFragmentsByName() { return delegate.getFragmentsByName(); }
private DataFetchingFieldSelectionSetImpl(ExecutionContext executionContext, GraphQLFieldsContainer parentFieldType, MergedField parentFields) { this(parentFields, parentFieldType, executionContext.getGraphQLSchema(), executionContext.getVariables(), executionContext.getFragmentsByName()); }
ResolvedField collectFields(ExecutionContext context) { FieldCollectorParameters parameters = FieldCollectorParameters.newParameters() .schema(context.getGraphQLSchema()) .objectType(context.getGraphQLSchema().getQueryType()) .fragments(context.getFragmentsByName()) .variables(context.getVariables()) .build(); List<Field> fields = context.getOperationDefinition().getSelectionSet().getSelections().stream() .map(selection -> (Field) selection) .collect(Collectors.toList()); Field field = fields.get(0); GraphQLFieldDefinition fieldDefinition; if (GraphQLUtils.isIntrospectionField(field)) { fieldDefinition = Introspection.SchemaMetaFieldDef; } else { fieldDefinition = Objects.requireNonNull( getRootType(context.getGraphQLSchema(), context.getOperationDefinition()) .getFieldDefinition(field.getName())); } Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDefinition.getArguments(), field.getArguments(), context.getVariables()); return collectFields(parameters, fields.stream().map(f -> new ResolvedField(f, fieldDefinition, argumentValues)).collect(Collectors.toList())); }
@Internal ExecutionContextBuilder(ExecutionContext other) { instrumentation = other.getInstrumentation(); executionId = other.getExecutionId(); instrumentationState = other.getInstrumentationState(); graphQLSchema = other.getGraphQLSchema(); queryStrategy = other.getQueryStrategy(); mutationStrategy = other.getMutationStrategy(); subscriptionStrategy = other.getSubscriptionStrategy(); context = other.getContext(); root = other.getRoot(); document = other.getDocument(); operationDefinition = other.getOperationDefinition(); variables = new HashMap<>(other.getVariables()); fragmentsByName = new HashMap<>(other.getFragmentsByName()); dataLoaderRegistry = other.getDataLoaderRegistry(); errors = new ArrayList<>(other.getErrors()); }
private MergedSelectionSet getChildFields(ExecutionContext executionContext, GraphQLObjectType resolvedType, MergedField fields) { FieldCollectorParameters collectorParameters = newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(resolvedType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); return fieldCollector.collectFields(collectorParameters, fields); }
public ReactiveContext(ExecutionContext context, Object key) { super( context.getInstrumentation(), context.getExecutionId(), context.getGraphQLSchema(), context.getQueryStrategy(), context.getMutationStrategy(), context.getSubscriptionStrategy(), context.getFragmentsByName(), context.getOperationDefinition(), context.getVariables(), context.getRoot() ); this.key = key; this.parent = context; }
public static Builder newDataFetchingEnvironment(ExecutionContext executionContext) { return new Builder() .context(executionContext.getContext()) .root(executionContext.getRoot()) .graphQLSchema(executionContext.getGraphQLSchema()) .fragmentsByName(executionContext.getFragmentsByName()) .dataLoaderRegistry(executionContext.getDataLoaderRegistry()) .document(executionContext.getDocument()) .operationDefinition(executionContext.getOperationDefinition()) .variables(executionContext.getVariables()) .executionId(executionContext.getExecutionId()); }
.schema(executionContext.getGraphQLSchema()) .objectType(operationRootType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build();
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; }
/** * Called to turn an java object value into an graphql object value * * @param executionContext contains the top level execution parameters * @param parameters contains the parameters holding the fields to be executed and source object * @param resolvedObjectType the resolved object type * @param result the result to be coerced * * @return a promise to an {@link ExecutionResult} */ protected CompletableFuture<ExecutionResult> completeValueForObject(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLObjectType resolvedObjectType, Object result) { ExecutionStepInfo executionStepInfo = parameters.getExecutionStepInfo(); FieldCollectorParameters collectorParameters = newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(resolvedObjectType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, parameters.getField()); ExecutionStepInfo newExecutionStepInfo = executionStepInfo.changeTypeWithPreservedNonNull(resolvedObjectType); NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator(executionContext, newExecutionStepInfo); ExecutionStrategyParameters newParameters = parameters.transform(builder -> builder.executionStepInfo(newExecutionStepInfo) .fields(subFields) .nonNullFieldValidator(nonNullableFieldValidator) .source(result) ); // Calling this from the executionContext to ensure we shift back from mutation strategy to the query strategy. return executionContext.getQueryStrategy().execute(executionContext, newParameters); }
public FieldSubSelection createFieldSubSelection(ExecutionContext executionContext, FetchedValueAnalysis analysis) { ExecutionStepInfo executionInfo = analysis.getExecutionStepInfo(); MergedField field = analysis.getField(); Object source = analysis.getCompletedValue(); Object localContext = analysis.getFetchedValue().getLocalContext(); GraphQLOutputType sourceType = executionInfo.getUnwrappedNonNullType(); GraphQLObjectType resolvedObjectType = resolveType.resolveType(executionContext, field, source, executionInfo.getArguments(), sourceType); FieldCollectorParameters collectorParameters = newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(resolvedObjectType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, executionInfo.getField()); // it is not really a new step but rather a refinement ExecutionStepInfo newExecutionStepInfoWithResolvedType = executionInfo.changeTypeWithPreservedNonNull(resolvedObjectType); return FieldSubSelection.newFieldSubSelection() .source(source) .localContext(localContext) .mergedSelectionSet(subFields) .executionInfo(newExecutionStepInfoWithResolvedType) .build(); }
.schema(executionContext.getGraphQLSchema()) .objectType(operationRootType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build();