widget.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const gql = require('graphql-tag')
  2. // Connectors
  3. const widgets = require('../connectors/widgets')
  4. exports.types = gql`
  5. extend type Query {
  6. widgetDefinitions: [WidgetDefinition]
  7. widgets: [Widget]
  8. }
  9. extend type Mutation {
  10. widgetAdd (input: WidgetAddInput!): Widget!
  11. widgetRemove (id: ID!): Widget
  12. widgetMove (input: WidgetMoveInput!): [Widget]!
  13. widgetConfigOpen (id: ID!): Widget!
  14. widgetConfigSave (id: ID!): Widget!
  15. widgetConfigReset (id: ID!): Widget!
  16. }
  17. type WidgetDefinition {
  18. id: ID!
  19. title: String!
  20. description: String
  21. longDescription: String
  22. link: String
  23. icon: String
  24. screenshot: String
  25. component: String!
  26. detailsComponent: String
  27. canAddMore: Boolean!
  28. hasConfigPrompts: Boolean!
  29. count: Int!
  30. maxCount: Int
  31. minWidth: Int!
  32. minHeight: Int!
  33. maxWidth: Int!
  34. maxHeight: Int!
  35. openDetailsButton: Boolean
  36. }
  37. type Widget {
  38. id: ID!
  39. definition: WidgetDefinition!
  40. x: Int!
  41. y: Int!
  42. width: Int!
  43. height: Int!
  44. prompts: [Prompt]
  45. config: JSON
  46. configured: Boolean!
  47. }
  48. input WidgetAddInput {
  49. definitionId: ID!
  50. }
  51. input WidgetMoveInput {
  52. id: ID!
  53. x: Int
  54. y: Int
  55. width: Int
  56. height: Int
  57. }
  58. `
  59. exports.resolvers = {
  60. WidgetDefinition: {
  61. canAddMore: (definition, args, context) => widgets.canAddMore(definition, context),
  62. count: (definition, args, context) => widgets.getCount(definition.id)
  63. },
  64. Widget: {
  65. definition: (widget, args, context) => widgets.findDefinition(widget, context),
  66. prompts: (widget, args, context) => widgets.getConfigPrompts(widget, context)
  67. },
  68. Query: {
  69. widgetDefinitions: (root, args, context) => widgets.listDefinitions(context),
  70. widgets: (root, args, context) => widgets.list(context)
  71. },
  72. Mutation: {
  73. widgetAdd: (root, { input }, context) => widgets.add(input, context),
  74. widgetRemove: (root, { id }, context) => widgets.remove({ id }, context),
  75. widgetMove: (root, { input }, context) => widgets.move(input, context),
  76. widgetConfigOpen: (root, { id }, context) => widgets.openConfig({ id }, context),
  77. widgetConfigSave: (root, { id }, context) => widgets.saveConfig({ id }, context),
  78. widgetConfigReset: (root, { id }, context) => widgets.resetConfig({ id }, context)
  79. }
  80. }