Understanding Session
When a GraphQL request arrives at GraphQL Modules, GraphQL Modules creates a scope only for that network request. GraphQL Modules identifies this scope by a unique object given in the global application context. The global application context defined in your GraphQL server/library is not the same with the module's context, because all resolvers, context builders, dependency injections, etc. are encapsulated in the global application context.
You can decide how to pass the session object in your application's context-building phase.
GraphQL Modules tries to get the session
property of your global application context first, but if there is no session
property, it takes all application context objects as your network session objects.
express-graphql
#
Using in For example, express-graphql
passes express.Request
by default as the global application context:
If we need more stuff in the network session:
ApolloServer
#
Using in On the other hand, apollo-server
needs to be passed it like below:
#
Using in another application that doesn't use GraphQL Modules on the topEven if you want to use GraphQLModule
in a non-GraphQL-Modules application, you can safely pass the context builder of GraphQLModule
.
And you can use the internal context of your GraphQLModule
including Dependency Injection.
GraphQL Modules internally handles session
without the need of passing session
specifically.
modules
of ApolloServer
#
Using #
Using schema stitchingYou can safely extract reusable typeDefs
, resolvers
and context
from your GraphQLModule
, and use it outside GraphQLModule
.
This is what Session
means in GraphQL Modules.
You can read more about Provider Scopes in the Dependency Injection section.