summaryrefslogtreecommitdiff
path: root/app/graphql/types/query_type.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2017-08-16 14:04:41 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2018-06-05 20:47:42 +0200
commit9c6c17cbcdb8bf8185fc1b873dcfd08f723e4df5 (patch)
tree624dba30e87ed0ea39afa0535d92c37c7718daef /app/graphql/types/query_type.rb
parent67dc43db2f30095cce7fe01d7f475d084be936e8 (diff)
downloadgitlab-ce-9c6c17cbcdb8bf8185fc1b873dcfd08f723e4df5.tar.gz
Add a minimal GraphQL API
Diffstat (limited to 'app/graphql/types/query_type.rb')
-rw-r--r--app/graphql/types/query_type.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb
new file mode 100644
index 00000000000..029bbd098ad
--- /dev/null
+++ b/app/graphql/types/query_type.rb
@@ -0,0 +1,38 @@
+Types::QueryType = GraphQL::ObjectType.define do
+ name 'Query'
+
+ field :project, Types::ProjectType do
+ argument :full_path, !types.ID do
+ description 'The full path of the project, e.g., "gitlab-org/gitlab-ce"'
+ end
+
+ authorize :read_project
+
+ resolve Loaders::FullPathLoader[:project]
+ end
+
+ field :merge_request, Types::MergeRequestType do
+ argument :project, !types.ID do
+ description 'The full path of the target project, e.g., "gitlab-org/gitlab-ce"'
+ end
+
+ argument :iid, !types.ID do
+ description 'The IID of the merge request, e.g., "1"'
+ end
+
+ authorize :read_merge_request
+
+ resolve Loaders::IidLoader[:merge_request]
+ end
+
+ # Testing endpoint to validate the API with
+ field :echo, types.String do
+ argument :text, types.String
+
+ resolve -> (obj, args, ctx) do
+ username = ctx[:current_user]&.username
+
+ "#{username.inspect} says: #{args[:text]}"
+ end
+ end
+end