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); }
private FetchedValue unboxPossibleOptional(FetchedValue result) { return result.transform( builder -> builder.fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(result.getFetchedValue())) ); }
/** * Called to discover the field definition give the current parameters and the AST {@link Field} * * @param executionContext contains the top level execution parameters * @param parameters contains the parameters holding the fields to be executed and source object * @param field the field to find the definition of * * @return a {@link GraphQLFieldDefinition} */ protected GraphQLFieldDefinition getFieldDef(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Field field) { GraphQLObjectType parentType = (GraphQLObjectType) parameters.getExecutionStepInfo().getUnwrappedNonNullType(); return getFieldDef(executionContext.getGraphQLSchema(), parentType, field); }
private ExecutionStrategyParameters firstFieldOfSubscriptionSelection(ExecutionStrategyParameters parameters) { MergedSelectionSet fields = parameters.getFields(); MergedField firstField = fields.getSubField(fields.getKeys().get(0)); ExecutionPath fieldPath = parameters.getPath().segment(mkNameForPath(firstField.getSingleField())); return parameters.transform(builder -> builder.field(firstField).path(fieldPath)); }
private CompletableFuture<ExecutionResult> executeSubscriptionEvent(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Object eventPayload) { ExecutionContext newExecutionContext = executionContext.transform(builder -> builder.root(eventPayload)); ExecutionStrategyParameters newParameters = firstFieldOfSubscriptionSelection(parameters); FetchedValue fetchedValue = FetchedValue.newFetchedValue().fetchedValue(eventPayload) .rawFetchedValue(eventPayload) .localContext(parameters.getLocalContext()) .build(); return completeField(newExecutionContext, newParameters, fetchedValue).getFieldValue() .thenApply(executionResult -> wrapWithRootFieldName(newParameters, executionResult)); }
private ExecutionStrategyParameters newParameters(ExecutionStrategyParameters parameters, MergedSelectionSet fields, String fieldName) { MergedField currentField = fields.getSubField(fieldName); ExecutionPath fieldPath = parameters.getPath().segment(fieldName); return parameters .transform(builder -> builder.field(currentField).path(fieldPath)); }
public ExecutionStepInfo newExecutionStepInfoForListElement(ExecutionStepInfo executionInfo, int index) { GraphQLList fieldType = (GraphQLList) executionInfo.getUnwrappedNonNullType(); GraphQLOutputType typeInList = (GraphQLOutputType) fieldType.getWrappedType(); ExecutionPath indexedPath = executionInfo.getPath().segment(index); return executionInfo.transform(builder -> builder .parentInfo(executionInfo) .type(typeInList) .path(indexedPath)); }
public static Builder newFetchedValue(FetchedValue otherValue) { return new Builder() .fetchedValue(otherValue.getFetchedValue()) .rawFetchedValue(otherValue.getRawFetchedValue()) .errors(otherValue.getErrors()) .localContext(otherValue.getLocalContext()) ; }
private void handleFetchingException(ExecutionContext executionContext, ExecutionStrategyParameters parameters, DataFetchingEnvironment environment, Throwable e) { DataFetcherExceptionHandlerParameters handlerParameters = DataFetcherExceptionHandlerParameters.newExceptionParameters() .dataFetchingEnvironment(environment) .exception(e) .build(); DataFetcherExceptionHandlerResult handlerResult = dataFetcherExceptionHandler.onException(handlerParameters); handlerResult.getErrors().forEach(executionContext::addError); parameters.deferredErrorSupport().onFetchingException(parameters, e); }
private void collectField(FieldCollectorParameters parameters, Map<String, MergedField> fields, Field field) { if (!conditionalNodes.shouldInclude(parameters.getVariables(), field.getDirectives())) { return; } String name = getFieldEntryKey(field); if (fields.containsKey(name)) { MergedField curFields = fields.get(name); fields.put(name, curFields.transform(builder -> builder.addField(field))); } else { fields.put(name, MergedField.newMergedField(field).build()); } }
private void collectInlineFragment(FieldCollectorParameters parameters, List<String> visitedFragments, Map<String, MergedField> fields, InlineFragment inlineFragment) { if (!conditionalNodes.shouldInclude(parameters.getVariables(), inlineFragment.getDirectives()) || !doesFragmentConditionMatch(parameters, inlineFragment)) { return; } collectFields(parameters, inlineFragment.getSelectionSet(), visitedFragments, fields); }
private boolean doesFragmentConditionMatch(FieldCollectorParameters parameters, FragmentDefinition fragmentDefinition) { GraphQLType conditionType; conditionType = getTypeFromAST(parameters.getGraphQLSchema(), fragmentDefinition.getTypeCondition()); return checkTypeCondition(parameters, conditionType); }
public Execution(ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy, ExecutionStrategy subscriptionStrategy, Instrumentation instrumentation) { this.queryStrategy = queryStrategy != null ? queryStrategy : new AsyncExecutionStrategy(); this.mutationStrategy = mutationStrategy != null ? mutationStrategy : new AsyncSerialExecutionStrategy(); this.subscriptionStrategy = subscriptionStrategy != null ? subscriptionStrategy : new AsyncExecutionStrategy(); this.instrumentation = instrumentation; }
@Override public DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) { // // do your custom handling here. The parameters have all you need GraphQLError buildCustomError = buildCustomError(handlerParameters); return DataFetcherExceptionHandlerResult.newResult() .error(buildCustomError).build(); } };
public NonNullableFieldWasNullError(NonNullableFieldWasNullException exception) { this.message = exception.getMessage(); this.path = exception.getPath().toList(); }
/** * Takes the current path and adds a new segment to it, returning a new path * * @param segment the string path segment to add * * @return a new path containing that segment */ public ExecutionPath segment(String segment) { return new ExecutionPath(this, new StringPathSegment(segment)); }
/** * Takes the current path and adds a new segment to it, returning a new path * * @param segment the int path segment to add * * @return a new path containing that segment */ public ExecutionPath segment(int segment) { return new ExecutionPath(this, new IntPathSegment(segment)); }
@Override public MergedSelectionSet get() { return MergedSelectionSet.newMergedSelectionSet().build(); }
private FetchedValue fetchField(ExecutionContext executionContext, ExecutionStrategyParameters parameters, MergedSelectionSet fields, String fieldName) { MergedField currentField = fields.getSubField(fieldName); ExecutionPath fieldPath = parameters.getPath().segment(fieldName); ExecutionStrategyParameters newParameters = parameters .transform(builder -> builder.field(currentField).path(fieldPath)); return fetchField(executionContext, newParameters).join(); }
private boolean doesFragmentConditionMatch(FieldCollectorParameters parameters, InlineFragment inlineFragment) { if (inlineFragment.getTypeCondition() == null) { return true; } GraphQLType conditionType; conditionType = getTypeFromAST(parameters.getGraphQLSchema(), inlineFragment.getTypeCondition()); return checkTypeCondition(parameters, conditionType); }