首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >[TypeGraphQL]无法确定GraphQL输入类型

[TypeGraphQL]无法确定GraphQL输入类型
EN

Stack Overflow用户
提问于 2021-01-25 02:08:18
回答 1查看 2.1K关注 0票数 2

在以下配置中发生错误。请告诉我错误的原因和解决方法。

错误信息

错误:无法确定“XxxxxInput”类的“zzzzzInputs”的GraphQL输入类型。该值(用作其TS类型或显式类型)是用适当的装饰符修饰的,还是一个适当的输入值?

繁殖环境与方法

  1. 克隆

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

  1. 执行命令

npm ci

npm run start

应用程序/库堆栈

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

源源

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

代码语言:javascript
复制
@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!);
    }
}

我指的是这里的代码。

https://typegraphql.com/docs/types-and-fields.html

Cannot determine GraphQL input type for argument named

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-25 14:32:49

我通过以下修改解决了我的问题。看“★”。

(找到了另一个,也解决了。)

源源

代码语言:javascript
复制
// @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!);
    }
}

相关来源

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

代码语言:javascript
复制
    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);
    }

另一个问题

在我解决了上面的问题后,又发生了一个问题。错误消息如下:

错误:无法确定“ZzzzzInput”类的“zzzzz”的GraphQL输入类型。该值(用作其TS类型或显式类型)是用适当的装饰符修饰的,还是一个适当的输入值?

查看模式-generator.js中的☆。

找不到Enum类型'ZzzzzType‘,因此出现了错误。

因为this.enumTypesInfo不包含“ZzzzzType”。

因为我在SchemaGenerating进程之后执行Enumtype注册。

我不得不修改以下内容。

代码语言:javascript
复制
    // 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",
//    });
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65878098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档