use of graphql.language.DirectiveDefinition in project graphql-java by graphql-java.
the class SchemaTypeChecker method checkObjTypeFields.
private void checkObjTypeFields(List<GraphQLError> errors, ObjectTypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions, Map<String, DirectiveDefinition> directiveDefinitionMap) {
// 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 -> fld.getDirectives().forEach(directive -> {
checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(typeDefinition, fld, argumentName));
}));
}
use of graphql.language.DirectiveDefinition in project graphql-java by graphql-java.
the class SchemaTypeChecker method checkDirectiveDefinitions.
private void checkDirectiveDefinitions(TypeDefinitionRegistry typeRegistry, List<GraphQLError> errors) {
List<DirectiveDefinition> directiveDefinitions = new ArrayList<>(typeRegistry.getDirectiveDefinitions().values());
directiveDefinitions.forEach(directiveDefinition -> {
List<InputValueDefinition> arguments = directiveDefinition.getInputValueDefinitions();
checkNamedUniqueness(errors, arguments, InputValueDefinition::getName, (name, arg) -> new NonUniqueNameError(directiveDefinition, arg));
List<Type> inputValueTypes = arguments.stream().map(InputValueDefinition::getType).collect(toList());
inputValueTypes.forEach(checkTypeExists(typeRegistry, errors, "directive definition", directiveDefinition, directiveDefinition.getName()));
directiveDefinition.getDirectiveLocations().forEach(directiveLocation -> {
String locationName = directiveLocation.getName();
try {
Introspection.DirectiveLocation.valueOf(locationName);
} catch (IllegalArgumentException e) {
errors.add(new DirectiveIllegalLocationError(directiveDefinition, locationName));
}
});
});
}
use of graphql.language.DirectiveDefinition 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, Map<String, DirectiveDefinition> directiveDefinitionMap) {
typeRegistry.unionTypeExtensions().forEach((name, extensions) -> {
checkTypeExtensionHasCorrespondingType(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.DirectiveDefinition in project graphql-java by graphql-java.
the class TypeDefinitionRegistry method add.
/**
* Adds a definition to the registry
*
* @param definition the definition to add
*
* @return an optional error
*/
public Optional<GraphQLError> add(SDLDefinition definition) {
// extensions
if (definition instanceof ObjectTypeExtensionDefinition) {
ObjectTypeExtensionDefinition newEntry = (ObjectTypeExtensionDefinition) definition;
return defineExt(objectTypeExtensions, newEntry, ObjectTypeExtensionDefinition::getName);
} else if (definition instanceof InterfaceTypeExtensionDefinition) {
InterfaceTypeExtensionDefinition newEntry = (InterfaceTypeExtensionDefinition) definition;
return defineExt(interfaceTypeExtensions, newEntry, InterfaceTypeExtensionDefinition::getName);
} else if (definition instanceof UnionTypeExtensionDefinition) {
UnionTypeExtensionDefinition newEntry = (UnionTypeExtensionDefinition) definition;
return defineExt(unionTypeExtensions, newEntry, UnionTypeExtensionDefinition::getName);
} else if (definition instanceof EnumTypeExtensionDefinition) {
EnumTypeExtensionDefinition newEntry = (EnumTypeExtensionDefinition) definition;
return defineExt(enumTypeExtensions, newEntry, EnumTypeExtensionDefinition::getName);
} else if (definition instanceof ScalarTypeExtensionDefinition) {
ScalarTypeExtensionDefinition newEntry = (ScalarTypeExtensionDefinition) definition;
return defineExt(scalarTypeExtensions, newEntry, ScalarTypeExtensionDefinition::getName);
} else if (definition instanceof InputObjectTypeExtensionDefinition) {
InputObjectTypeExtensionDefinition newEntry = (InputObjectTypeExtensionDefinition) definition;
return defineExt(inputObjectTypeExtensions, newEntry, InputObjectTypeExtensionDefinition::getName);
} else if (definition instanceof SchemaExtensionDefinition) {
schemaExtensionDefinitions.add((SchemaExtensionDefinition) definition);
schemaParseOrder.addDefinition(definition);
Optional<GraphQLError> error = checkAddOperationDefs();
if (error.isPresent()) {
return error;
}
} else if (definition instanceof ScalarTypeDefinition) {
ScalarTypeDefinition newEntry = (ScalarTypeDefinition) definition;
return define(scalarTypes, scalarTypes, newEntry);
} else if (definition instanceof TypeDefinition) {
TypeDefinition newEntry = (TypeDefinition) definition;
return define(types, types, newEntry);
} else if (definition instanceof DirectiveDefinition) {
DirectiveDefinition newEntry = (DirectiveDefinition) definition;
return define(directiveDefinitions, directiveDefinitions, newEntry);
} else if (definition instanceof SchemaDefinition) {
SchemaDefinition newSchema = (SchemaDefinition) definition;
if (schema != null) {
return Optional.of(new SchemaRedefinitionError(this.schema, newSchema));
} else {
schema = newSchema;
schemaParseOrder.addDefinition(newSchema);
}
Optional<GraphQLError> error = checkAddOperationDefs();
if (error.isPresent()) {
return error;
}
} else {
return Assert.assertShouldNeverHappen();
}
return Optional.empty();
}
Aggregations