GraphQL: добавление подписки в схему

Я пытаюсь настроить подписки с помощью 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.

Спасибо за помощь!

0 ответов

Другие вопросы по тегам