summaryrefslogtreecommitdiff
path: root/app/graphql
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2019-05-22 12:43:35 +0100
committerPhil Hughes <me@iamphill.com>2019-05-22 12:43:35 +0100
commit67a50861953be9347e267795a9ce736dfea5316b (patch)
treeb9546274a629204b8c2ae9a60c5da70ae3a06ba7 /app/graphql
parentc841c8771b8d69034c1ceb6e452746d193865cb0 (diff)
downloadgitlab-ce-67a50861953be9347e267795a9ce736dfea5316b.tar.gz
Added repository files to GraphQL API
Diffstat (limited to 'app/graphql')
-rw-r--r--app/graphql/resolvers/tree_resolver.rb26
-rw-r--r--app/graphql/types/project_type.rb2
-rw-r--r--app/graphql/types/repository_type.rb14
-rw-r--r--app/graphql/types/tree/blob_type.rb10
-rw-r--r--app/graphql/types/tree/entry_type.rb14
-rw-r--r--app/graphql/types/tree/submodule_type.rb10
-rw-r--r--app/graphql/types/tree/tree_entry_type.rb11
-rw-r--r--app/graphql/types/tree/tree_type.rb12
-rw-r--r--app/graphql/types/tree/type_enum.rb14
9 files changed, 113 insertions, 0 deletions
diff --git a/app/graphql/resolvers/tree_resolver.rb b/app/graphql/resolvers/tree_resolver.rb
new file mode 100644
index 00000000000..5aad1c71b40
--- /dev/null
+++ b/app/graphql/resolvers/tree_resolver.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module Resolvers
+ class TreeResolver < BaseResolver
+ argument :path, GraphQL::STRING_TYPE,
+ required: false,
+ default_value: '',
+ description: 'The path to get the tree for. Default value is the root of the repository'
+ argument :ref, GraphQL::STRING_TYPE,
+ required: false,
+ default_value: :head,
+ description: 'The commit ref to get the tree for. Default value is HEAD'
+ argument :recursive, GraphQL::BOOLEAN_TYPE,
+ required: false,
+ default_value: false,
+ description: 'Used to get a recursive tree. Default is false'
+
+ alias_method :repository, :object
+
+ def resolve(**args)
+ return unless repository.exists?
+
+ repository.tree(args[:ref], args[:path], recursive: args[:recursive])
+ end
+ end
+end
diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb
index baea6658e05..06a1aab09f6 100644
--- a/app/graphql/types/project_type.rb
+++ b/app/graphql/types/project_type.rb
@@ -69,6 +69,8 @@ module Types
field :namespace, Types::NamespaceType, null: false
field :group, Types::GroupType, null: true
+ field :repository, Types::RepositoryType, null: false
+
field :merge_requests,
Types::MergeRequestType.connection_type,
null: true,
diff --git a/app/graphql/types/repository_type.rb b/app/graphql/types/repository_type.rb
new file mode 100644
index 00000000000..5987467e1ea
--- /dev/null
+++ b/app/graphql/types/repository_type.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Types
+ class RepositoryType < BaseObject
+ graphql_name 'Repository'
+
+ authorize :download_code
+
+ field :root_ref, GraphQL::STRING_TYPE, null: true
+ field :empty, GraphQL::BOOLEAN_TYPE, null: false, method: :empty?
+ field :exists, GraphQL::BOOLEAN_TYPE, null: false, method: :exists?
+ field :tree, Types::Tree::TreeType, null: true, resolver: Resolvers::TreeResolver
+ end
+end
diff --git a/app/graphql/types/tree/blob_type.rb b/app/graphql/types/tree/blob_type.rb
new file mode 100644
index 00000000000..230624201b0
--- /dev/null
+++ b/app/graphql/types/tree/blob_type.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+module Types
+ module Tree
+ class BlobType < BaseObject
+ implements Types::Tree::EntryType
+
+ graphql_name 'Blob'
+ end
+ end
+end
diff --git a/app/graphql/types/tree/entry_type.rb b/app/graphql/types/tree/entry_type.rb
new file mode 100644
index 00000000000..d8e8642ddb8
--- /dev/null
+++ b/app/graphql/types/tree/entry_type.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+module Types
+ module Tree
+ module EntryType
+ include Types::BaseInterface
+
+ field :id, GraphQL::ID_TYPE, null: false
+ field :name, GraphQL::STRING_TYPE, null: false
+ field :type, Tree::TypeEnum, null: false
+ field :path, GraphQL::STRING_TYPE, null: false
+ field :flat_path, GraphQL::STRING_TYPE, null: false
+ end
+ end
+end
diff --git a/app/graphql/types/tree/submodule_type.rb b/app/graphql/types/tree/submodule_type.rb
new file mode 100644
index 00000000000..cea76dbfd2a
--- /dev/null
+++ b/app/graphql/types/tree/submodule_type.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+module Types
+ module Tree
+ class SubmoduleType < BaseObject
+ implements Types::Tree::EntryType
+
+ graphql_name 'Submodule'
+ end
+ end
+end
diff --git a/app/graphql/types/tree/tree_entry_type.rb b/app/graphql/types/tree/tree_entry_type.rb
new file mode 100644
index 00000000000..d5cfb898aea
--- /dev/null
+++ b/app/graphql/types/tree/tree_entry_type.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+module Types
+ module Tree
+ class TreeEntryType < BaseObject
+ implements Types::Tree::EntryType
+
+ graphql_name 'TreeEntry'
+ description 'Represents a directory'
+ end
+ end
+end
diff --git a/app/graphql/types/tree/tree_type.rb b/app/graphql/types/tree/tree_type.rb
new file mode 100644
index 00000000000..1eb6c43972e
--- /dev/null
+++ b/app/graphql/types/tree/tree_type.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+module Types
+ module Tree
+ class TreeType < BaseObject
+ graphql_name 'Tree'
+
+ field :trees, Types::Tree::TreeEntryType.connection_type, null: false
+ field :submodules, Types::Tree::SubmoduleType.connection_type, null: false
+ field :blobs, Types::Tree::BlobType.connection_type, null: false
+ end
+ end
+end
diff --git a/app/graphql/types/tree/type_enum.rb b/app/graphql/types/tree/type_enum.rb
new file mode 100644
index 00000000000..6560d91e9e5
--- /dev/null
+++ b/app/graphql/types/tree/type_enum.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Types
+ module Tree
+ class TypeEnum < BaseEnum
+ graphql_name 'EntryType'
+ description 'Type of a tree entry'
+
+ value 'tree', value: :tree
+ value 'blob', value: :blob
+ value 'commit', value: :commit
+ end
+ end
+end