Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscribe function doesn't pass correct arguments when hardcoded to the query #183

Open
pogson opened this issue Oct 26, 2022 · 3 comments

Comments

@pogson
Copy link

pogson commented Oct 26, 2022

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
                }
              };
            });
          }
        }
      }
    })
  });
@half2me
Copy link

half2me commented Apr 6, 2023

I was about to report this. I have this exact same issue.

@laurisvan
Copy link

laurisvan commented Apr 29, 2023

I cannot tell this for certain, but it is likely mutations have the same problem. At least I remember we have JIT handling disabled for both subscriptions and mutations, and the cause was likely the same. Cannot tell this for certain - it's been a while since we encountered it. :(

@laurisvan
Copy link

Is there any update regarding this issue? We have runned graphql-jit with subscriptions (and mutations) disabled for the past few years, but it would be great to have them supported.

We might be able to contribute to a fix, but need a few pointers from the original authors to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants