Skip to content

Instantly share code, notes, and snippets.

View alexandr-g's full-sized avatar

Oleksandr Hrishchuk alexandr-g

View GitHub Profile
@alexandr-g
alexandr-g / index.js
Created June 11, 2020 16:03
pages/index.js
// 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>
@alexandr-g
alexandr-g / Users.js
Created June 11, 2020 16:02
components/Users.js
// 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
@alexandr-g
alexandr-g / graphql.js
Created June 11, 2020 16:00
pages/api/graphql.js
// 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({
@alexandr-g
alexandr-g / revolvers.js
Created June 11, 2020 15:59
apollo/type-defs.js
// apollo/revolvers.js
export const resolvers = {
Query: {
users(_parent, _args, _context, _info) {
return _context.db
.collection('users')
.findOne()
.then((data) => {
return data.users
})
@alexandr-g
alexandr-g / graphql.js
Created June 11, 2020 15:56
Sharing schema between Apollo Client and Apollo Server
// 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!
@alexandr-g
alexandr-g / client.js
Last active June 11, 2020 15:53
Setting up Apollo Client with `withApollo()` HOC for NextJS application
// 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
/**
@alexandr-g
alexandr-g / gist:5ed8a19396387eb7cdb8a758fd4f933a
Created August 10, 2018 09:20
Testing changes to npm package locally
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
@alexandr-g
alexandr-g / javascript.json
Last active June 28, 2018 13:26
VSCode user snippets
{
"print to console": {
"prefix": "cl",
"body": [
"console.log('--->', $1)"
],
"description": "Log output to console"
},
"import React": {
"prefix": "imr",