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
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
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
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
# To Authenticate | |
mutation Authenticate($githubCode: String!) { | |
authenticate(githubCode: $githubCode) { | |
token | |
user { | |
name | |
} | |
} | |
} |
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/resolvers/index.ts | |
import { note } from './Query/note' | |
import { notes } from './Mutation/notes' | |
export const resolvers = { | |
Query: { | |
note, | |
}, | |
Mutation: { | |
...notes |
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/resolvers/Mutation/auth.ts | |
import * as jwt from 'jsonwebtoken' | |
export const auth = { | |
authenticate: async (parent, { githubCode }, ctx: Context, info) => { | |
// ... | |
return { | |
token: jwt.sign({ userId: user.id }, process.env.JWT_SECRET), // <- Sign in | |
user |
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/resolvers/index.ts | |
import { me } from './Query/me' | |
import { auth } from './Mutation/auth' | |
export const resolvers = { | |
Query: { | |
me, | |
}, | |
Mutation: { | |
...auth, |
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 | |
# import User, Note from './generated/database.graphql' | |
type Query { | |
me: User, | |
note(id: ID!): Note | |
} | |
type Mutation { |
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/index.ts | |
import { Prisma } from './generated/prisma' | |
new Prisma({ | |
endpoint: process.env.PRISMA_ENDPOINT, | |
secret: process.env.PRISMA_SECRET | |
}) |