use of graphql.language.Type in project graphql-java by graphql-java.
the class SchemaTypeExtensionsChecker method checkUnionTypeExtensions.
/*
* Union type extensions have the potential to be invalid if incorrectly defined.
*
* The named type must already be defined and must be a Union type.
* The member types of a Union type extension must all be Object base types; Scalar, Interface and Union types must not be member types of a Union. Similarly, wrapping types must not be member types of a Union.
* All member types of a Union type extension must be unique.
* All member types of a Union type extension must not already be a member of the original Union type.
* Any directives provided must not already apply to the original Union type.
*/
private void checkUnionTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) {
typeRegistry.unionTypeExtensions().forEach((name, extensions) -> {
checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, UnionTypeDefinition.class);
checkTypeExtensionDirectiveRedefinition(errors, typeRegistry, name, extensions, UnionTypeDefinition.class);
extensions.forEach(extension -> {
List<TypeName> memberTypes = extension.getMemberTypes().stream().map(t -> TypeInfo.typeInfo(t).getTypeName()).collect(Collectors.toList());
checkNamedUniqueness(errors, memberTypes, TypeName::getName, (namedMember, memberType) -> new NonUniqueNameError(extension, namedMember));
memberTypes.forEach(memberType -> {
Optional<ObjectTypeDefinition> unionTypeDefinition = typeRegistry.getType(memberType, ObjectTypeDefinition.class);
if (!unionTypeDefinition.isPresent()) {
errors.add(new MissingTypeError("union member", extension, memberType));
}
});
});
});
}
use of graphql.language.Type in project graphql-java by graphql-java.
the class SchemaTypeExtensionsChecker method checkObjectTypeExtensions.
/*
* Object type extensions have the potential to be invalid if incorrectly defined.
*
* The named type must already be defined and must be an Object type.
* The fields of an Object type extension must have unique names; no two fields may share the same name.
* Any fields of an Object type extension must not be already defined on the original Object type.
* Any directives provided must not already apply to the original Object type.
* Any interfaces provided must not be already implemented by the original Object type.
* The resulting extended object type must be a super-set of all interfaces it implements.
*/
private void checkObjectTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) {
typeRegistry.objectTypeExtensions().forEach((name, extensions) -> {
checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, ObjectTypeDefinition.class);
checkTypeExtensionDirectiveRedefinition(errors, typeRegistry, name, extensions, ObjectTypeDefinition.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<ObjectTypeDefinition> baseTypeOpt = typeRegistry.getType(extension.getName(), ObjectTypeDefinition.class);
baseTypeOpt.ifPresent(baseTypeDef -> checkForFieldRedefinition(errors, extension, fieldDefinitions, baseTypeDef.getFieldDefinitions()));
});
});
}
use of graphql.language.Type in project graphql-java by graphql-java.
the class SchemaGenerator method buildObjectTypeInterfaces.
private void buildObjectTypeInterfaces(BuildContext buildCtx, ObjectTypeDefinition typeDefinition, GraphQLObjectType.Builder builder, List<ObjectTypeExtensionDefinition> extensions) {
Map<String, GraphQLInterfaceType> interfaces = new LinkedHashMap<>();
typeDefinition.getImplements().forEach(type -> {
GraphQLInterfaceType newInterfaceType = buildOutputType(buildCtx, type);
interfaces.put(newInterfaceType.getName(), newInterfaceType);
});
extensions.forEach(extension -> extension.getImplements().forEach(type -> {
GraphQLInterfaceType interfaceType = buildOutputType(buildCtx, type);
if (!interfaces.containsKey(interfaceType.getName())) {
interfaces.put(interfaceType.getName(), interfaceType);
}
}));
interfaces.values().forEach(builder::withInterface);
}
use of graphql.language.Type in project graphql-java by graphql-java.
the class SchemaDiff method checkImplements.
private void checkImplements(DiffCtx ctx, ObjectTypeDefinition old, List<Type> oldImplements, List<Type> newImplements) {
Map<String, Type> oldImplementsMap = sortedMap(oldImplements, t -> ((TypeName) t).getName());
Map<String, Type> newImplementsMap = sortedMap(newImplements, t -> ((TypeName) t).getName());
for (Map.Entry<String, Type> entry : oldImplementsMap.entrySet()) {
InterfaceTypeDefinition oldInterface = ctx.getOldTypeDef(entry.getValue(), InterfaceTypeDefinition.class).get();
Optional<InterfaceTypeDefinition> newInterface = ctx.getNewTypeDef(newImplementsMap.get(entry.getKey()), InterfaceTypeDefinition.class);
if (!newInterface.isPresent()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(old.getName()).typeKind(getTypeKind(old)).components(oldInterface.getName()).reasonMsg("The new API is missing the interface named '%s'", oldInterface.getName()).build());
} else {
checkInterfaceType(ctx, oldInterface, newInterface.get());
}
}
}
use of graphql.language.Type in project graphql-java by graphql-java.
the class SchemaDiff method checkField.
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);
}
Aggregations