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 { ApolloServer } from 'apollo-server-micro'; | |
| import resolvers from './resolvers'; | |
| import typeDefs from './TypeDef'; | |
| const apolloServer = new ApolloServer({ | |
| typeDefs, | |
| resolvers, | |
| }); | |
| export const config = { |
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 { gql } from 'apollo-server-micro'; | |
| const typeDefs = gql` | |
| type User { | |
| id: Int! | |
| name: String! | |
| age: Int | |
| active: Boolean! | |
| } |
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 lodash from 'lodash/collection'; | |
| const users = [ | |
| { id: 1, name: 'barney', age: 36, active: true }, | |
| { id: 2, name: 'fred', age: 40, active: false }, | |
| { id: 3, name: 'pebbles', age: 1, active: true } | |
| ]; | |
| const resolvers = { | |
| Query: { |
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
| ... | |
| "scripts": { | |
| "dev": "next dev", | |
| "build": "next build", | |
| "start": "next start -p $PORT" | |
| }, | |
| ... |
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 data = [ | |
| { | |
| "id": 1, | |
| "name": "Leanne Graham", | |
| "username": "Bret", | |
| "email": "[email protected]", | |
| "address": { | |
| "street": "Kulas Light", | |
| "suite": "Apt. 556", | |
| "city": "Gwenborough", |
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 { gql } = require('apollo-server'); | |
| const typeDefs = gql` | |
| type User { | |
| id: Int! | |
| firstName: String! | |
| lastName: String! | |
| userName: String! | |
| email: String! | |
| jobTitle: String |
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
| MONGO_URI=mongodb+srv://fake:[email protected]/test?retryWrites=true&w=majority |
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
| require('dotenv').config(); | |
| const { MongoClient } = require('mongodb'); | |
| const faker = require('faker'); | |
| const generateUsers = async () => { | |
| const users = []; | |
| for (let id = 1; id <= 100; id++) { | |
| const firstName = faker.name.firstName(); | |
| const lastName = faker.name.lastName(); |
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 Users = require('../models/users'); | |
| const resolvers = { | |
| Query: { | |
| getUsers: async (_, args) => { | |
| // destrcture search, page, limit, and set default values | |
| const { search = null, page = 1, limit = 20 } = args; | |
| let searchQuery = {}; |
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
| require('dotenv').config(); | |
| const { ApolloServer } = require('apollo-server'); | |
| const mongoose = require('mongoose'); | |
| const typeDefs = require('./graphql/typeDefs'); | |
| const resolvers = require('./graphql/resolvers'); | |
| mongoose | |
| .connect(process.env.MONGO_URI, { | |
| useNewUrlParser: true, | |
| useUnifiedTopology: true |