【发布时间】:2020-01-04 03:49:26
【问题描述】:
我是 GraphQL 的新手,正在尝试实现一个 args 类以用作自定义输入类型。
这是我的课的一个例子:
@ArgsType()
export class CreateVariableArgs {
... other properties
@Field(type => String, { nullable: true })
customClass?: customClassInputType[];
}
这是我的输入类型:
@ArgsType()
export class customClassInputType {
@Field(type => String)
name: string;
@Field(type => Boolean)
isDefault: boolean;
... other properties
}
我想要做的是从 React Typescript UI 传递我的自定义实体数组。我的查询是对我的 GraphQL 服务器的突变请求。我想在解析器中做一些工作,并最终将数据保存在 PostGres 数据库中,并将数据返回或向 UI 抛出错误。
目前我的 graphQL 服务器不知道自定义输入类型是什么。 GraphQL 必须有一种方法可以处理的不仅仅是原始标量类型,但我一直无法找到任何文档,并且已经在这个问题上折腾了一个星期,但没有成功。非常感谢任何帮助。
这是我在调试控制台中遇到的错误。
{"message":"Cannot determine GraphQL input type for customClass","level":"error"}
{"message":"Error: Cannot determine GraphQL input type for customClass\n at Function.getGraphQLInputType (node_modules/type-graphql/dist/schema/schema-generator.js:415:19)\n at argumentType.fields.forEach.field (node_modules/type-graphql/dist/schema/schema-generator.js:361:28)\n at Array.forEach (<anonymous>)\n at Function.mapArgFields (node_modules/type-graphql/dist/schema/schema-generator.js:357:29)\n at params.reduce (node_modules/type-graphql/dist/schema/schema-generator.js:350:22)\n at Array.reduce (<anonymous>)\n at Function.generateHandlerArgs (node_modules/type-graphql/dist/schema/schema-generator.js:332:23)\n at handlers.reduce (node_modules/type-graphql/dist/schema/schema-generator.js:285:28)\n at Array.reduce (<anonymous>)\n at Function.generateHandlerFields (node_modules/type-graphql/dist/schema/schema-generator.js:278:25)","level":"error"}
是否可以使用自定义类型?或者我是否仅限于对我的自定义类型数组进行字符串化并以这种形式使用它们?
【问题讨论】:
标签: reactjs typescript graphql typegraphql