This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const User = { | |
| getAll: () => { /* fetching/transform logic for all users */ }, | |
| getById: (id) => { /* fetching/transform logic for a single user */ }, | |
| getByGroupId: (id) => { /* fetching/transform logic for a group of users */ }, | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| users: (root, args, context) => { | |
| if (!context.user || !context.user.roles.includes('admin')) return null; | |
| return context.models.User.getAll(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| users: (root, args, context) => { | |
| if (!context.user) return null; | |
| return ['bob', 'jake']; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { ApolloServer } = require('apollo-server'); | |
| const server = new ApolloServer({ | |
| typeDefs, | |
| resolvers, | |
| context: ({ req }) => { | |
| // get the user token from the headers | |
| const token = req.headers.authorization || ''; | |
| // try to retrieve a user with the token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { schema } from '../my-schema'; | |
| // Docs for `graphql` function | |
| // http://graphql.org/graphql-js/graphql/#graphql | |
| import { graphql } from 'graphql'; | |
| it('executes a query that looks up some data', async () => { | |
| // optionally create some fake context (i.e. data connectors) | |
| const myFakeContext = { restConnectionOne: { findOne: jest.fn() } }; |
NewerOlder