2

I am trying to setup subscriptions with GraphQL and Relay. I have the following mutation which adds a new team:

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
 }
});

This works fine but I can't seem to figure out how to get my subscriptions working at least in GraphiQL. I have the following definition in my schema:

const GraphQLCreateTeamSubscription = subscriptionWithClientId({
  name: 'CreateTeamSubscription',
  outputFields: {
    team: {
      type: teamType,
      resolve: (payload) => payload
    }
  },
  subscribe: (input, context) => {
    // What is meant to go here??
  },
});

I am not sure how to build out the subscribe feature and can't seem to find enough documentation. When I run the following in GraphiQL,

subscription createFeedSubscription {
  team {
    id
    ownerId
    name
  } 
}

I get the following error:

Cannot query field team on type Subscription.

Thank you for all the help!

Mary Cahill
  • 163
  • 3
  • 12

0 Answers0