@Override public TraversalControl visitInputValueDefinition(InputValueDefinition node, TraverserContext<Node> context) { InputValueDefinition changedNode = node.transform(builder -> { List<Directive> directives = sort(node.getDirectives(), comparing(Directive::getName)); builder.directives(directives); }); return changeNode(context, changedNode); }
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 checkInputValues(List<GraphQLError> errors, InputObjectTypeDefinition inputType, List<InputValueDefinition> inputValueDefinitions) { // field unique ness checkNamedUniqueness(errors, inputValueDefinitions, InputValueDefinition::getName, (name, inputValueDefinition) -> { // not sure why this is needed but inlining breaks it @SuppressWarnings("UnnecessaryLocalVariable") InputObjectTypeDefinition as = inputType; return new NonUniqueNameError(as, inputValueDefinition); }); // directive checks inputValueDefinitions.forEach(inputValueDef -> checkNamedUniqueness(errors, inputValueDef.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(inputType, inputValueDef, directiveName))); inputValueDefinitions.forEach(inputValueDef -> inputValueDef.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(inputType, inputValueDef)); checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(inputType, inputValueDef, argumentName)); })); }
private NodePrinter<InputValueDefinition> inputValueDefinition() { String nameTypeSep = compactMode ? ":" : ": "; String defaultValueEquals = compactMode ? "=" : "= "; return (out, node) -> { Value defaultValue = node.getDefaultValue(); out.printf("%s", comments(node)); out.printf("%s", spaced( node.getName() + nameTypeSep + type(node.getType()), wrap(defaultValueEquals, defaultValue, ""), directives(node.getDirectives()) ) ); }; }
private Builder(InputValueDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.type = existing.getType(); this.defaultValue = existing.getDefaultValue(); this.description = existing.getDescription(); this.directives = existing.getDirectives(); }
inputValueDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName))); inputValueDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
private void checkDirectives(DirectiveLocation expectedLocation, List<GraphQLError> errors, TypeDefinition<?> typeDef) { checkDirectives(expectedLocation, errors, typeRegistry, typeDef, typeDef.getName(), typeDef.getDirectives()); if (typeDef instanceof ObjectTypeDefinition) { List<FieldDefinition> fieldDefinitions = ((ObjectTypeDefinition) typeDef).getFieldDefinitions(); checkFieldsDirectives(errors, typeRegistry, fieldDefinitions); } if (typeDef instanceof InterfaceTypeDefinition) { List<FieldDefinition> fieldDefinitions = ((InterfaceTypeDefinition) typeDef).getFieldDefinitions(); checkFieldsDirectives(errors, typeRegistry, fieldDefinitions); } if (typeDef instanceof EnumTypeDefinition) { List<EnumValueDefinition> enumValueDefinitions = ((EnumTypeDefinition) typeDef).getEnumValueDefinitions(); enumValueDefinitions.forEach(definition -> checkDirectives(ENUM_VALUE, errors, typeRegistry, definition, definition.getName(), definition.getDirectives())); } if (typeDef instanceof InputObjectTypeDefinition) { List<InputValueDefinition> inputValueDefinitions = ((InputObjectTypeDefinition) typeDef).getInputValueDefinitions(); inputValueDefinitions.forEach(definition -> checkDirectives(INPUT_FIELD_DEFINITION, errors, typeRegistry, definition, definition.getName(), definition.getDirectives())); } }
private GraphQLInputObjectField buildInputField(BuildContext buildCtx, InputValueDefinition fieldDef) { buildCtx.enterNode(fieldDef); GraphQLInputObjectField.Builder fieldBuilder = GraphQLInputObjectField.newInputObjectField(); fieldBuilder.definition(fieldDef); fieldBuilder.name(fieldDef.getName()); fieldBuilder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription())); // currently the spec doesnt allow deprecations on InputValueDefinitions but it should! //fieldBuilder.deprecate(buildDeprecationReason(fieldDef.getDirectives())); GraphQLInputType inputType = buildInputType(buildCtx, fieldDef.getType()); fieldBuilder.type(inputType); Value defaultValue = fieldDef.getDefaultValue(); if (defaultValue != null) { fieldBuilder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType)); } fieldBuilder.withDirectives( buildDirectives(fieldDef.getDirectives(), emptyList(), INPUT_FIELD_DEFINITION, buildCtx.getDirectiveDefinitions()) ); GraphQLInputObjectField inputObjectField = fieldBuilder.build(); inputObjectField = directiveBehaviour.onInputObjectField(inputObjectField, buildCtx.mkBehaviourParams()); return buildCtx.exitNode(inputObjectField); }
private GraphQLArgument buildArgument(BuildContext buildCtx, InputValueDefinition valueDefinition) { buildCtx.enterNode(valueDefinition); GraphQLArgument.Builder builder = GraphQLArgument.newArgument(); builder.definition(valueDefinition); builder.name(valueDefinition.getName()); builder.description(schemaGeneratorHelper.buildDescription(valueDefinition, valueDefinition.getDescription())); GraphQLInputType inputType = buildInputType(buildCtx, valueDefinition.getType()); builder.type(inputType); Value defaultValue = valueDefinition.getDefaultValue(); if (defaultValue != null) { builder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType)); } builder.withDirectives( buildDirectives(valueDefinition.getDirectives(), emptyList(), ARGUMENT_DEFINITION, buildCtx.getDirectiveDefinitions()) ); GraphQLArgument argument = builder.build(); argument = directiveBehaviour.onArgument(argument, buildCtx.mkBehaviourParams()); return buildCtx.exitNode(argument); }
checkDirectives(ctx, oldDef, oldArg.getDirectives(), newArg.getDirectives());
@Override public TraversalControl visitInputValueDefinition(InputValueDefinition node, TraverserContext<Node> context) { InputValueDefinition changedNode = node.transform(builder -> { List<Directive> directives = sort(node.getDirectives(), comparing(Directive::getName)); builder.directives(directives); }); return changeNode(context, changedNode); }
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 checkInputValues(List<GraphQLError> errors, InputObjectTypeDefinition inputType, List<InputValueDefinition> inputValueDefinitions) { // field unique ness checkNamedUniqueness(errors, inputValueDefinitions, InputValueDefinition::getName, (name, inputValueDefinition) -> { // not sure why this is needed but inlining breaks it @SuppressWarnings("UnnecessaryLocalVariable") InputObjectTypeDefinition as = inputType; return new NonUniqueNameError(as, inputValueDefinition); }); // directive checks inputValueDefinitions.forEach(inputValueDef -> checkNamedUniqueness(errors, inputValueDef.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(inputType, inputValueDef, directiveName))); inputValueDefinitions.forEach(inputValueDef -> inputValueDef.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(inputType, inputValueDef)); checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(inputType, inputValueDef, argumentName)); })); }
private NodePrinter<InputValueDefinition> inputValueDefinition() { String nameTypeSep = compactMode ? ":" : ": "; String defaultValueEquals = compactMode ? "=" : "= "; return (out, node) -> { Value defaultValue = node.getDefaultValue(); out.printf("%s", comments(node)); out.printf("%s", spaced( node.getName() + nameTypeSep + type(node.getType()), wrap(defaultValueEquals, defaultValue, ""), directives(node.getDirectives()) ) ); }; }
private Builder(InputValueDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.type = existing.getType(); this.defaultValue = existing.getDefaultValue(); this.description = existing.getDescription(); this.directives = existing.getDirectives(); }
inputValueDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName))); inputValueDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> { checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
private void checkDirectives(DirectiveLocation expectedLocation, List<GraphQLError> errors, TypeDefinition<?> typeDef) { checkDirectives(expectedLocation, errors, typeRegistry, typeDef, typeDef.getName(), typeDef.getDirectives()); if (typeDef instanceof ObjectTypeDefinition) { List<FieldDefinition> fieldDefinitions = ((ObjectTypeDefinition) typeDef).getFieldDefinitions(); checkFieldsDirectives(errors, typeRegistry, fieldDefinitions); } if (typeDef instanceof InterfaceTypeDefinition) { List<FieldDefinition> fieldDefinitions = ((InterfaceTypeDefinition) typeDef).getFieldDefinitions(); checkFieldsDirectives(errors, typeRegistry, fieldDefinitions); } if (typeDef instanceof EnumTypeDefinition) { List<EnumValueDefinition> enumValueDefinitions = ((EnumTypeDefinition) typeDef).getEnumValueDefinitions(); enumValueDefinitions.forEach(definition -> checkDirectives(ENUM_VALUE, errors, typeRegistry, definition, definition.getName(), definition.getDirectives())); } if (typeDef instanceof InputObjectTypeDefinition) { List<InputValueDefinition> inputValueDefinitions = ((InputObjectTypeDefinition) typeDef).getInputValueDefinitions(); inputValueDefinitions.forEach(definition -> checkDirectives(INPUT_FIELD_DEFINITION, errors, typeRegistry, definition, definition.getName(), definition.getDirectives())); } }
private GraphQLArgument buildArgument(BuildContext buildCtx, InputValueDefinition valueDefinition) { buildCtx.enterNode(valueDefinition); GraphQLArgument.Builder builder = GraphQLArgument.newArgument(); builder.definition(valueDefinition); builder.name(valueDefinition.getName()); builder.description(schemaGeneratorHelper.buildDescription(valueDefinition, valueDefinition.getDescription())); GraphQLInputType inputType = buildInputType(buildCtx, valueDefinition.getType()); builder.type(inputType); Value defaultValue = valueDefinition.getDefaultValue(); if (defaultValue != null) { builder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType)); } builder.withDirectives( buildDirectives(valueDefinition.getDirectives(), emptyList(), ARGUMENT_DEFINITION, buildCtx.getDirectiveDefinitions()) ); GraphQLArgument argument = builder.build(); argument = directiveBehaviour.onArgument(argument, buildCtx.mkBehaviourParams()); return buildCtx.exitNode(argument); }
private GraphQLInputObjectField buildInputField(BuildContext buildCtx, InputValueDefinition fieldDef) { buildCtx.enterNode(fieldDef); GraphQLInputObjectField.Builder fieldBuilder = GraphQLInputObjectField.newInputObjectField(); fieldBuilder.definition(fieldDef); fieldBuilder.name(fieldDef.getName()); fieldBuilder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription())); // currently the spec doesnt allow deprecations on InputValueDefinitions but it should! //fieldBuilder.deprecate(buildDeprecationReason(fieldDef.getDirectives())); GraphQLInputType inputType = buildInputType(buildCtx, fieldDef.getType()); fieldBuilder.type(inputType); Value defaultValue = fieldDef.getDefaultValue(); if (defaultValue != null) { fieldBuilder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType)); } fieldBuilder.withDirectives( buildDirectives(fieldDef.getDirectives(), emptyList(), INPUT_FIELD_DEFINITION, buildCtx.getDirectiveDefinitions()) ); GraphQLInputObjectField inputObjectField = fieldBuilder.build(); inputObjectField = directiveBehaviour.onInputObjectField(inputObjectField, buildCtx.mkBehaviourParams()); return buildCtx.exitNode(inputObjectField); }
checkDirectives(ctx, oldDef, oldArg.getDirectives(), newArg.getDirectives());