configuration.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const gql = require('graphql-tag')
  2. // Connectors
  3. const cwd = require('../connectors/cwd')
  4. const configurations = require('../connectors/configurations')
  5. const plugins = require('../connectors/plugins')
  6. exports.types = gql`
  7. extend type Query {
  8. configurations: [Configuration]
  9. configuration (id: ID!): Configuration
  10. }
  11. extend type Mutation {
  12. configurationSave (id: ID!): Configuration
  13. configurationCancel (id: ID!): Configuration
  14. }
  15. type Configuration implements DescribedEntity {
  16. id: ID!
  17. name: String!
  18. description: String
  19. link: String
  20. icon: String
  21. plugin: Plugin
  22. tabs: [ConfigurationTab]!
  23. }
  24. type ConfigurationTab {
  25. id: ID!
  26. label: String!
  27. icon: String
  28. prompts: [Prompt]
  29. }
  30. `
  31. exports.resolvers = {
  32. Configuration: {
  33. tabs: (configuration, args, context) => configurations.getPromptTabs(configuration.id, context),
  34. plugin: (configuration, args, context) => plugins.findOne({ id: configuration.pluginId, file: cwd.get() }, context)
  35. },
  36. Query: {
  37. configurations: (root, args, context) => configurations.list(context),
  38. configuration: (root, { id }, context) => configurations.findOne(id, context)
  39. },
  40. Mutation: {
  41. configurationSave: (root, { id }, context) => configurations.save(id, context),
  42. configurationCancel: (root, { id }, context) => configurations.cancel(id, context)
  43. }
  44. }