apollographql / meteor-integration

🚀 meteor add apollo
http://dev.apollodata.com/core/meteor.html
108 stars 45 forks source link

How to use async/await with webpack:webpack? #27

Closed lorensr closed 6 years ago

lorensr commented 8 years ago

https://atmospherejs.com/webpack/webpack

Using async/await gives this error:

GraphQL error: regeneratorRuntime is not defined

Taken from https://github.com/apollostack/meteor-integration/issues/25#issuecomment-238658365

smeijer commented 8 years ago

Perhaps helpful. When using async / await, and using the babel-polyfill to fix the error quoted by @lorensr above, Graphiql returns the following error on the async query:

"message": "Match error: Failed Match.OneOf, Match.Maybe or Match.Optional validation",

I have no idea what or where the Match failed.

warlokkz commented 8 years ago

I believe @smeijer is right, @lorensr, to include the babel-polyfill package.

We use the webpack:webpack package in our Meteor setup, and I eliminated the regeneratorRuntime error by using something like this for the resolvers:

import { Random } from 'meteor/random';
import 'babel-polyfill';

export const typeDefs = [`
type Email {
  address: String
  verified: Boolean
}
type User {
  emails: [Email]
  username: String
  randomString: String
}
type Query {
  user(id: String!): User
}
schema {
  query: Query
}
`];

export const resolvers = {
  Query: {
    async user(root, args, context) {
      // Only return the current user, for security
      if (context.userId === args.id) {
        return await Meteor.users.findOne(context.userId);
      }
    }
  },
  User: {
    emails: ({ emails }) => emails,
    randomString: () => Random.id()
  }
};
xavxyz commented 7 years ago

Is it still relevant? This issue happened before Meteor 1.4.2.1 and babel-runtime requirement for Babel transform.

If yes, do you think we should have a note in the docs mentioning this issue & fix?

(assumption about the problem: if the right preset/plugins are added in .babelrc, is babel-polyfill needed? 🤔 )