folder.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const gql = require('graphql-tag')
  2. // Connectors
  3. const folders = require('../connectors/folders')
  4. const cwd = require('../connectors/cwd')
  5. exports.types = gql`
  6. extend type Query {
  7. folderCurrent: Folder
  8. foldersFavorite: [Folder]
  9. folderExists (file: String!): Boolean
  10. }
  11. extend type Mutation {
  12. folderOpen (path: String!): Folder
  13. folderOpenParent: Folder
  14. folderSetFavorite (path: String!, favorite: Boolean!): Folder
  15. folderCreate(name: String!): Folder
  16. }
  17. type Folder {
  18. name: String!
  19. path: String!
  20. isPackage: Boolean
  21. isVueProject: Boolean
  22. favorite: Boolean
  23. children: [Folder]
  24. hidden: Boolean
  25. }
  26. `
  27. exports.resolvers = {
  28. Folder: {
  29. children: (folder, args, context) => folders.list(folder.path, context),
  30. isPackage: (folder, args, context) => folders.isPackage(folder.path, context),
  31. isVueProject: (folder, args, context) => folders.isVueProject(folder.path, context),
  32. favorite: (folder, args, context) => folders.isFavorite(folder.path, context)
  33. },
  34. Query: {
  35. folderCurrent: (root, args, context) => folders.getCurrent(args, context),
  36. foldersFavorite: (root, args, context) => folders.listFavorite(context),
  37. folderExists: (root, { file }, context) => folders.isDirectory(file)
  38. },
  39. Mutation: {
  40. folderOpen: (root, { path }, context) => folders.open(path, context),
  41. folderOpenParent: (root, args, context) => folders.openParent(cwd.get(), context),
  42. folderSetFavorite: (root, args, context) => folders.setFavorite({
  43. file: args.path,
  44. favorite: args.favorite
  45. }, context),
  46. folderCreate: (root, { name }, context) => folders.create(name, context)
  47. }
  48. }