[TypeGraphQL]无法确定 GraphQL 输入类型
[TypeGraphQL]Cannot determine GraphQL input type
以下配置出现错误。请告诉我错误的原因和解决方法。
■错误信息
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?
■复制环境及方法
克隆
git clone https://github.com/isoittech/hellpj-type-graphql
执行命令
npm ci
npm run start
■Application/library堆栈
- 节点.js/Express
- 续集
- sequelize-typescript
- type-graphql
■来源
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!);
}
}
■我参考这里编码的
我通过如下修改解决了我的问题。看'★'.
(又找到了一个,也解决了。)
■来源
// @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
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);
}
■另一个问题
在我解决了上面的问题后,又出现了一个问题。错误信息如下:
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?
看schema中的☆-generator.js.
找不到枚举类型 'ZzzzzType',因此发生错误。
因为 this.enumTypesInfo
不包含 'ZzzzzType'.
因为我在SchemaGenerating过程之后执行了注册Enumtype。
我不得不在下面进行修改。
// 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",
// });
以下配置出现错误。请告诉我错误的原因和解决方法。
■错误信息
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?
■复制环境及方法
克隆
git clone https://github.com/isoittech/hellpj-type-graphql
执行命令
npm ci
npm run start
■Application/library堆栈
- 节点.js/Express
- 续集
- sequelize-typescript
- type-graphql
■来源
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!);
}
}
■我参考这里编码的
我通过如下修改解决了我的问题。看'★'.
(又找到了一个,也解决了。)
■来源
// @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
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);
}
■另一个问题
在我解决了上面的问题后,又出现了一个问题。错误信息如下:
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?
看schema中的☆-generator.js.
找不到枚举类型 'ZzzzzType',因此发生错误。
因为 this.enumTypesInfo
不包含 'ZzzzzType'.
因为我在SchemaGenerating过程之后执行了注册Enumtype。
我不得不在下面进行修改。
// 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",
// });