/** * All merged fields share the same arguments. * * @return the list of arguments */ public List<Argument> getArguments() { return getSingleField().getArguments(); }
@Override public void visitField(QueryVisitorFieldEnvironment env) { Field field = env.getField(); if (field.getArguments() != null && !field.getArguments().isEmpty()) { // // only fields that have arguments make any sense to placed in play // since only they have variable input FieldAndArguments fieldArguments = new FieldAndArgumentsImpl(env); ExecutionPath path = fieldArguments.getPath(); List<FieldAndArguments> list = fieldArgumentsMap.getOrDefault(path, new ArrayList<>()); list.add(fieldArguments); fieldArgumentsMap.put(path, list); } } });
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); } } }
private Builder(Field existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.alias = existing.getAlias(); this.arguments = existing.getArguments(); this.directives = existing.getDirectives(); this.selectionSet = existing.getSelectionSet(); this.ignoredChars = existing.getIgnoredChars(); }
@Override public TraversalControl visitField(Field node, TraverserContext<Node> context) { Field changedNode = node.transform(builder -> { builder.arguments(sort(node.getArguments(), comparing(Argument::getName))); builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.selectionSet(sortSelectionSet(node.getSelectionSet())); }); return changeNode(context, changedNode); }
@Override public void checkField(Field field) { GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef(); if (fieldDef == null) return; Map<String, Argument> argumentMap = argumentMap(field.getArguments()); for (GraphQLArgument graphQLArgument : fieldDef.getArguments()) { Argument argument = argumentMap.get(graphQLArgument.getName()); if (argument == null && (isNonNull(graphQLArgument.getType())) && (graphQLArgument.getDefaultValue() == null)) { String message = String.format("Missing field argument %s", graphQLArgument.getName()); addError(ValidationErrorType.MissingFieldArgument, field.getSourceLocation(), message); } } }
if (!sameArguments(fieldA.getArguments(), fieldB.getArguments())) { String reason = format("%s: they have differing arguments", responseName); return new Conflict(responseName, reason, fieldA, fieldB);
private NodePrinter<Field> field() { final String argSep = compactMode ? "," : ", "; final String aliasSuffix = compactMode ? ":" : ": "; return (out, node) -> { String alias = wrap("", node.getAlias(), aliasSuffix); String name = node.getName(); String arguments = wrap("(", join(node.getArguments(), argSep), ")"); String directives = directives(node.getDirectives()); String selectionSet = node(node.getSelectionSet()); out.printf("%s", spaced( alias + name + arguments, directives, selectionSet )); }; }
private CompletableFuture<List<ExecutionNode>> resolveField(ExecutionContext executionContext, ExecutionStrategyParameters parameters, String fieldName, ExecutionNode node) { GraphQLObjectType parentType = node.getType(); MergedField fields = node.getFields().get(fieldName); GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.getSingleField()); Instrumentation instrumentation = executionContext.getInstrumentation(); ExecutionStepInfo executionStepInfo = parameters.getExecutionStepInfo(); InstrumentationContext<ExecutionResult> fieldCtx = instrumentation.beginField( new InstrumentationFieldParameters(executionContext, fieldDef, executionStepInfo) ); CompletableFuture<FetchedValues> fetchedData = fetchData(executionContext, parameters, fieldName, node, fieldDef); CompletableFuture<List<ExecutionNode>> result = fetchedData.thenApply((fetchedValues) -> { GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry(); Map<String, Object> argumentValues = valuesResolver.getArgumentValues( codeRegistry, fieldDef.getArguments(), fields.getSingleField().getArguments(), executionContext.getVariables()); return completeValues(executionContext, fetchedValues, executionStepInfo, fieldName, fields, argumentValues); }); fieldCtx.onDispatched(null); result = result.whenComplete((nodes, throwable) -> fieldCtx.onCompleted(null, throwable)); return result; }
Map<String, Object> argumentValues = valuesResolver.getArgumentValues( codeRegistry, fieldDef.getArguments(), fields.getSingleField().getArguments(), executionContext.getVariables());
public CompletableFuture<FetchedValue> fetchValue(ExecutionContext executionContext, Object source, Object localContext, MergedField sameFields, ExecutionStepInfo executionInfo) { Field field = sameFields.getSingleField(); GraphQLFieldDefinition fieldDef = executionInfo.getFieldDefinition(); GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry(); GraphQLFieldsContainer parentType = getFieldsContainer(executionInfo); Map<String, Object> argumentValues = valuesResolver.getArgumentValues(codeRegistry, fieldDef.getArguments(), field.getArguments(), executionContext.getVariables()); GraphQLOutputType fieldType = fieldDef.getType(); DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(executionContext, fieldType, sameFields); DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext) .source(source) .localContext(localContext) .arguments(argumentValues) .fieldDefinition(fieldDef) .mergedField(sameFields) .fieldType(fieldType) .executionStepInfo(executionInfo) .parentType(parentType) .selectionSet(fieldCollector) .build(); ExecutionId executionId = executionContext.getExecutionId(); ExecutionPath path = executionInfo.getPath(); return callDataFetcher(codeRegistry, parentType, fieldDef, environment, executionId, path) .thenApply(rawFetchedValue -> FetchedValue.newFetchedValue() .fetchedValue(rawFetchedValue) .rawFetchedValue(rawFetchedValue) .build()) .exceptionally(exception -> handleExceptionWhileFetching(field, path, exception)) .thenApply(result -> unboxPossibleDataFetcherResult(sameFields, path, result, localContext)) .thenApply(this::unboxPossibleOptional); }
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(codeRegistry, fieldDef.getArguments(), field.getArguments(), executionContext.getVariables());
GraphQLFieldsContainer fieldsContainer = !isTypeNameIntrospectionField ? (GraphQLFieldsContainer) unwrapAll(parentEnv.getOutputType()) : null; GraphQLCodeRegistry codeRegistry = schema.getCodeRegistry(); Map<String, Object> argumentValues = valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), field.getArguments(), variables); QueryVisitorFieldEnvironment environment = new QueryVisitorFieldEnvironmentImpl(isTypeNameIntrospectionField, field,
/** * All merged fields share the same arguments. * * @return the list of arguments */ public List<Argument> getArguments() { return getSingleField().getArguments(); }
protected Optional<Argument> extractArgument(DataFetchingEnvironment environment, Field field, String argumentName) { return field.getArguments() .stream() .filter(it -> argumentName.equals(it.getName())) .findFirst(); }
private Optional<Argument> getPageArgument(Field field) { return field.getArguments() .stream() .filter(it -> GraphQLJpaSchemaBuilder.PAGE_PARAM_NAME.equals(it.getName())) .findFirst(); }
private TypedQuery<Long> getCountQuery(DataFetchingEnvironment environment, Field field) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = cb.createQuery(Long.class); Root<?> root = query.from(entityType); SingularAttribute<?,?> idAttribute = entityType.getId(Object.class); query.select(cb.count(root.get(idAttribute.getName()))); List<Predicate> predicates = field.getArguments().stream() .map(it -> getPredicate(cb, root, null, environment, it)) .filter(it -> it != null) .collect(Collectors.toList()); query.where(predicates.toArray(new Predicate[predicates.size()])); return entityManager.createQuery(query); }
private void collectField(FieldCollectorParameters parameters, Map<String, List<ResolvedField>> fields, Field field, GraphQLFieldsContainer parent) { if (!conditionalNodes.shouldInclude(parameters.getVariables(), field.getDirectives())) { return; } GraphQLFieldDefinition fieldDefinition = parent.getFieldDefinition(field.getName()); Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDefinition.getArguments(), field.getArguments(), parameters.getVariables()); ResolvedField node = new ResolvedField(field, fieldDefinition, argumentValues); fields.putIfAbsent(node.getName(), new ArrayList<>()); fields.get(node.getName()).add(node); }
@Override public TraversalControl visitField(Field node, TraverserContext<Node> context) { Field changedNode = node.transform(builder -> { builder.arguments(sort(node.getArguments(), comparing(Argument::getName))); builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.selectionSet(sortSelectionSet(node.getSelectionSet())); }); return changeNode(context, changedNode); }
private Builder(Field existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.alias = existing.getAlias(); this.arguments = existing.getArguments(); this.directives = existing.getDirectives(); this.selectionSet = existing.getSelectionSet(); this.ignoredChars = existing.getIgnoredChars(); }