Guest User

Untitled

a guest
Oct 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. //
  2. // graphql/types/new-card-patch.ts
  3. //
  4.  
  5. export const NewCardPatch = `
  6. input NewCardPatch {
  7. # title is required
  8. title : String!
  9. description : String
  10. done : Boolean
  11. }
  12. `;
  13.  
  14.  
  15. //
  16. // graphql/types.ts
  17. //
  18.  
  19. import { Card } from 'graphql/types/card';
  20. import { CardPatch } from 'graphql/types/card-patch';
  21. import { NewCardPatch } from 'graphql/types/new-card-patch';
  22.  
  23.  
  24. export const types = [
  25. Card,
  26. CardPatch,
  27. NewCardPatch, // <-- add type here
  28. ];
  29.  
  30.  
  31.  
  32. //
  33. // graphql/mutations/create-card.ts
  34. //
  35.  
  36. import * as uuid from 'uuid/v4';
  37.  
  38. import { getRepository } from 'typeorm';
  39. import { Card } from 'entities/card';
  40.  
  41.  
  42. export const createCardMutation = {
  43. async createCard(_, { card: attrs }) {
  44. const repository = getRepository(Card);
  45. const card = {
  46. id: uuid(),
  47. ...attrs,
  48. };
  49. await repository.save(card);
  50. return card;
  51. }
  52. };
  53.  
  54.  
  55. //
  56. // graphql/resolvers.ts
  57. //
  58.  
  59. import { cardResolver } from 'graphql/resolvers/card';
  60. import { cardsResolver } from 'graphql/resolvers/cards';
  61.  
  62. import { toggleCardMutation } from 'graphql/mutations/toggle-card';
  63. import { updateCardMutation } from 'graphql/mutations/update-card';
  64. import { createCardMutation } from 'graphql/mutations/create-card';
  65.  
  66.  
  67. export const resolvers = {
  68. Query: {
  69. ...cardsResolver,
  70. ...cardResolver,
  71. },
  72.  
  73. Mutation: {
  74. ...toggleCardMutation,
  75. ...updateCardMutation,
  76. ...createCardMutation, // <-- add mutation to schema
  77. },
  78. };
Add Comment
Please, Sign In to add comment