graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Runs outside Fiber while using inside a Meteor package

Open kamilkisiela opened this issue 6 years ago • 2 comments

Issue

The issue occurs when using @accounts/graphql-api inside of a meteor package. If we'd create the same logic but inside an app, it'd work.

const resolver = {
  User: {
    foo: () => FooCollection.findOne()
  }
};
mutation login {
  loginWithPassword( /*...*/ ) {
    user {
      username
      foo {
        id
      }
    }
  }
}

Gives:

{
  "data": {
    "loginWithPassword": {
      "user": {
        "username": "foo",
        "foo": null
      }
    }
  },
  "errors": [
    {
      "message": "Can't wait without a fiber",
      "locations": [
        {
          "line": 5,
          "column": 7
        }
      ],
      "path": [
        "loginWithPassword",
        "user",
        "foo"
      ]
    }
  ]
}

Reproduction

Run it and go to http://localhost:3000. It should display SUCCESS or FAILURE.

Failure:

Meteor@1.5.2 or less https://github.com/kamilkisiela/js-accounts-meteor-fiber/tree/failure

Success:

Meteor@1.6-alpha.0 at least https://github.com/kamilkisiela/js-accounts-meteor-fiber/tree/success

Differences

https://github.com/kamilkisiela/js-accounts-meteor-fiber/compare/failure...success

Idea

For me it's something to do with async/await and Promise. async/await is being compiled to something that uses asyncGeneratorFunction from babel-runtime's helpers and there's a Promise inside of it. For me, that Promise is not wrapped with a Fiber as it'd normally be in Meteor's environment.

kamilkisiela avatar Sep 02 '17 19:09 kamilkisiela