public TypeExtensionFieldRedefinitionError(TypeDefinition typeDefinition, InputValueDefinition fieldDefinition) { super(typeDefinition, formatMessage(typeDefinition, fieldDefinition.getName(), fieldDefinition)); }
public NonUniqueNameError(InputObjectTypeDefinition typeDefinition, InputValueDefinition inputValueDefinition) { super(typeDefinition, format("The type '%s' %s has declared an input field with a non unique name '%s'", typeDefinition.getName(), lineCol(typeDefinition), inputValueDefinition.getName())); }
public NonUniqueNameError(DirectiveDefinition typeDefinition, InputValueDefinition inputValueDefinition) { super(typeDefinition, format("The directive definition '%s' %s has declared an argument with a non unique name '%s'", typeDefinition.getName(), lineCol(typeDefinition), inputValueDefinition.getName())); }
public InvalidDeprecationDirectiveError(TypeDefinition typeDefinition, InputValueDefinition inputValueDefinition) { super(typeDefinition, format("The type '%s' with input value '%s' %s has declared an invalid deprecation directive. Its must be @deprecated(reason : \"xyz\")", typeDefinition.getName(), inputValueDefinition.getName(), lineCol(typeDefinition))); }
public NonUniqueDirectiveError(TypeDefinition typeDefinition, InputValueDefinition inputValueDefinition, String directiveName) { super(typeDefinition, format("The type '%s' with input value '%s' %s has declared a directive with a non unique name '%s'", typeDefinition.getName(), inputValueDefinition.getName(), lineCol(typeDefinition), directiveName)); }
public NonUniqueNameError(TypeDefinition typeDefinition, InputValueDefinition inputValueDefinition) { super(typeDefinition, format("The type '%s' %s has declared an argument with a non unique name '%s'", typeDefinition.getName(), lineCol(typeDefinition), inputValueDefinition.getName())); }
public NonUniqueArgumentError(TypeDefinition typeDefinition, InputValueDefinition inputValueDefinition, String argumentName) { super(typeDefinition, format("The type '%s' with input value '%s' %s has declared an argument with a non unique name '%s'", typeDefinition.getName(), inputValueDefinition.getName(), lineCol(typeDefinition), argumentName)); }
private void checkForInputValueRedefinition(List<GraphQLError> errors, InputObjectTypeExtensionDefinition typeDefinition, List<InputValueDefinition> inputValueDefinitions, List<InputValueDefinition> referenceInputValues) { Map<String, InputValueDefinition> referenceMap = FpKit.getByName(referenceInputValues, InputValueDefinition::getName, mergeFirst()); inputValueDefinitions.forEach(fld -> { InputValueDefinition reference = referenceMap.get(fld.getName()); if (referenceMap.containsKey(fld.getName())) { // ok they have the same field but is it the same type if (!isSameType(fld.getType(), reference.getType())) { errors.add(new TypeExtensionFieldRedefinitionError(typeDefinition, fld)); } } }); }
ObjectField objectField = nameToFieldsMap.get(allowedValueDef.getName()); checkArgInputObjectValueFieldMatchesAllowedDefinition(errors, objectField, allowedValueDef); });
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 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(); }
private void checkArgInputObjectValueFieldMatchesAllowedDefinition(List<GraphQLError> errors, ObjectField objectField, InputValueDefinition allowedValueDef) { if (objectField != null) { checkArgValueMatchesAllowedType(errors, objectField.getValue(), allowedValueDef.getType()); return; } // check if field definition is required and has no default value if (allowedValueDef.getType() instanceof NonNullType && allowedValueDef.getDefaultValue() == null) { addValidationError(errors, MISSING_REQUIRED_FIELD_MESSAGE, allowedValueDef.getName()); } // other cases are // - field definition is marked as non-null but has a default value, so the default value can be used // - field definition is nullable hence null can be used }
private GraphQLArgument buildDirectiveArgumentFromDefinition(InputValueDefinition arg, Function<Type, GraphQLInputType> inputTypeFactory) { GraphQLArgument.Builder builder = GraphQLArgument.newArgument() .name(arg.getName()) .definition(arg); GraphQLInputType inputType = inputTypeFactory.apply(arg.getType()); builder.type(inputType); builder.value(buildValue(arg.getDefaultValue(), inputType)); builder.defaultValue(buildValue(arg.getDefaultValue(), inputType)); return builder.build(); }
.typeName(old.getName()) .typeKind(getTypeKind(old)) .fieldName(oldField.getName()) .reasonMsg("\tExamining input field '%s' ...", mkDotName(old.getName(), oldField.getName())) .build()); .typeName(old.getName()) .typeKind(getTypeKind(old)) .fieldName(oldField.getName()) .reasonMsg("The new API is missing an input field '%s'", mkDotName(old.getName(), oldField.getName())) .build()); } else { .typeName(old.getName()) .typeKind(getTypeKind(old)) .fieldName(oldField.getName()) .components(getAstDesc(oldField.getType()), getAstDesc(newField.get().getType())) .reasonMsg("The new API has changed input field '%s' from type '%s' to '%s'", oldField.getName(), getAstDesc(oldField.getType()), getAstDesc(newField.get().getType())) .build()); .typeName(old.getName()) .typeKind(getTypeKind(old)) .fieldName(newField.getName()) .reasonMsg("The new API has made the new input field '%s' non null and hence more strict for old consumers", newField.getName()) .build());
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())); } }
Optional<InputValueDefinition> oldArg = Optional.ofNullable(oldArgsMap.get(newArg.getName())); .typeKind(getTypeKind(oldDef)) .fieldName(oldField.getName()) .components(newArg.getName()) .reasonMsg("The new API has made the new argument '%s' on field '%s' non null and hence more strict for old consumers", newArg.getName(), mkDotName(oldDef.getName(), oldField.getName())) .build());
.fieldName(oldField.getName()) .components(getAstDesc(oldArgType), getAstDesc(newArgType)) .reasonMsg("The new API has changed field '%s' argument '%s' from type '%s' to '%s'", mkDotName(oldDef.getName(), oldField.getName()), oldArg.getName(), getAstDesc(oldArgType), getAstDesc(newArgType)) .build()); } else { .typeKind(getTypeKind(oldDef)) .fieldName(oldField.getName()) .components(oldArg.getName()) .reasonMsg("The new API has changed default value types on argument named '%s' on field '%s' of type '%s", oldArg.getName(), mkDotName(oldDef.getName(), oldField.getName()), oldDef.getName()) .build()); .typeKind(getTypeKind(oldDef)) .fieldName(oldField.getName()) .components(oldArg.getName()) .reasonMsg("The new API has changed default value on argument named '%s' on field '%s' of type '%s", oldArg.getName(), mkDotName(oldDef.getName(), oldField.getName()), oldDef.getName()) .build());
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); }