Skip to content

Instantly share code, notes, and snippets.

View maticzav's full-sized avatar
🎉
Keep moving forward!

Matic Zavadlal maticzav

🎉
Keep moving forward!
View GitHub Profile
mutation {
first: createBook(data: {
title: "First book",
page: {
set: [1,2,3,4]
}
}) {
id
}
}
type Book {
id: ID! @unique
title: String!
page: [Int!]!
}
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)
}
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,
# To Authenticate
mutation Authenticate($githubCode: String!) {
authenticate(githubCode: $githubCode) {
token
user {
name
}
}
}
// src/resolvers/index.ts
import { note } from './Query/note'
import { notes } from './Mutation/notes'
export const resolvers = {
Query: {
note,
},
Mutation: {
...notes
// 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
// src/resolvers/index.ts
import { me } from './Query/me'
import { auth } from './Mutation/auth'
export const resolvers = {
Query: {
me,
},
Mutation: {
...auth,
# src/schema.graphql
# import User, Note from './generated/database.graphql'
type Query {
me: User,
note(id: ID!): Note
}
type Mutation {
// src/index.ts
import { Prisma } from './generated/prisma'
new Prisma({
endpoint: process.env.PRISMA_ENDPOINT,
secret: process.env.PRISMA_SECRET
})