summaryrefslogtreecommitdiff
path: root/app/graphql/types/query_type.rb
blob: 029bbd098ad05a194fc5a7a496778b3a30c996e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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