Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
668 views
in Technique[技术] by (71.8m points)

reactjs - [TypeGraphQL]Cannot determine GraphQL input type

An error occurs in the following configuration. Please tell me the cause of the error and how to fix it.

■Error message

Error: Cannot determine GraphQL input type for 'zzzzzInputs' of 'XxxxxInput' class. Is the value, that is used as its TS type or explicit type, decorated with a proper decorator or is it a proper input value?

■Reproduction environment and method

  1. Clone
    git clone https://github.com/isoittech/hellpj-type-graphql

  2. Execute commands
    npm ci
    npm run start

■Application/library stack

  • Node.js/Express
  • sequelize
  • sequelize-typescript
  • type-graphql

■Source

https://github.com/isoittech/hellpj-type-graphql/blob/master/src/main/graphql/ppppp.resolver.ts

@ObjectType()
export class ZzzzzInput {
    @Field((type) => ZzzzzType)
    zzzzz!: ZzzzzType;
    // @Field()
    // zzzzz!: string;
}

@InputType()
export class XxxxxInput {
    @Field((type) => [ZzzzzInput])
    zzzzzInputs!: ZzzzzInput[];
    // @Field((type) => [String])
    // zzzzzInputs!: string[];
}

@Resolver((of) => Yyyyy)
export class XxxxxResolver {
    @Mutation((returns) => Yyyyy)
    async addXxxxx(@Arg("Xxxxx") XxxxxInput: XxxxxInput): Promise<Yyyyy> {
        const serviceOutput: XxxxxServiceOutputDto = {};

        return Promise.resolve(serviceOutput.addedXxxxx!);
    }
}

■I coded it by referring to here.

https://typegraphql.com/docs/types-and-fields.html
Cannot determine GraphQL input type for argument named

question from:https://stackoverflow.com/questions/65878098/typegraphqlcannot-determine-graphql-input-type

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solved my problem by modifying like below. Look at '★'.
(And found another one, solved too.)

■Source

// @ObjectType()   // ★  Before
@InputType()       // ★  After
export class ZzzzzInput {
    @Field((type) => ZzzzzType)
    zzzzz!: ZzzzzType;
    // @Field()
    // zzzzz!: string;
}

@InputType()
export class XxxxxInput {
    @Field((type) => [ZzzzzInput])
    zzzzzInputs!: ZzzzzInput[];
    // @Field((type) => [String])
    // zzzzzInputs!: string[];
}

@Resolver((of) => Yyyyy)
export class XxxxxResolver {
    @Mutation((returns) => Yyyyy)
    async addXxxxx(@Arg("Xxxxx") XxxxxInput: XxxxxInput): Promise<Yyyyy> {
        const serviceOutput: XxxxxServiceOutputDto = {};

        return Promise.resolve(serviceOutput.addedXxxxx!);
    }
}

■Related source

node_modules/type-graphql/dist/schema/schema-generator.js


    static getGraphQLInputType(target, propertyName, type, typeOptions = {}, parameterIndex, argName) {
        let gqlType;
        gqlType = types_1.convertTypeIfScalar(type);
        if (!gqlType) {
            ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
            ★ Finding process below not worked when @ObjectType.
            ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
            const inputType = this.inputTypesInfo.find(it => it.target === type);
            if (inputType) {
                gqlType = inputType.type;
            }
        }
        if (!gqlType) {
            ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆
            ☆ Finding process below not worked when wrong order in src/index.ts.
            ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆
            const enumType = this.enumTypesInfo.find(it => it.enumObj === type);
            if (enumType) {
                gqlType = enumType.type;
            }
        }
        if (!gqlType) {
            throw new errors_1.CannotDetermineGraphQLTypeError("input", target.name, propertyName, parameterIndex, argName);
        }
        const { nullableByDefault } = build_context_1.BuildContext;
        return types_1.wrapWithTypeOptions(target, propertyName, gqlType, typeOptions, nullableByDefault);
    }

■Another problem

After I've solved above problem, another one occured. Error message is below:

Error: Cannot determine GraphQL input type for 'zzzzz' of 'ZzzzzInput' class. Is the value, that is used as its TS type or explicit type, decorated with a proper decorator or is it a proper input value?

Look at ☆ in schema-generator.js.
Enum type 'ZzzzzType' couldn't be found, so error occured.
Because this.enumTypesInfo doesn't contain 'ZzzzzType'.
Because I executed registering Enumtype after SchemaGenerating process.
I had to modify below.

    // enable Enum
    registerEnumType(ZzzzzType, {
        name: "ZzzzzType",
    });
    const schema = await buildSchema({
        resolvers: [__dirname + "/graphql/*.resolver.ts"],
        emitSchemaFile: true,
        validate: false,
    });
//    // enable Enum
//    registerEnumType(ZzzzzType, {
//        name: "ZzzzzType",
//    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...