use of graphql.language.FieldDefinition in project graphql-java by graphql-java.
the class SchemaTypeChecker method checkObjTypeFields.
private void checkObjTypeFields(List<GraphQLError> errors, ObjectTypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions) {
// 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 -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(typeDefinition, fld, directiveName)));
fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> {
checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(typeDefinition, fld));
checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(typeDefinition, fld, argumentName));
}));
}
use of graphql.language.FieldDefinition 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.FieldDefinition in project graphql-java by graphql-java.
the class SchemaTypeExtensionsChecker method checkForFieldRedefinition.
private void checkForFieldRedefinition(List<GraphQLError> errors, TypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions, List<FieldDefinition> referenceFieldDefinitions) {
Map<String, FieldDefinition> referenceMap = FpKit.getByName(referenceFieldDefinitions, FieldDefinition::getName, mergeFirst());
fieldDefinitions.forEach(fld -> {
FieldDefinition 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.FieldDefinition 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.FieldDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitTypeName.
// MARKER END: Here GraphqlOperation.g4 specific methods end
@Override
public Void visitTypeName(GraphqlParser.TypeNameContext ctx) {
TypeName typeName = new TypeName(ctx.name().getText());
newNode(typeName, ctx);
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.value instanceof ListType) {
((ListType) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof NonNullType) {
((NonNullType) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof VariableDefinition) {
((VariableDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof FieldDefinition) {
((FieldDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof InputValueDefinition) {
((InputValueDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
((ObjectTypeDefinition) contextEntry.value).getImplements().add(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.UnionTypeDefinition) {
((UnionTypeDefinition) contextEntry.value).getMemberTypes().add(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.OperationTypeDefinition) {
((OperationTypeDefinition) contextEntry.value).setType(typeName);
break;
}
}
return super.visitTypeName(ctx);
}
Aggregations