Search in sources :

Example 1 with NotAnOutputTypeError

use of graphql.schema.idl.errors.NotAnOutputTypeError 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);
}
Also used : ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) GraphQLOutputType(graphql.schema.GraphQLOutputType) INPUT_OBJECT(graphql.introspection.Introspection.DirectiveLocation.INPUT_OBJECT) OBJECT(graphql.introspection.Introspection.DirectiveLocation.OBJECT) EnumTypeDefinition(graphql.language.EnumTypeDefinition) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) UnionTypeDefinition(graphql.language.UnionTypeDefinition) NotAnOutputTypeError(graphql.schema.idl.errors.NotAnOutputTypeError) EnumTypeDefinition(graphql.language.EnumTypeDefinition) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) TypeDefinition(graphql.language.TypeDefinition) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) UnionTypeDefinition(graphql.language.UnionTypeDefinition) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition)

Aggregations

INPUT_OBJECT (graphql.introspection.Introspection.DirectiveLocation.INPUT_OBJECT)1 OBJECT (graphql.introspection.Introspection.DirectiveLocation.OBJECT)1 EnumTypeDefinition (graphql.language.EnumTypeDefinition)1 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)1 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)1 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)1 OperationTypeDefinition (graphql.language.OperationTypeDefinition)1 ScalarTypeDefinition (graphql.language.ScalarTypeDefinition)1 TypeDefinition (graphql.language.TypeDefinition)1 UnionTypeDefinition (graphql.language.UnionTypeDefinition)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 NotAnOutputTypeError (graphql.schema.idl.errors.NotAnOutputTypeError)1