在以下配置中发生错误。请告诉我错误的原因和解决方法。
错误信息
错误:无法确定“XxxxxInput”类的“zzzzzInputs”的GraphQL输入类型。该值(用作其TS类型或显式类型)是用适当的装饰符修饰的,还是一个适当的输入值?
繁殖环境与方法
git clone https://github.com/isoittech/hellpj-type-graphql
npm ci
npm run start
应用程序/库堆栈
源源
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!);
}
}我指的是这里的代码。
发布于 2021-01-25 14:32:49
我通过以下修改解决了我的问题。看“★”。
(找到了另一个,也解决了。)
源源
// @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);
}另一个问题
在我解决了上面的问题后,又发生了一个问题。错误消息如下:
错误:无法确定“ZzzzzInput”类的“zzzzz”的GraphQL输入类型。该值(用作其TS类型或显式类型)是用适当的装饰符修饰的,还是一个适当的输入值?
查看模式-generator.js中的☆。
找不到Enum类型'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",
// });https://stackoverflow.com/questions/65878098
复制相似问题