mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

Problem setting dataloader contextToOptions with dataloader-sequelize 2.0.0 #670

Closed caioflores closed 5 years ago

caioflores commented 5 years ago

Following this discussion: https://github.com/mickhansen/graphql-sequelize/issues/656

The example server of dataloader with graph-yoga is not working anymore with dataloader-sequelize 2.0.0: https://github.com/mickhansen/graphql-sequelize/blob/master/examples/graphql-yoga/src/server.js

The new way to make it work as @intellix solved is:

schema.context = req => {
  const dataloaderContext = createContext(sequelize);

  resolver.contextToOptions = {
    dataloaderContext: [EXPECTED_OPTIONS_KEY]
  };
  return {
    ...req,
    dataloaderContext
  };
};

I'll open a PR to update README and example.

caioflores commented 5 years ago

Solved the problem here #671

mickhansen commented 5 years ago

Will discuss in PR.