[英]Issue setting up subscription with GraphQL
Good day:再会:
I"m trying to setup my graphql server for a subscription. This is my schema.js我正在尝试为订阅设置我的 graphql 服务器。这是我的 schema.js
const ChatCreatedSubscription = new GraphQLObjectType({
name: "ChatCreated",
fields: () => ({
chatCreated: {
subscribe: () => pubsub.asyncIterator(CONSTANTS.Websocket.CHANNEL_CONNECT_CUSTOMER)
}
})
});
const ChatConnectedSubscription = {
chatConnected: {
subscribe: withFilter(
(_, args) => pubsub.asyncIterator(`${args.id}`),
(payload, variables) => payload.chatConnect.id === variables.id,
)
}
}
const subscriptionType = new GraphQLObjectType({
name: "Subscription",
fields: () => ({
chatCreated: ChatCreatedSubscription,
chatConnected: ChatConnectedSubscription
})
});
const schema = new GraphQLSchema({
subscription: subscriptionType
});
However, I'm getting this error when I try to run my subscription server:但是,当我尝试运行订阅服务器时出现此错误:
ERROR introspecting schema: [
{
"message": "The type of Subscription.chatCreated must be Output Type but got: undefined."
},
{
"message": "The type of Subscription.chatConnected must be Output Type but got: undefined."
}
]
A field definition is an object that includes these properties: type
, args
, description
, deprecationReason
and resolve
.字段定义是一个包含以下属性的对象: type
、 args
、 description
、 deprecationReason
和resolve
。 All these properties are optional except type
.除了type
之外,所有这些属性都是可选的。 Each field in your field map must be an object like this -- you cannot just set the field to a type like you're doing.字段映射中的每个字段都必须是这样的对象——您不能像正在做的那样将字段设置为类型。
Incorrect:不正确:
const subscriptionType = new GraphQLObjectType({
name: "Subscription",
fields: () => ({
chatCreated: ChatCreatedSubscription,
chatConnected: ChatConnectedSubscription
})
});
Correct:正确的:
const subscriptionType = new GraphQLObjectType({
name: "Subscription",
fields: () => ({
chatCreated: {
type: ChatCreatedSubscription,
},
chatConnected: {
type: ChatConnectedSubscription,
},
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.