This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR slightly tweaks the default behavior so that by default the express request is passed as the context object, and updates a decent amount of the README documentation.
The rationale is to make it simpler to support express middleware, in particular authentication. Most express middleware works similarly - some extra field is tacked onto
request
. This is convenient for express developers because therequest
object is accessible from every route handler. The graphql equivalent of a route handler is a resolver, so if therequest
object is simply available to every resolver, express middleware is generally usable without having to alter the graphqlHTTP route handler itself. I think this is an "expressy" thing to do, even if it does not quite aesthetically jive with the deep love of immutability reflected in graphql itself.Middleware that behaves this way & can now be used without altering the graphqlHTTP method call:
Note the "advanced scenario" docs of authentication are simpler now - you do not have to pass a function to the graphqlHTTP method, you can just use the same call that was in the "intro".
This is backward compatible unless you wrote code that relies on having a falsy context which seems unlikely.
Documentation changes are mostly self-explanatory. The change to using port 4000 in the example is so that it doesn't conflict by default with create-react-app - a small tweak but this may avoid little bits of confusion. Using 'require' instead of 'import' is a bit sad but preferable for now because it means that this code works with node out of the box - most node developers are not transpiling.