Skip to content

Instantly share code, notes, and snippets.

@govorov
Last active October 17, 2017 22:04
Show Gist options
  • Save govorov/d551f6778f297841b506091607d16cce to your computer and use it in GitHub Desktop.
Save govorov/d551f6778f297841b506091607d16cce to your computer and use it in GitHub Desktop.
//
// graphql/types/card-patch.ts
//
export const CardPatch = `
input CardPatch {
title : String
description : String
done : Boolean
}
`;
//
// graphql/types.ts
//
import { Card } from 'graphql/types/card';
import { CardPatch } from 'graphql/types/card-patch';
export const types = [
Card,
CardPatch, // <-- add new type to types list
];
//
// graphql/mutation.ts
//
export const Mutation = `
type Mutation {
toggleCard (
id: String!
): Card
# add mutation definition here
updateCard (
id: String!
patch: CardPatch!
): Card
}
`;
//
// graphql/mutations/update-card.ts
//
import { getRepository } from 'typeorm';
import { Card } from 'entities/card';
export const updateCardMutation = {
async updateCard(_, { id, patch }) {
const repository = getRepository(Card);
const card = await repository.findOne({ id });
const result = await repository.updateById(id, patch);
return {
...card,
...patch,
};
}
};
//
// graphql/resolvers.ts
//
export const resolvers = {
Query: {
...cardsResolver,
...cardResolver,
},
Mutation: {
...toggleCardMutation,
...updateCardMutation, // <-- add new mutation to resolvers
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment