具有不同嵌套参数的GraphQLObjectType的类型解析



我可能处理了这个不正确的问题,但对于字段具有不同argsGraphQLObjectType似乎只会解析为第一个子字段。这里有没有我所缺少的更好的惯例或结构?

示例中:

import { GraphQLFloat, GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql';
export default new GraphQLObjectType({
name: 'Parent',
fields: {
firstChild: {
type: GraphQLString,
args: {
text: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: (_: never, { text }: { text: string }) => {
return text;
},
},
secondChild: {
type: GraphQLFloat,
args: {
float: { type: new GraphQLNonNull(GraphQLFloat) },
},
resolve: (_: never, { float }: { float: number }) => {
return float;
},
},
},
});

secondChild的解析将导致的打字脚本出错

Type '(_: never, { float }: { float: number; }) => number' is not assignable to type 'GraphQLFieldResolver<never, any, { text: string; }>'.
Types of parameters '__1' and 'args' are incompatible.
Property 'float' is missing in type '{ text: string; }' but required in type '{ float: number; }'.ts(2322)
test.ts(21, 40): 'float' is declared here.
definition.d.ts(470, 3): The expected type comes from property 'resolve' which is declared here on type 'GraphQLFieldConfig<never, any, { text: string; }>'

似乎在https://github.com/graphql/graphql-js/issues/2152和PRhttps://github.com/graphql/graphql-js/pull/2488

相关内容

  • 没有找到相关文章

最新更新