MCPcopy Create free account
hub / github.com/apollographql/fullstack-tutorial / context

Function context

final/server/src/index.js:24–36  ·  view source on GitHub ↗
({ req })

Source from the content-addressed store, hash-verified

22
23// the function that sets up the global context for each resolver, using the req
24const context = async ({ req }) => {
25 // simple auth check on every request
26 const auth = (req.headers && req.headers.authorization) || '';
27 const email = Buffer.from(auth, 'base64').toString('ascii');
28
29 // if the email isn't formatted validly, return null for user
30 if (!isEmail.validate(email)) return { user: null };
31 // find a user by their email
32 const users = await store.users.findOrCreate({ where: { email } });
33 const user = users && users[0] ? users[0] : null;
34
35 return { user };
36};
37
38// Set up Apollo Server
39const server = new ApolloServer({

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected