我正在尝试使用GraphQL和Relay设置订阅。我有以下突变,增加了一个新团队:
const createTeamMutation = mutationWithClientMutationId({
name: 'CreateTeam',
inputFields: {
ownerId: { type: new GraphQLNonNull(GraphQLInt) },
name: { type: new GraphQLNonNull(GraphQLString) },
},
outputFields: {
team: {
type: teamType,
resolve: (payload) => payload
}
},
mutateAndGetPayload: (team) => {
const { ownerId, name } = team;
// Using Sequalize ORM here..
return db.models.team.create(team)
.then.... etc
}
});
这很好但我似乎无法弄清楚如何让我的订阅至少在GraphiQL中工作。我的架构中有以下定义:
const GraphQLCreateTeamSubscription = subscriptionWithClientId({
name: 'CreateTeamSubscription',
outputFields: {
team: {
type: teamType,
resolve: (payload) => payload
}
},
subscribe: (input, context) => {
// What is meant to go here??
},
});
我不确定如何构建订阅功能,似乎无法找到足够的文档。当我在GraphiQL中运行以下内容时,
subscription createFeedSubscription {
team {
id
ownerId
name
}
}
我收到以下错误:
Cannot query field team on type Subscription.
感谢您的帮助!