Skip to content

Commit

Permalink
pass base context (db, user, userId) along to context creator
Browse files Browse the repository at this point in the history
resolves #51
  • Loading branch information
smeijer committed Jul 10, 2019
1 parent 5a1dff8 commit ef73530
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions server/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function getContextCreator(meteorApolloConfig, initialApolloConfig) {
meteorAccounts,
} = initialApolloConfig;

const baseContext = { db };
return async function getContext({ req: request, connection }) {
// This function is called whenever a normal graphql request is being made,
// as well as when a client initiates a new subscription. However, when a
Expand All @@ -98,10 +99,6 @@ function getContextCreator(meteorApolloConfig, initialApolloConfig) {
// reconstruct a fake request object to be used by the context creator.
const req = connection ? connection.context.req : request;

const defaultContext = defaultContextResolver
? await defaultContextResolver({ req, connection })
: {};

let userContext = {};
if (meteorAccounts !== false && Package['accounts-base']) {
const loginToken =
Expand All @@ -112,8 +109,17 @@ function getContextCreator(meteorApolloConfig, initialApolloConfig) {
userContext = await getUserForContext(loginToken, meteorApolloConfig.userFields);
}

const defaultContext = defaultContextResolver
? await defaultContextResolver({
req,
connection,
...baseContext,
...userContext,
})
: {};

return {
db,
...baseContext,
...userContext,
...defaultContext,
};
Expand Down

0 comments on commit ef73530

Please sign in to comment.