Skip to content

Instantly share code, notes, and snippets.

@jgoux
Last active March 20, 2019 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgoux/fbf9e0cb112d2aa0d73ff67f7192bf5e to your computer and use it in GitHub Desktop.
Save jgoux/fbf9e0cb112d2aa0d73ff67f7192bf5e to your computer and use it in GitHub Desktop.
import { gql } from "apollo-server-koa"
export let typeDefs = gql`
type Action {
id: ID!
libelle: String!
active: Boolean!
}
`
export let Query = {
actions: [
gql`
extend type Query {
actions: [Action]!
}
`,
async function actions() {}
],
action: [
gql`
extend type Query {
action(id: ID!): Action!
}
`,
async function action() {}
]
}
export let Mutation = {
createAction: [
gql`
input CreateActionInput {
libelle: String!
}
extend type Mutation {
createAction(input: CreateActionInput!): Action!
}
`,
async function createAction() {}
],
updateAction: [
gql`
input UpdateActionInput {
id: ID!
libelle: String!
active: Boolean!
}
extend type Mutation {
updateAction(input: UpdateActionInput!): Action!
}
`,
async function updateAction() {}
]
}
import { gql } from "apollo-server-koa"
import R from "ramda"
import { Action } from "./generated-schema"
// type definition for Action
export let typeDefs = Action.typeDefs
// expose all queries for Action
export let Query = Action.Query
// customize mutation, add extra one, omit one
export let Mutation = R.pipe(
R.mergeLeft({
createAction: [
Action.Mutation.createAction.typeDefs,
async function createAction(...resolverArgs) {
let [, args, ctx] = resolverArgs
// custom logic
let action = await Action.Mutation.createAction.resolver(
...resolverArgs
)
// more custom logic
return action
}
],
excentricStuff: [
gql`
extend type Mutation {
excentricStuff(foo: String!): Action
}
`,
async function excentricStuff(_, { foo }, { prisma }) {
return await prisma.action({ label: foo })
}
]
}),
R.omit(["deleteAction"])
)(Action.Mutation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment