use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class SchemaTypeChecker method checkInputValues.
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));
}));
}
use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class SchemaTypeExtensionsChecker method checkForInputValueRedefinition.
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));
}
}
});
}
use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class SchemaTypeExtensionsChecker method checkInterfaceTypeExtensions.
/*
* Interface type extensions have the potential to be invalid if incorrectly defined.
*
* The named type must already be defined and must be an Interface type.
* The fields of an Interface type extension must have unique names; no two fields may share the same name.
* Any fields of an Interface type extension must not be already defined on the original Interface type.
* Any Object type which implemented the original Interface type must also be a super-set of the fields of the Interface type extension (which may be due to Object type extension).
* Any directives provided must not already apply to the original Interface type.
*/
private void checkInterfaceTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) {
typeRegistry.interfaceTypeExtensions().forEach((name, extensions) -> {
checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, InterfaceTypeDefinition.class);
checkTypeExtensionDirectiveRedefinition(errors, typeRegistry, name, extensions, InterfaceTypeDefinition.class);
extensions.forEach(extension -> {
List<FieldDefinition> fieldDefinitions = extension.getFieldDefinitions();
// field unique ness
checkNamedUniqueness(errors, extension.getFieldDefinitions(), FieldDefinition::getName, (namedField, fieldDef) -> new NonUniqueNameError(extension, fieldDef));
// field arg unique ness
extension.getFieldDefinitions().forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (namedField, inputValueDefinition) -> new NonUniqueArgumentError(extension, fld, name)));
// directive checks
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));
checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(extension, fld, argumentName));
}));
//
// fields must be unique within a type extension
forEachBut(extension, extensions, otherTypeExt -> checkForFieldRedefinition(errors, otherTypeExt, otherTypeExt.getFieldDefinitions(), fieldDefinitions));
//
// then check for field re-defs from the base type
Optional<InterfaceTypeDefinition> baseTypeOpt = typeRegistry.getType(extension.getName(), InterfaceTypeDefinition.class);
baseTypeOpt.ifPresent(baseTypeDef -> checkForFieldRedefinition(errors, extension, fieldDefinitions, baseTypeDef.getFieldDefinitions()));
});
});
}
use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class SchemaDiff method checkFieldArguments.
private void checkFieldArguments(DiffCtx ctx, TypeDefinition oldDef, FieldDefinition oldField, List<InputValueDefinition> oldInputValueDefinitions, List<InputValueDefinition> newInputValueDefinitions) {
Map<String, InputValueDefinition> oldArgsMap = sortedMap(oldInputValueDefinitions, InputValueDefinition::getName);
Map<String, InputValueDefinition> newArgMap = sortedMap(newInputValueDefinitions, InputValueDefinition::getName);
if (oldArgsMap.size() > newArgMap.size()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(oldField.getName()).reasonMsg("The new API has less arguments on field '%s' of type '%s' than the old API", mkDotName(oldDef.getName(), oldField.getName()), oldDef.getName()).build());
return;
}
for (Map.Entry<String, InputValueDefinition> entry : oldArgsMap.entrySet()) {
String argName = entry.getKey();
ctx.report(DiffEvent.apiInfo().typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(oldField.getName()).reasonMsg("\tExamining field argument '%s' ...", mkDotName(oldDef.getName(), oldField.getName(), argName)).build());
InputValueDefinition newArg = newArgMap.get(argName);
if (newArg == null) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(oldField.getName()).components(argName).reasonMsg("The new API is missing the field argument '%s'", mkDotName(oldDef.getName(), oldField.getName(), argName)).build());
} else {
checkFieldArg(ctx, oldDef, oldField, entry.getValue(), newArg);
}
}
// check new fields are not mandatory
for (Map.Entry<String, InputValueDefinition> entry : newArgMap.entrySet()) {
InputValueDefinition newArg = entry.getValue();
Optional<InputValueDefinition> oldArg = Optional.ofNullable(oldArgsMap.get(newArg.getName()));
if (!oldArg.isPresent()) {
// new args MUST not be mandatory
if (typeInfo(newArg.getType()).isNonNull()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.STRICTER).typeName(oldDef.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());
}
}
}
}
use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class SchemaTypeChecker method checkArgumentConsistency.
private void checkArgumentConsistency(String typeOfType, ObjectTypeDefinition objectTypeDef, InterfaceTypeDefinition interfaceTypeDef, FieldDefinition objectFieldDef, FieldDefinition interfaceFieldDef, List<GraphQLError> errors) {
List<InputValueDefinition> objectArgs = objectFieldDef.getInputValueDefinitions();
List<InputValueDefinition> interfaceArgs = interfaceFieldDef.getInputValueDefinitions();
for (int i = 0; i < interfaceArgs.size(); i++) {
InputValueDefinition interfaceArg = interfaceArgs.get(i);
InputValueDefinition objectArg = objectArgs.get(i);
String interfaceArgStr = AstPrinter.printAst(interfaceArg);
String objectArgStr = AstPrinter.printAst(objectArg);
if (!interfaceArgStr.equals(objectArgStr)) {
errors.add(new InterfaceFieldArgumentRedefinitionError(typeOfType, objectTypeDef, interfaceTypeDef, objectFieldDef, objectArgStr, interfaceArgStr));
}
}
}
Aggregations