This file contains 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
// pages/index.js | |
import Head from 'next/head' | |
import Users from '../components/Users' | |
import { withApollo } from '../apollo/client' | |
const Index = () => { | |
return ( | |
<div className="container"> | |
<Head> | |
<title>Create Next App</title> |
This file contains 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
// components/Users.js | |
import React from 'react' | |
import gql from 'graphql-tag' | |
import { useQuery } from '@apollo/react-hooks' | |
const UsersQuery = gql` | |
query Users { | |
users { | |
id | |
firstName |
This file contains 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
// pages/api/graphql.js | |
import { ApolloServer } from 'apollo-server-micro' | |
import { MongoClient } from 'mongodb' | |
import { schema } from '../../apollo/schema' | |
require('dotenv').config() | |
let db | |
const apolloServer = new ApolloServer({ |
This file contains 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
// apollo/revolvers.js | |
export const resolvers = { | |
Query: { | |
users(_parent, _args, _context, _info) { | |
return _context.db | |
.collection('users') | |
.findOne() | |
.then((data) => { | |
return data.users | |
}) |
This file contains 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
// pages/api/graphql.js | |
import { ApolloServer, gql } from 'apollo-server-micro' | |
import { makeExecutableSchema } from 'graphql-tools' | |
import { MongoClient } from 'mongodb' | |
require('dotenv').config() | |
const typeDefs = gql` | |
type User { | |
id: ID! |
This file contains 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
// apollo/client.js | |
import React from 'react' | |
import Head from 'next/head' | |
import { ApolloProvider } from '@apollo/react-hooks' | |
import { ApolloClient } from 'apollo-client' | |
import { InMemoryCache } from 'apollo-cache-inmemory' | |
let globalApolloClient = null | |
/** |
This file contains 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
For Example: | |
cd ~/projects/node-redis | |
npm link | |
cd ~/projects/node-bloggy | |
npm link redis # links to your local redis | |
To reinstall from your package.json: | |
npm unlink redis | |
npm install |
This file contains 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
{ | |
"print to console": { | |
"prefix": "cl", | |
"body": [ | |
"console.log('--->', $1)" | |
], | |
"description": "Log output to console" | |
}, | |
"import React": { | |
"prefix": "imr", |