Skip to content

Instantly share code, notes, and snippets.

View nikolasburk's full-sized avatar
😑

Nikolas nikolasburk

😑
View GitHub Profile
{
"hello": "Hello World"
}
query {
user(id: "user123") {
name
}
}
const resolvers = {
Query: {
hello: () => `Hello World`
}
}
const resolvers = {
Query: {
user: (root, args) => db.getUser(argd.id),
users: () => db.getUsers(),
},
Mutation: {
createUser: (root, args) => db.createUser(args.name),
updateUser: (root, args) => db.updateUser(args.id, args.name),
deleteUser: (root, args) => db.deleteUser(args.id),
},
const resolvers = {
Query: {
user: (root, args) => db.getUser(argd.id),
users: () => db.getUsers(),
},
Mutation: {
createUser: (root, args) => db.createUser(args.name),
updateUser: (root, args) => db.updateUser(args.id, args.name),
deleteUser: (root, args) => db.deleteUser(args.id),
}
import { GraphQLServer } from 'graphql-yoga'
const typeDefs = `
type Query {
hello: String!
}
`
const resolvers = {
Query: {
@nikolasburk
nikolasburk / instructions.md
Last active March 7, 2020 17:50
Use the Contentful GraphQL API inside a GraphQL Playground

Use the Contentful GraphQL API inside a GraphQL Playground

The Contentful GraphQL API ships with GraphiQL by default. To get even better workflows (such as multiple tabs, speciyfing HTTP headers or work with multiple GraphQL APIs side-by-side), you can use a GraphQL Playground.

1. Get the endpoint for your Contentful GraphQL API

The endpoint of your Contentful GraphQL API has the following structure: https://cdn.contentful.com/spaces/{SPACE}/graphql/alpha/explore?access_token={CDA_TOKEN}

There are two placeholders that need to be replaced:

@nikolasburk
nikolasburk / stitching.graphql
Last active June 29, 2018 12:07
stitching.graphql
query myMenu {
menu {
burger {
bun
cheese
patty
}
salad {
romaine
tomato

Data model vs Prisma database schema

When starting out with GraphQL and Prisma, the amount of .graphql-files you're working with can be confusing. Yet, it's crucial to understand what the role of each of them is.

Looking only at Prisma, there are two .graphql-files that are relevant:

  • The data model containing the model definitions for your service's APIs, typically called datamodel.graphql.
  • The Prisma database schema defining the actual CRUD/realtime operations of the service's API, typically called prisma.graphql.
input AddProjectInput {
name: String!
stage: String!
secrets: [String!]
clientMutationId: String
}
type AddProjectPayload {
project: Project
clientMutationId: String