dependency.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const gql = require('graphql-tag')
  2. // Connectors
  3. const cwd = require('../connectors/cwd')
  4. const dependencies = require('../connectors/dependencies')
  5. exports.types = gql`
  6. extend type Query {
  7. dependencies: [Dependency]
  8. dependency (id: ID!): Dependency
  9. }
  10. extend type Mutation {
  11. dependencyInstall (input: DependencyInstall!): Dependency
  12. dependencyUninstall (input: DependencyUninstall!): Dependency
  13. dependencyUpdate (input: DependencyUpdate!): Dependency
  14. dependenciesUpdate: [Dependency]
  15. }
  16. type Dependency {
  17. id: ID!
  18. type: DependencyType!
  19. version: Version!
  20. installed: Boolean
  21. website: String
  22. description: String
  23. githubStats: GitHubStats
  24. }
  25. enum DependencyType {
  26. dependencies
  27. devDependencies
  28. }
  29. input DependencyInstall {
  30. id: ID!
  31. type: DependencyType!
  32. range: String
  33. }
  34. input DependencyUninstall {
  35. id: ID!
  36. }
  37. input DependencyUpdate {
  38. id: ID!
  39. }
  40. `
  41. exports.resolvers = {
  42. Dependency: {
  43. version: (dependency, args, context) => dependencies.getVersion(dependency, context),
  44. description: (dependency, args, context) => dependencies.getDescription(dependency, context)
  45. },
  46. Query: {
  47. dependencies: (root, args, context) => dependencies.list(cwd.get(), context),
  48. dependency: (root, { id }, context) => dependencies.findOne(id, context)
  49. },
  50. Mutation: {
  51. dependencyInstall: (root, { input }, context) => dependencies.install(input, context),
  52. dependencyUninstall: (root, { input }, context) => dependencies.uninstall(input, context),
  53. dependencyUpdate: (root, { input }, context) => dependencies.update(input, context),
  54. dependenciesUpdate: (root, args, context) => dependencies.updateAll(context)
  55. }
  56. }