0

Working getting subscriptions working in apollo. I have my web socket set up properly, and I can see that I'm connecting, as I see it flow into the pubsub module. Though I think something is up with how I subscribing, as the server is not triggering a response when I publish.

Apologize for any confusion around naming, as I'm using it for something called subscriptions.

Graphql Subscription

  subscription subscriptionsUpdated($userId: String!){
    subscriptionsUpdated(user: $userId, type:ROOM, open:true) {
        id,
        parent{
          ... on Rooms{
            id
          }
        }
    }
  }

GraphQLType

  subscription: new GraphQLObjectType({
    name: `subscriptions`,
    fields: {
      subscriptionsUpdated:{
        type:Subscriptions.type,
        args:{
          parent: { type: GraphQLString},
          type:{ type: ContentTypes },
          open: {type: GraphQLBoolean },
          user:{type: GraphQLString },
        },
        resolve:(source, args)=>{
          console.log('it worked and stuff');
          return {};
        }
      },
    }
  })

Susbscription Manager and setup functions:

import schema from '../graphql/index.js';
const subscriptionManager = new SubscriptionManager({
  schema,
  pubsub,
  setupFunctions: {
    subscriptionsUpdated: (options, args) => ({
      subscriptionsUpdated: (comment)=>{
        return true;
      },
    }),
  },
});

In My Mutation (I can see this firing)

pubsub.publish('subscriptionsUpdated', doc);

With the event firing, shouldn't the subscriptionsUpdated resolve function / or the setup function fire?

I've looked into the githunt examples and medium post on the topic, but still struggling to get this last part working.

Any help or insight would be awesome!

Justin
  • 2,940
  • 3
  • 25
  • 43
  • Subscriptions can be a bit tricky to debug initially, so I would simplify as much as possible. Have you tried removing the setupFunctions? I think they're optional if the channel has the same name as the top-level subscription field. – helfer Nov 16 '16 at 16:38
  • Yeah tried removing setup functions. Still no dice. I'm thinking maybe my graphql subscription query is setup wrong, though not sure. Going to keep digging. – Justin Nov 16 '16 at 18:55

1 Answers1

3

I wish I had a better answer on how I solved my issue. I've been tweaking things and I'm not sure what I did to make it work. Meh... :/

Though if you do get stuck somewhere along this way, dive into the graphql subscriptions package. You'll at least have a better idea of how things move.

If your connected properly your browser will respond with any other errors you're experiencing. Hope his helps! Safe journeys!

Justin
  • 2,940
  • 3
  • 25
  • 43