({ req })
| 22 | |
| 23 | // the function that sets up the global context for each resolver, using the req |
| 24 | const 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 |
| 39 | const server = new ApolloServer({ |
nothing calls this directly
no outgoing calls
no test coverage detected