Search in sources :

Example 1 with NotAnInputTypeError

use of graphql.schema.idl.errors.NotAnInputTypeError in project graphql-java by graphql-java.

the class SchemaGenerator method buildInputType.

private GraphQLInputType buildInputType(BuildContext buildCtx, Type rawType) {
    TypeDefinition typeDefinition = buildCtx.getTypeDefinition(rawType);
    TypeInfo typeInfo = TypeInfo.typeInfo(rawType);
    GraphQLInputType inputType = buildCtx.hasInputType(typeDefinition);
    if (inputType != null) {
        return typeInfo.decorate(inputType);
    }
    if (buildCtx.stackContains(typeInfo)) {
        // we have circled around so put in a type reference and fix it later
        return typeInfo.decorate(typeRef(typeInfo.getName()));
    }
    buildCtx.push(typeInfo);
    if (typeDefinition instanceof InputObjectTypeDefinition) {
        inputType = buildInputObjectType(buildCtx, (InputObjectTypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof EnumTypeDefinition) {
        inputType = buildEnumType(buildCtx, (EnumTypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof ScalarTypeDefinition) {
        inputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
    } else {
        // typeDefinition is not a valid InputType
        throw new NotAnInputTypeError(typeDefinition);
    }
    buildCtx.put(inputType);
    buildCtx.pop();
    return typeInfo.decorate(inputType);
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) NotAnInputTypeError(graphql.schema.idl.errors.NotAnInputTypeError) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) 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

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 GraphQLInputType (graphql.schema.GraphQLInputType)1 NotAnInputTypeError (graphql.schema.idl.errors.NotAnInputTypeError)1