Skip to content

Instantly share code, notes, and snippets.

@govorov
Created October 17, 2017 22:29
Show Gist options
  • Save govorov/67311dcd7a4c9491f78454d9c02a3c0e to your computer and use it in GitHub Desktop.
Save govorov/67311dcd7a4c9491f78454d9c02a3c0e to your computer and use it in GitHub Desktop.
//
// graphql/types/new-card-patch.ts
//
export const NewCardPatch = `
input NewCardPatch {
# title is required
title : String!
description : String
done : Boolean
}
`;
//
// graphql/types.ts
//
import { Card } from 'graphql/types/card';
import { CardPatch } from 'graphql/types/card-patch';
import { NewCardPatch } from 'graphql/types/new-card-patch';
export const types = [
Card,
CardPatch,
NewCardPatch, // <-- add type here
];
//
// graphql/mutations/create-card.ts
//
import * as uuid from 'uuid/v4';
import { getRepository } from 'typeorm';
import { Card } from 'entities/card';
export const createCardMutation = {
async createCard(_, { card: attrs }) {
const repository = getRepository(Card);
const card = {
id: uuid(),
...attrs,
};
await repository.save(card);
return card;
}
};
//
// graphql/resolvers.ts
//
import { cardResolver } from 'graphql/resolvers/card';
import { cardsResolver } from 'graphql/resolvers/cards';
import { toggleCardMutation } from 'graphql/mutations/toggle-card';
import { updateCardMutation } from 'graphql/mutations/update-card';
import { createCardMutation } from 'graphql/mutations/create-card';
export const resolvers = {
Query: {
...cardsResolver,
...cardResolver,
},
Mutation: {
...toggleCardMutation,
...updateCardMutation,
...createCardMutation, // <-- add mutation to schema
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment