Last active
October 17, 2017 22:04
-
-
Save govorov/d551f6778f297841b506091607d16cce 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
// | |
// 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