.schema(executionContext.getGraphQLSchema()) .objectType(operationRootType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build();
.schema(executionContext.getGraphQLSchema()) .objectType(operationRootType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build();
operationRootType = Common.getOperationRootType(executionContext.getGraphQLSchema(), operationDefinition); FieldCollectorParameters collectorParameters = FieldCollectorParameters.newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(operationRootType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); MergedSelectionSet mergedSelectionSet = fieldCollector.collectFields(collectorParameters, operationDefinition.getSelectionSet()); ExecutionStepInfo executionInfo = newExecutionStepInfo().type(operationRootType).path(ExecutionPath.rootPath()).build();
/** * 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); }
private void traverseFields(MergedField fieldList, GraphQLFieldsContainer parentFieldType, String fieldPrefix) { FieldCollectorParameters parameters = FieldCollectorParameters.newParameters() .schema(graphQLSchema) .objectType(asObjectTypeOrNull(parentFieldType)) .fragments(fragmentsByName) .variables(variables) .build(); MergedSelectionSet collectedFields = fieldCollector.collectFields(parameters, fieldList); for (Map.Entry<String, MergedField> entry : collectedFields.getSubFields().entrySet()) { String fieldName = mkFieldName(fieldPrefix, entry.getKey()); MergedField collectedFieldList = entry.getValue(); selectionSetFields.put(fieldName, collectedFieldList); Field field = collectedFieldList.getSingleField(); GraphQLFieldDefinition fieldDef = Introspection.getFieldDef(graphQLSchema, parentFieldType, field.getName()); GraphQLType unwrappedType = GraphQLTypeUtil.unwrapAll(fieldDef.getType()); Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDef.getArguments(), field.getArguments(), variables); selectionSetFieldArgs.put(fieldName, argumentValues); selectionSetFieldDefinitions.put(fieldName, fieldDef); flattenedFields.add(fieldName); if (unwrappedType instanceof GraphQLFieldsContainer) { traverseFields(collectedFieldList, (GraphQLFieldsContainer) unwrappedType, fieldName); } } }
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(); }
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())); }
public static Builder newParameters() { return new Builder(); }
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); }
operationRootType = Common.getOperationRootType(executionContext.getGraphQLSchema(), operationDefinition); FieldCollectorParameters collectorParameters = FieldCollectorParameters.newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(operationRootType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); MergedSelectionSet mergedSelectionSet = fieldCollector.collectFields(collectorParameters, operationDefinition.getSelectionSet()); ExecutionStepInfo executionInfo = newExecutionStepInfo().type(operationRootType).path(ExecutionPath.rootPath()).build();
/** * 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); }
private void traverseFields(MergedField fieldList, GraphQLFieldsContainer parentFieldType, String fieldPrefix) { FieldCollectorParameters parameters = FieldCollectorParameters.newParameters() .schema(graphQLSchema) .objectType(asObjectTypeOrNull(parentFieldType)) .fragments(fragmentsByName) .variables(variables) .build(); MergedSelectionSet collectedFields = fieldCollector.collectFields(parameters, fieldList); for (Map.Entry<String, MergedField> entry : collectedFields.getSubFields().entrySet()) { String fieldName = mkFieldName(fieldPrefix, entry.getKey()); MergedField collectedFieldList = entry.getValue(); selectionSetFields.put(fieldName, collectedFieldList); Field field = collectedFieldList.getSingleField(); GraphQLFieldDefinition fieldDef = Introspection.getFieldDef(graphQLSchema, parentFieldType, field.getName()); GraphQLType unwrappedType = GraphQLTypeUtil.unwrapAll(fieldDef.getType()); Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDef.getArguments(), field.getArguments(), variables); selectionSetFieldArgs.put(fieldName, argumentValues); selectionSetFieldDefinitions.put(fieldName, fieldDef); flattenedFields.add(fieldName); if (unwrappedType instanceof GraphQLFieldsContainer) { traverseFields(collectedFieldList, (GraphQLFieldsContainer) unwrappedType, fieldName); } } }
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(); }
public static Builder newParameters() { return new Builder(); }
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); }