plugin.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const gql = require('graphql-tag')
  2. // Subs
  3. const channels = require('../channels')
  4. // Connectors
  5. const cwd = require('../connectors/cwd')
  6. const plugins = require('../connectors/plugins')
  7. const dependencies = require('../connectors/dependencies')
  8. exports.types = gql`
  9. extend type Query {
  10. pluginInstallation: PluginInstallation
  11. plugins: [Plugin]
  12. plugin (id: ID!): Plugin
  13. }
  14. extend type Mutation {
  15. pluginInstall (id: ID!): PluginInstallation
  16. pluginInstallLocal: PluginInstallation
  17. pluginUninstall (id: ID!): PluginInstallation
  18. pluginInvoke (id: ID!): PluginInstallation
  19. pluginFinishInstall: PluginInstallation
  20. pluginUpdate (id: ID!, full: Boolean = true): Plugin
  21. pluginActionCall (id: ID!, params: JSON): PluginActionResult
  22. pluginsUpdate: [Plugin]
  23. pluginResetApi: Boolean
  24. }
  25. extend type Subscription {
  26. pluginActionCalled: PluginActionCall
  27. pluginActionResolved: PluginActionResult
  28. }
  29. type Plugin {
  30. id: ID!
  31. version: Version!
  32. official: Boolean
  33. installed: Boolean
  34. website: String
  35. description: String
  36. githubStats: GitHubStats
  37. logo: String
  38. }
  39. type PluginInstallation {
  40. id: ID!
  41. pluginId: ID
  42. step: PluginInstallationStep
  43. prompts: [Prompt]
  44. }
  45. enum PluginInstallationStep {
  46. install
  47. uninstall
  48. config
  49. diff
  50. }
  51. type PluginActionCall {
  52. id: ID!
  53. params: JSON
  54. }
  55. type PluginActionResult {
  56. id: ID!
  57. params: JSON
  58. results: [JSON]
  59. errors: [JSON]
  60. }
  61. `
  62. exports.resolvers = {
  63. Plugin: {
  64. version: (plugin, args, context) => dependencies.getVersion(plugin, context),
  65. description: (plugin, args, context) => dependencies.getDescription(plugin, context),
  66. logo: (plugin, args, context) => plugins.getLogo(plugin, context)
  67. },
  68. Query: {
  69. pluginInstallation: (root, args, context) => plugins.getInstallation(context),
  70. plugins: (root, args, context) => plugins.list(cwd.get(), context),
  71. plugin: (root, { id }, context) => plugins.findOne({ id, file: cwd.get() }, context)
  72. },
  73. Mutation: {
  74. pluginInstall: (root, { id }, context) => plugins.install(id, context),
  75. pluginInstallLocal: (root, args, context) => plugins.installLocal(context),
  76. pluginUninstall: (root, { id }, context) => plugins.uninstall(id, context),
  77. pluginInvoke: (root, { id }, context) => plugins.runInvoke(id, context),
  78. pluginFinishInstall: (root, args, context) => plugins.finishInstall(context),
  79. pluginUpdate: (root, { id, full }, context) => plugins.update({ id, full }, context),
  80. pluginActionCall: (root, args, context) => plugins.callAction(args, context),
  81. pluginsUpdate: (root, args, context) => plugins.updateAll(context),
  82. pluginResetApi: (root, args, context) => plugins.resetPluginApi({ file: cwd.get() }, context)
  83. },
  84. Subscription: {
  85. pluginActionCalled: {
  86. subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.PLUGIN_ACTION_CALLED)
  87. },
  88. pluginActionResolved: {
  89. subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.PLUGIN_ACTION_RESOLVED)
  90. }
  91. }
  92. }