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 fetch from 'isomorphic-fetch' | |
import { ApolloClient } from 'apollo-client' | |
import { HttpLink } from 'apollo-link-http' | |
import { InMemoryCache } from 'apollo-cache-inmemory' | |
import { from, ApolloLink } from 'apollo-link' | |
// WORKING ------------------------------------------------------------------- | |
const httpLink = new HttpLink({ | |
uri: process.env.GRAPHCOOL_ENDPOINT, |
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 { GraphQLServer } from 'graphql-yoga' | |
import { importSchema } from 'graphql-import' | |
import { Prisma } from './generated/prisma' | |
import { Context } from './utils' | |
const resolvers = { | |
Query: { | |
async allBooks(parent, args, ctx, info) { | |
return await ctx.db.query.books({}, info) | |
} |
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
type Book { | |
id: ID! @unique | |
title: String! | |
page: [Int!]! | |
} |
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
mutation { | |
first: createBook(data: { | |
title: "First book", | |
page: { | |
set: [1,2,3,4] | |
} | |
}) { | |
id | |
} | |
} |
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
040ee84504ae89bd76c1536376520cc8832e49649dc751df18f8e8020f0b8e534da34d848bc67ca30977edb902cb6e48c3d4a54553cb63910fd4b9c7735208766f |
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 fetch from 'isomorphic-fetch' | |
import { ApolloClient } from 'apollo-client' | |
import { InMemoryCache } from 'apollo-cache-inmemory' | |
import { from, ApolloLink } from 'apollo-link' | |
import { createUploadLink } from 'apollo-upload-client' | |
let apolloClient = null | |
// Apollo server polyfill | |
if (!process.browser) { |
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
# database/datamodel.graphql | |
type Grocer { | |
id: ID! @unique | |
createdAt: DateTime! | |
updatedAt: DateTime! | |
email: String! @unique | |
} |
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
# src/schema.graphql | |
type Query { | |
viewer: Viewer | |
products: [Product!]! | |
} | |
type Mutation { | |
addItemToBasket(productId: ID!): Viewer | |
removeItemFromBasket(itemId: ID!): Viewer |
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
// src/permissions/rules.ts | |
import { rule, and, or, not } from 'graphql-shield' | |
import { Context, getUserEmail } from '../utils' | |
export const isGrocer = rule()(async (parent, args, ctx: Context, info) => { | |
const email = getUserEmail(ctx) | |
// Is there a Grocer with such email in our database (Prisma)? | |
return ctx.db.exists.Grocer({ email }) | |
}) |
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
// src/permissions/index.ts | |
import { shield, and } from 'graphql-shield' | |
import * as rules from './rules' | |
export const permissions = shield({ | |
Query: { | |
viewer: rules.isGrocer, | |
}, | |
Mutation: { |