view.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const gql = require('graphql-tag')
  2. // Sub
  3. const channels = require('../channels')
  4. // Connectors
  5. const views = require('../connectors/views')
  6. exports.types = gql`
  7. extend type Query {
  8. views: [View]
  9. }
  10. extend type Mutation {
  11. viewOpen (id: ID!): Boolean
  12. }
  13. extend type Subscription {
  14. viewAdded: View
  15. viewRemoved: View
  16. viewChanged: View
  17. }
  18. type View {
  19. id: ID!
  20. name: String!
  21. icon: String!
  22. tooltip: String
  23. badges: [ViewBadge]
  24. projectTypes: [ProjectType]
  25. }
  26. type ViewBadge {
  27. id: ID!
  28. type: ViewBadgeType!
  29. count: Int
  30. label: String!
  31. priority: Int!
  32. hidden: Boolean!
  33. }
  34. enum ViewBadgeType {
  35. info
  36. success
  37. warning
  38. error
  39. accent
  40. dim
  41. }
  42. `
  43. exports.resolvers = {
  44. Query: {
  45. views: (root, args, context) => views.list(context)
  46. },
  47. Mutation: {
  48. viewOpen: (root, { id }, context) => views.open(id, context)
  49. },
  50. Subscription: {
  51. viewAdded: {
  52. subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.VIEW_ADDED)
  53. },
  54. viewChanged: {
  55. subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.VIEW_CHANGED)
  56. },
  57. viewRemoved: {
  58. subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.VIEW_REMOVED)
  59. }
  60. }
  61. }