suggestion.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const gql = require('graphql-tag')
  2. // Subs
  3. const channels = require('../channels')
  4. // Connectors
  5. const suggestions = require('../connectors/suggestions')
  6. exports.types = gql`
  7. extend type Query {
  8. suggestions: [Suggestion]
  9. }
  10. extend type Mutation {
  11. suggestionActivate (input: SuggestionActivate!): Suggestion
  12. }
  13. extend type Subscription {
  14. suggestionAdded: Suggestion
  15. suggestionUpdated: Suggestion
  16. suggestionRemoved: Suggestion
  17. }
  18. type Suggestion {
  19. id: ID!
  20. type: SuggestionType!
  21. importance: SuggestionImportance!
  22. label: String!
  23. image: String
  24. message: String
  25. link: String
  26. actionLink: String
  27. busy: Boolean!
  28. }
  29. enum SuggestionType {
  30. action
  31. }
  32. enum SuggestionImportance {
  33. critical
  34. important
  35. normal
  36. secondary
  37. }
  38. input SuggestionActivate {
  39. id: ID!
  40. }
  41. `
  42. exports.resolvers = {
  43. Query: {
  44. suggestions: (root, args, context) => suggestions.list(context)
  45. },
  46. Mutation: {
  47. suggestionActivate: (root, { input }, context) => suggestions.activate(input, context)
  48. },
  49. Subscription: {
  50. suggestionAdded: {
  51. subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.SUGGESTION_ADDED)
  52. },
  53. suggestionUpdated: {
  54. subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.SUGGESTION_UPDATED)
  55. },
  56. suggestionRemoved: {
  57. subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.SUGGESTION_REMOVED)
  58. }
  59. }
  60. }