String fieldNameA = fieldA.getName(); String fieldNameB = fieldB.getName(); if (!sameArguments(fieldA.getArguments(), fieldB.getArguments())) { String reason = format("%s: they have differing arguments", responseName); return new Conflict(responseName, reason, fieldA, fieldB); SelectionSet selectionSet1 = fieldA.getSelectionSet(); SelectionSet selectionSet2 = fieldB.getSelectionSet(); if (selectionSet1 != null && selectionSet2 != null) { Set<String> visitedFragmentSpreads = new LinkedHashSet<>();
@Override public Field deepCopy() { return new Field(name, alias, deepCopy(arguments), deepCopy(directives), deepCopy(selectionSet), getSourceLocation(), getComments(), getIgnoredChars() ); }
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(); }
public static boolean requestContainsPageInfo(Field field) { return field.getSelectionSet().getSelections().stream() .anyMatch(f -> f instanceof Field && ConnectionContainer.PAGE_INFO_KEYWORD.equals(((Field) f).getName())); } }
/** * All merged fields have the same name. * * WARNING: This is not always the key in the execution result, because of possible aliases. See {@link #getResultKey()} * * @return the name of of the merged fields. */ public String getName() { return fields.get(0).getName(); }
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 )); }; }
String fieldName = recordsSelection.get().getName(); )).orElse(environment); queryField = new Field(fieldName, field.getArguments(), recordsSelection.get().getSelectionSet()); .map(contentField -> getCountQuery(countQueryEnvironment, countQueryField).getSingleResult()) .orElseGet(() -> getCountQuery(environment, new Field("count")).getSingleResult());
QueryTraversalContext parentEnv = context.getVarFromParents(QueryTraversalContext.class); GraphQLFieldDefinition fieldDefinition = Introspection.getFieldDef(schema, parentEnv.getRawType(), field.getName()); boolean isTypeNameIntrospectionField = fieldDefinition == Introspection.TypeNameMetaFieldDef; 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, if (!conditionalNodes.shouldInclude(variables, field.getDirectives())) { return TraversalControl.ABORT;
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 JsonNode getFieldJson(Field field, String parentId, String nodeId, String parentType) { ObjectMapper mapper = new ObjectMapper(); ObjectNode query = mapper.createObjectNode(); query.put("name", field.getName()); query.put("alias", field.getAlias()); query.put("parentId", parentId); query.put("nodeId", nodeId); List<Argument> args = field.getArguments(); String contextLdKey = (field.getAlias()==null) ? field.getName() : field.getAlias(); String contextLdValue = getContextLdValue(contextLdKey); this.ldContext.put(contextLdKey, contextLdValue); if (args.isEmpty()) { query.set("args", null); } else { query.set("args", getArgsJson(args)); } FieldOfTypeConfig fieldConfig = hgqlSchema.getTypes().get(parentType).getField(field.getName()); String targetName = fieldConfig.getTargetName(); query.put("targetName", targetName); query.set("fields", this.traverse(field, nodeId, parentType)); return query; }
/** * All merged fields share the same arguments. * * @return the list of arguments */ public List<Argument> getArguments() { return getSingleField().getArguments(); }
@Override public void checkField(Field field) { GraphQLOutputType type = getValidationContext().getOutputType(); if (type == null) return; if (isLeaf(type)) { if (field.getSelectionSet() != null) { String message = String.format("Sub selection not allowed on leaf type %s of field %s", type.getName(), field.getName()); addError(ValidationErrorType.SubSelectionNotAllowed, field.getSourceLocation(), message); } } else { if (field.getSelectionSet() == null) { String message = String.format("Sub selection required for type %s of field %s", type.getName(), field.getName()); addError(ValidationErrorType.SubSelectionRequired, field.getSourceLocation(), message); } } } }
@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); }
public MergedSelectionSet collectFields(FieldCollectorParameters parameters, MergedField mergedField) { Map<String, MergedField> subFields = new LinkedHashMap<>(); List<String> visitedFragments = new ArrayList<>(); for (Field field : mergedField.getFields()) { if (field.getSelectionSet() == null) { continue; } this.collectFields(parameters, field.getSelectionSet(), visitedFragments, subFields); } return newMergedSelectionSet().subFields(subFields).build(); }
@Override public void checkField(Field field) { GraphQLCompositeType parentType = getValidationContext().getParentType(); // this means the parent type is not a CompositeType, which is an error handled elsewhere if (parentType == null) return; GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef(); if (fieldDef == null) { String message = String.format("Field '%s' in type '%s' is undefined", field.getName(), parentType.getName()); addError(ValidationErrorType.FieldUndefined, field.getSourceLocation(), message); } } }
@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); } } }
@Override public void checkField(Field field) { checkDirectivesUniqueness(field, field.getDirectives()); }
public Field build() { Field field = new Field(name, alias, arguments, directives, selectionSet, sourceLocation, comments, ignoredChars); return field; } }
public static boolean requestContainsPageInfo(Field field) { return field.getSelectionSet().getSelections().stream() .anyMatch(f -> f instanceof Field && ConnectionContainer.PAGE_INFO_KEYWORD.equals(((Field) f).getName())); } }