Last active
March 20, 2019 09:37
-
-
Save jgoux/fbf9e0cb112d2aa0d73ff67f7192bf5e to your computer and use it in GitHub Desktop.
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 { 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() {} | |
] | |
} |
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 { 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