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

apolloOptions.context type and default value #75

Closed
lvauvillier opened this issue Aug 3, 2016 · 5 comments
Closed

apolloOptions.context type and default value #75

lvauvillier opened this issue Aug 3, 2016 · 5 comments

Comments

@lvauvillier
Copy link

By default context is undefined and has a type to any.

attachConnectorsToContext from graphql-tools works only with an object typed context.
If context is undefined, it will raise an error for each requests.

So, we have to explicitely set context to an empty object to make it working :

server.use('/', bodyParser.json(), apolloExpress({
  schema: executableSchema,
  context: {},
}));

Maybe apolloOptions.context can have a default value setted to {} and be explicitely typed as Object.

@lvauvillier lvauvillier changed the title apolloOption.context type and default value apolloOption.context type and default values Aug 3, 2016
@lvauvillier lvauvillier changed the title apolloOption.context type and default values apolloOptions.context type and default values Aug 3, 2016
@lvauvillier lvauvillier changed the title apolloOptions.context type and default values apolloOptions.context type and default value Aug 3, 2016
@helfer
Copy link
Contributor

helfer commented Aug 3, 2016

Yeah, it's true that there's a bit of a mismatch. The reason we let it be any is that graphql-js accepts any as the context, and we don't want to change that function signature with apollo server. Maybe there's a place in the documentation where we can make it clear that if connectors are used, the context has to be explicitly set to an empty object first?

@vedmalex
Copy link

vedmalex commented Aug 4, 2016

@helfer it will be very helpfull, i've moving to new server and spent some time to make it works, before i found the solution! just because graphql-implementation make it required.

@helfer
Copy link
Contributor

helfer commented Aug 4, 2016

If someone could submit a PR to the docs, that would be great! 😃

@tomitrescak
Copy link

Guys, since context now it an object, how can I modify context based on request? In Meteor the context is filled with userID, so how can this be achieved with the new design ?

I need context to be a function that accepts request.

@helfer
Copy link
Contributor

helfer commented Aug 8, 2016

I think this issue is mostly solved, so I'll close this. Feel free to open again if there's still something to discuss.

@helfer helfer closed this as completed Aug 8, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants