如何在GraphQQL中定义异步字段解析器?
我有解决字段
在我的消息
中键入的代码。
import {
GraphQLString,
GraphQLObjectType,
} from 'graphql';
const MessageType = new GraphQLObjectType({
name: 'Message',
fields: () => ({
text: { type: GraphQLString },
comments: new GraphQLList(MessageType),
}),
});
问题是,我想让字段
键入async函数:
import {
GraphQLString,
GraphQLObjectType,
} from 'graphql';
const MessageType = new GraphQLObjectType({
name: 'Message',
fields: async () => {
await Promise.resolve(r => setTimeout(r, 100)); // <--------------------- PROMISE EXAMPLE
return ({
text: { type: GraphQLString },
comments: new GraphQLList(MessageType),
};;
},
});
问题是,字段
类型不接受承诺,是否有任何解决方法?
谢谢。
I have code to resolve fields
type in my Message
.
import {
GraphQLString,
GraphQLObjectType,
} from 'graphql';
const MessageType = new GraphQLObjectType({
name: 'Message',
fields: () => ({
text: { type: GraphQLString },
comments: new GraphQLList(MessageType),
}),
});
Problem is, that I would like to have fields
type as async function:
import {
GraphQLString,
GraphQLObjectType,
} from 'graphql';
const MessageType = new GraphQLObjectType({
name: 'Message',
fields: async () => {
await Promise.resolve(r => setTimeout(r, 100)); // <--------------------- PROMISE EXAMPLE
return ({
text: { type: GraphQLString },
comments: new GraphQLList(MessageType),
};;
},
});
Problem is, that fields
type does not accept promise, is there any workaround?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论