project.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. const gql = require('graphql-tag')
  2. // Connectors
  3. const projects = require('../connectors/projects')
  4. const plugins = require('../connectors/plugins')
  5. const tasks = require('../connectors/tasks')
  6. exports.types = gql`
  7. extend type Query {
  8. projects: [Project]
  9. projectCurrent: Project
  10. projectCreation: ProjectCreation
  11. }
  12. extend type Mutation {
  13. projectInitCreation: ProjectCreation
  14. projectCancelCreation: Boolean
  15. projectCreate (input: ProjectCreateInput!): Project!
  16. projectImport (input: ProjectImportInput!): Project!
  17. projectOpen (id: ID!): Project!
  18. projectRemove (id: ID!): Boolean!
  19. projectCwdReset: String
  20. projectSetFavorite (id: ID!, favorite: Int!): Project!
  21. projectRename (id: ID!, name: String!): Project!
  22. presetApply (id: ID!): ProjectCreation
  23. featureSetEnabled (id: ID!, enabled: Boolean): Feature
  24. }
  25. type Project {
  26. id: ID!
  27. name: String!
  28. type: ProjectType
  29. path: String!
  30. favorite: Int
  31. plugins: [Plugin]
  32. tasks: [Task]
  33. homepage: String
  34. openDate: JSON
  35. }
  36. enum ProjectType {
  37. vue
  38. unknown
  39. }
  40. input ProjectCreateInput {
  41. folder: String!
  42. force: Boolean!
  43. bare: Boolean!
  44. packageManager: PackageManager
  45. preset: String!
  46. remote: String
  47. clone: Boolean
  48. save: String
  49. enableGit: Boolean!
  50. gitCommitMessage: String
  51. }
  52. input ProjectImportInput {
  53. path: String!
  54. force: Boolean
  55. }
  56. type Preset implements DescribedEntity {
  57. id: ID!
  58. name: String
  59. description: String
  60. link: String
  61. features: [String]
  62. }
  63. type ProjectCreation {
  64. presets: [Preset]
  65. features: [Feature]
  66. prompts: [Prompt]
  67. }
  68. type Feature implements DescribedEntity {
  69. id: ID!
  70. name: String
  71. description: String
  72. link: String
  73. enabled: Boolean!
  74. }
  75. `
  76. exports.resolvers = {
  77. Project: {
  78. type: (project, args, context) => projects.getType(project, context),
  79. plugins: (project, args, context) => plugins.list(project.path, context),
  80. tasks: (project, args, context) => tasks.list({ file: project.path }, context),
  81. homepage: (project, args, context) => projects.getHomepage(project, context)
  82. },
  83. Query: {
  84. projects: (root, args, context) => projects.list(context),
  85. projectCurrent: (root, args, context) => projects.getCurrent(context),
  86. projectCreation: (root, args, context) => projects.getCreation(context)
  87. },
  88. Mutation: {
  89. projectInitCreation: (root, args, context) => projects.initCreator(context),
  90. projectCancelCreation: (root, args, context) => projects.removeCreator(context),
  91. projectCreate: (root, { input }, context) => projects.create(input, context),
  92. projectImport: (root, { input }, context) => projects.import(input, context),
  93. projectOpen: (root, { id }, context) => projects.open(id, context),
  94. projectRemove: (root, { id }, context) => projects.remove(id, context),
  95. projectCwdReset: (root, args, context) => projects.resetCwd(context),
  96. projectSetFavorite: (root, args, context) => projects.setFavorite(args, context),
  97. projectRename: (root, args, context) => projects.rename(args, context),
  98. presetApply: (root, { id }, context) => projects.applyPreset(id, context),
  99. featureSetEnabled: (root, args, context) => projects.setFeatureEnabled(args, context)
  100. }
  101. }