-
Notifications
You must be signed in to change notification settings - Fork 2k
Set default value for contextValue #365
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
Comments
I'm not sure I follow. If you don't need any of the things you would put in context, why do you want an object? Also, if you want the empty object, is there something wrong with providing that directly? |
Without an implied guarantee of an object we either need to assure it's there: Or, we need to make sure to code a little more defensively in the This was great because the rootValue is guaranteed to be an object. If we try something similar without an object present: |
I think if you have any usage of context or rootValue in your schema, then it's reasonable to assume you're providing something for them when executing, and so it's not necessary to code defensively in resolution functions. Also in the previous version where rootValue was used in place of context, this situation still existed since rootValue also does not have a default value and is |
BTW, the documentation of the |
Following up from #326 (comment) often times it does make sense that the
contextValue
is an object. This is because in addition to an authToken, you might have another token (resetPasswordToken
,verifyEmailToken
, etc) or even something like asocket
for subscriptions. However, if you don't need any of those things, it's still nice to callgraphql(Schema, query)
instead ofgraphql(Schema, query, null, {})
. To keep it that way,execute
should default the value to an object here: https://github.com/graphql/graphql-js/blob/master/src/execution/execute.js#L115Thoughts?
The text was updated successfully, but these errors were encountered: