2

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

1 Answer 1

2

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",
//    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.