Skip to content

Instantly share code, notes, and snippets.

View lovegrovegeorge's full-sized avatar

George lovegrovegeorge

View GitHub Profile
@lovegrovegeorge
lovegrovegeorge / utils.js
Created May 22, 2018 10:27
Utility functions used in a Prisma server
const jwt = require('jsonwebtoken')
function getUserId(ctx) {
let authorization = ctx.request ? ctx.request.get('authorization') : null
// Get from subscription connection context
if (!authorization) {
authorization = ctx.connection ? ctx.connection.context.authorization : null
}
@lovegrovegeorge
lovegrovegeorge / apollo.js
Created May 22, 2018 10:21
React Native Apollo client setup
import { createHttpLink } from 'apollo-link-http'
import { ApolloLink, split, concat } from 'apollo-link'
import { ApolloClient } from 'apollo-client'
import { WebSocketLink } from 'apollo-link-ws'
import { getMainDefinition } from 'apollo-utilities'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { onError } from 'apollo-link-error'
import { withClientState } from 'apollo-link-state'
import env from '../env.json'
@lovegrovegeorge
lovegrovegeorge / index.js
Created May 22, 2018 10:20
Prisma server setup
const { GraphQLServer } = require('graphql-yoga')
const { Prisma } = require('prisma-binding')
const resolvers = require('./resolvers')
const server = new GraphQLServer({
typeDefs: 'src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Prisma({