我正在尝试使用 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.
谢谢大家的帮助!