private void checkFieldsDirectives(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, List<FieldDefinition> fieldDefinitions) { fieldDefinitions.forEach(definition -> { checkDirectives(FIELD_DEFINITION, errors, typeRegistry, definition, definition.getName(), definition.getDirectives()); // // and check its arguments definition.getInputValueDefinitions().forEach(arg -> checkDirectives(ARGUMENT_DEFINITION, errors, typeRegistry, arg, arg.getName(), arg.getDirectives())); }); }
private void checkObjTypeFields(List<GraphQLError> errors, ObjectTypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions) { // field unique ness checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(typeDefinition, fieldDef)); // field arg unique ness fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(typeDefinition, fld, name))); // directive checks fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(typeDefinition, fld, directiveName))); fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(typeDefinition, fld)); checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(typeDefinition, fld, argumentName)); })); }
private void checkInterfaceFields(List<GraphQLError> errors, InterfaceTypeDefinition interfaceType, List<FieldDefinition> fieldDefinitions) { // field unique ness checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(interfaceType, fieldDef)); // field arg unique ness fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(interfaceType, fld, name))); // directive checks fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(interfaceType, fld, directiveName))); fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(interfaceType, fld)); checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(interfaceType, fld, argumentName)); })); }
@Override public TraversalControl visitFieldDefinition(FieldDefinition node, TraverserContext<Node> context) { FieldDefinition changedNode = node.transform(builder -> { builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.inputValueDefinitions(sort(node.getInputValueDefinitions(), comparing(InputValueDefinition::getName))); }); return changeNode(context, changedNode); }
private Builder(FieldDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.name = existing.getName(); this.comments = existing.getComments(); this.type = existing.getType(); this.description = existing.getDescription(); this.inputValueDefinitions = existing.getInputValueDefinitions(); this.directives = existing.getDirectives(); this.ignoredChars = existing.getIgnoredChars(); }
extension.getFieldDefinitions().forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName))); fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
extension.getFieldDefinitions().forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName))); fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
private NodePrinter<FieldDefinition> fieldDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { out.printf("%s", comments(node)); String args; if (hasComments(node.getInputValueDefinitions()) && !compactMode) { args = join(node.getInputValueDefinitions(), "\n"); out.printf("%s", node.getName() + wrap("(\n", args, "\n)") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } else { args = join(node.getInputValueDefinitions(), argSep); out.printf("%s", node.getName() + wrap("(", args, ")") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } }; }
private FieldDefAndDirectiveParams buildField(BuildContext buildCtx, TypeDefinition parentType, FieldDefinition fieldDef) { buildCtx.enterNode(fieldDef); GraphQLFieldDefinition.Builder builder = GraphQLFieldDefinition.newFieldDefinition(); builder.definition(fieldDef); builder.name(fieldDef.getName()); builder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription())); builder.deprecate(schemaGeneratorHelper.buildDeprecationReason(fieldDef.getDirectives())); GraphQLDirective[] directives = buildDirectives(fieldDef.getDirectives(), Collections.emptyList(), DirectiveLocation.FIELD_DEFINITION, buildCtx.getDirectiveDefinitions()); builder.withDirectives( directives ); fieldDef.getInputValueDefinitions().forEach(inputValueDefinition -> builder.argument(buildArgument(buildCtx, inputValueDefinition))); GraphQLOutputType fieldType = buildOutputType(buildCtx, fieldDef.getType()); builder.type(fieldType); GraphQLFieldDefinition fieldDefinition = builder.build(); // if they have already wired in a fetcher - then leave it alone FieldCoordinates coordinates = FieldCoordinates.coordinates(parentType.getName(), fieldDefinition.getName()); if (!buildCtx.codeRegistry.hasDataFetcher(coordinates)) { DataFetcherFactory dataFetcherFactory = buildDataFetcherFactory(buildCtx, parentType, fieldDef, fieldType, Arrays.asList(directives)); buildCtx.getCodeRegistry().dataFetcher(coordinates, dataFetcherFactory); } return buildCtx.exitNode(new FieldDefAndDirectiveParams(fieldDefinition, buildCtx.mkBehaviourParams())); }
private void checkField(DiffCtx ctx, TypeDefinition old, FieldDefinition oldField, FieldDefinition newField) { Type oldFieldType = oldField.getType(); Type newFieldType = newField.getType(); DiffCategory category = checkTypeWithNonNullAndList(oldFieldType, newFieldType); if (category != null) { ctx.report(DiffEvent.apiBreakage() .category(category) .typeName(old.getName()) .typeKind(getTypeKind(old)) .fieldName(oldField.getName()) .components(getAstDesc(oldFieldType), getAstDesc(newFieldType)) .reasonMsg("The new API has changed field '%s' from type '%s' to '%s'", mkDotName(old.getName(), oldField.getName()), getAstDesc(oldFieldType), getAstDesc(newFieldType)) .build()); } checkFieldArguments(ctx, old, oldField, oldField.getInputValueDefinitions(), newField.getInputValueDefinitions()); checkDirectives(ctx, old, oldField.getDirectives(), newField.getDirectives()); // // and down we go again recursively via fields // checkType(ctx, oldFieldType, newFieldType); }
private void checkFieldsDirectives(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, List<FieldDefinition> fieldDefinitions) { fieldDefinitions.forEach(definition -> { checkDirectives(FIELD_DEFINITION, errors, typeRegistry, definition, definition.getName(), definition.getDirectives()); // // and check its arguments definition.getInputValueDefinitions().forEach(arg -> checkDirectives(ARGUMENT_DEFINITION, errors, typeRegistry, arg, arg.getName(), arg.getDirectives())); }); }
private void checkInterfaceFields(List<GraphQLError> errors, InterfaceTypeDefinition interfaceType, List<FieldDefinition> fieldDefinitions) { // field unique ness checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(interfaceType, fieldDef)); // field arg unique ness fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(interfaceType, fld, name))); // directive checks fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(interfaceType, fld, directiveName))); fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(interfaceType, fld)); checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(interfaceType, fld, argumentName)); })); }
private void checkObjTypeFields(List<GraphQLError> errors, ObjectTypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions) { // field unique ness checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(typeDefinition, fieldDef)); // field arg unique ness fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(typeDefinition, fld, name))); // directive checks fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(typeDefinition, fld, directiveName))); fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(typeDefinition, fld)); checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(typeDefinition, fld, argumentName)); })); }
@Override public TraversalControl visitFieldDefinition(FieldDefinition node, TraverserContext<Node> context) { FieldDefinition changedNode = node.transform(builder -> { builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.inputValueDefinitions(sort(node.getInputValueDefinitions(), comparing(InputValueDefinition::getName))); }); return changeNode(context, changedNode); }
private Builder(FieldDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.name = existing.getName(); this.comments = existing.getComments(); this.type = existing.getType(); this.description = existing.getDescription(); this.inputValueDefinitions = existing.getInputValueDefinitions(); this.directives = existing.getDirectives(); this.ignoredChars = existing.getIgnoredChars(); }
extension.getFieldDefinitions().forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName))); fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
extension.getFieldDefinitions().forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName))); fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
private NodePrinter<FieldDefinition> fieldDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { out.printf("%s", comments(node)); String args; if (hasComments(node.getInputValueDefinitions()) && !compactMode) { args = join(node.getInputValueDefinitions(), "\n"); out.printf("%s", node.getName() + wrap("(\n", args, "\n)") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } else { args = join(node.getInputValueDefinitions(), argSep); out.printf("%s", node.getName() + wrap("(", args, ")") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } }; }
private FieldDefAndDirectiveParams buildField(BuildContext buildCtx, TypeDefinition parentType, FieldDefinition fieldDef) { buildCtx.enterNode(fieldDef); GraphQLFieldDefinition.Builder builder = GraphQLFieldDefinition.newFieldDefinition(); builder.definition(fieldDef); builder.name(fieldDef.getName()); builder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription())); builder.deprecate(schemaGeneratorHelper.buildDeprecationReason(fieldDef.getDirectives())); GraphQLDirective[] directives = buildDirectives(fieldDef.getDirectives(), Collections.emptyList(), DirectiveLocation.FIELD_DEFINITION, buildCtx.getDirectiveDefinitions()); builder.withDirectives( directives ); fieldDef.getInputValueDefinitions().forEach(inputValueDefinition -> builder.argument(buildArgument(buildCtx, inputValueDefinition))); GraphQLOutputType fieldType = buildOutputType(buildCtx, fieldDef.getType()); builder.type(fieldType); GraphQLFieldDefinition fieldDefinition = builder.build(); // if they have already wired in a fetcher - then leave it alone FieldCoordinates coordinates = FieldCoordinates.coordinates(parentType.getName(), fieldDefinition.getName()); if (!buildCtx.codeRegistry.hasDataFetcher(coordinates)) { DataFetcherFactory dataFetcherFactory = buildDataFetcherFactory(buildCtx, parentType, fieldDef, fieldType, Arrays.asList(directives)); buildCtx.getCodeRegistry().dataFetcher(coordinates, dataFetcherFactory); } return buildCtx.exitNode(new FieldDefAndDirectiveParams(fieldDefinition, buildCtx.mkBehaviourParams())); }
private void checkField(DiffCtx ctx, TypeDefinition old, FieldDefinition oldField, FieldDefinition newField) { Type oldFieldType = oldField.getType(); Type newFieldType = newField.getType(); DiffCategory category = checkTypeWithNonNullAndList(oldFieldType, newFieldType); if (category != null) { ctx.report(DiffEvent.apiBreakage() .category(category) .typeName(old.getName()) .typeKind(getTypeKind(old)) .fieldName(oldField.getName()) .components(getAstDesc(oldFieldType), getAstDesc(newFieldType)) .reasonMsg("The new API has changed field '%s' from type '%s' to '%s'", mkDotName(old.getName(), oldField.getName()), getAstDesc(oldFieldType), getAstDesc(newFieldType)) .build()); } checkFieldArguments(ctx, old, oldField, oldField.getInputValueDefinitions(), newField.getInputValueDefinitions()); checkDirectives(ctx, old, oldField.getDirectives(), newField.getDirectives()); // // and down we go again recursively via fields // checkType(ctx, oldFieldType, newFieldType); }