use of graphql.language.ObjectTypeDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitObjectTypeDefinition.
@Override
public Void visitObjectTypeDefinition(GraphqlParser.ObjectTypeDefinitionContext ctx) {
ObjectTypeDefinition def = new ObjectTypeDefinition(ctx.name().getText());
newNode(def, ctx);
def.setDescription(newDescription(ctx.description()));
result.getDefinitions().add(def);
addContextProperty(ContextProperty.ObjectTypeDefinition, def);
super.visitChildren(ctx);
popContext();
return null;
}
use of graphql.language.ObjectTypeDefinition 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.ObjectTypeDefinition in project graphql-java by graphql-java.
the class TypeDefinitionRegistry method isPossibleType.
/**
* Returns true of the abstract type is in implemented by the object type
*
* @param abstractType the abstract type to check (interface or union)
* @param possibleObjectType the object type to check
*
* @return true if the object type implements the abstract type
*/
@SuppressWarnings("ConstantConditions")
public boolean isPossibleType(Type abstractType, Type possibleObjectType) {
if (!isInterfaceOrUnion(abstractType)) {
return false;
}
if (!isObjectType(possibleObjectType)) {
return false;
}
ObjectTypeDefinition targetObjectTypeDef = getType(possibleObjectType, ObjectTypeDefinition.class).get();
TypeDefinition abstractTypeDef = getType(abstractType).get();
if (abstractTypeDef instanceof UnionTypeDefinition) {
List<Type> memberTypes = ((UnionTypeDefinition) abstractTypeDef).getMemberTypes();
for (Type memberType : memberTypes) {
Optional<ObjectTypeDefinition> checkType = getType(memberType, ObjectTypeDefinition.class);
if (checkType.isPresent()) {
if (checkType.get().getName().equals(targetObjectTypeDef.getName())) {
return true;
}
}
}
return false;
} else {
InterfaceTypeDefinition iFace = (InterfaceTypeDefinition) abstractTypeDef;
List<ObjectTypeDefinition> objectTypeDefinitions = getImplementationsOf(iFace);
return objectTypeDefinitions.stream().anyMatch(od -> od.getName().equals(targetObjectTypeDef.getName()));
}
}
use of graphql.language.ObjectTypeDefinition in project graphql-java by graphql-java.
the class SchemaGenerator method buildOutputType.
/**
* This is the main recursive spot that builds out the various forms of Output types
*
* @param buildCtx the context we need to work out what we are doing
* @param rawType the type to be built
*
* @return an output type
*/
@SuppressWarnings("unchecked")
private <T extends GraphQLOutputType> T buildOutputType(BuildContext buildCtx, Type rawType) {
TypeDefinition typeDefinition = buildCtx.getTypeDefinition(rawType);
TypeInfo typeInfo = TypeInfo.typeInfo(rawType);
GraphQLOutputType outputType = buildCtx.hasOutputType(typeDefinition);
if (outputType != null) {
return typeInfo.decorate(outputType);
}
if (buildCtx.stackContains(typeInfo)) {
// otherwise we will go into an infinite loop
return typeInfo.decorate(typeRef(typeInfo.getName()));
}
buildCtx.push(typeInfo);
if (typeDefinition instanceof ObjectTypeDefinition) {
outputType = buildObjectType(buildCtx, (ObjectTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof InterfaceTypeDefinition) {
outputType = buildInterfaceType(buildCtx, (InterfaceTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof UnionTypeDefinition) {
outputType = buildUnionType(buildCtx, (UnionTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof EnumTypeDefinition) {
outputType = buildEnumType(buildCtx, (EnumTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof ScalarTypeDefinition) {
outputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
} else {
// typeDefinition is not a valid output type
throw new NotAnOutputTypeError(typeDefinition);
}
buildCtx.put(outputType);
buildCtx.pop();
return (T) typeInfo.decorate(outputType);
}
use of graphql.language.ObjectTypeDefinition in project graphql-java by graphql-java.
the class SchemaGenerator method buildObjectType.
private GraphQLObjectType buildObjectType(BuildContext buildCtx, ObjectTypeDefinition typeDefinition) {
GraphQLObjectType.Builder builder = GraphQLObjectType.newObject();
builder.definition(typeDefinition);
builder.name(typeDefinition.getName());
builder.description(schemaGeneratorHelper.buildDescription(typeDefinition, typeDefinition.getDescription()));
List<ObjectTypeExtensionDefinition> extensions = objectTypeExtensions(typeDefinition, buildCtx);
builder.withDirectives(buildDirectives(typeDefinition.getDirectives(), directivesOf(extensions), OBJECT));
typeDefinition.getFieldDefinitions().forEach(fieldDef -> {
GraphQLFieldDefinition newFieldDefinition = buildField(buildCtx, typeDefinition, fieldDef);
builder.field(newFieldDefinition);
});
extensions.forEach(extension -> extension.getFieldDefinitions().forEach(fieldDef -> {
GraphQLFieldDefinition newFieldDefinition = buildField(buildCtx, typeDefinition, fieldDef);
if (!builder.hasField(newFieldDefinition.getName())) {
builder.field(newFieldDefinition);
}
}));
buildObjectTypeInterfaces(buildCtx, typeDefinition, builder, extensions);
return builder.build();
}
Aggregations