- 
                Notifications
    
You must be signed in to change notification settings  - Fork 63
 
Open
Description
when passing arguments via variables the subscription resolver receives args correctly. If the variables aren't used and hardcoded to the query the subscription resolver gets an empty object.
This modification to src/__tests__/subscription.test.ts will demonstrate
Changed the query from
    subscription ($priority: Int = 0) {
      importantEmail(priority: $priority) {
        email {
          from
          subject
        }
        inbox {
          unread
          total
        }
      }
    }
to
     subscription {
      importantEmail(priority: 0) {
        email {
          from
          subject
        }
        inbox {
          unread
          total
        }
      }
    }
and added expect(args).toEqual({"priority": 0})
function createSubscription(pubsub: SimplePubSub<Email>) {
  const document = parse(`
    subscription {
      importantEmail(priority: 0) {
        email {
          from
          subject
        }
        inbox {
          unread
          total
        }
      }
    }
  `);
  const emails = [
    {
      from: "[email protected]",
      subject: "Hello",
      message: "Hello World",
      unread: false
    }
  ];
  const inbox = { emails };
  const QueryType = new GraphQLObjectType({
    name: "Query",
    fields: {
      inbox: { type: InboxType, resolve: (...args) => {
        return emails
      } }
    }
  });
  const emailSchema = new GraphQLSchema({
    query: QueryType,
    subscription: new GraphQLObjectType({
      name: "Subscription",
      fields: {
        importantEmail: {
          type: EmailEventType,
          args: {
            priority: { type: GraphQLInt }
          },
          // FIXME: we shouldn't use mapAsyncIterator here since it makes tests way more complex
          subscribe(root,args) {
            return pubsub.getSubscriber((newEmail) => {
              expect(args).toEqual({"priority": 0})
              emails.push(newEmail);
              return {
                importantEmail: {
                  email: newEmail,
                  inbox
                }
              };
            });
          }
        }
      }
    })
  });
Metadata
Metadata
Assignees
Labels
No labels