Welcome to mirror list, hosted at ThFree Co, Russian Federation.

copy_field_description.rb « graphql « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ed2273bc91a398a989de93f0605c8ca285eea073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

module Gitlab
  module Graphql
    module CopyFieldDescription
      extend ActiveSupport::Concern

      class_methods do
        # Returns the `description` for property of field `field_name` on type.
        # This can be used to ensure, for example, that mutation argument descriptions
        # are always identical to the corresponding query field descriptions.
        #
        # E.g.:
        #   argument :name, GraphQL::Types::String, description: copy_field_description(Types::UserType, :name)
        def copy_field_description(type, field_name)
          type.fields[field_name.to_s.camelize(:lower)].description
        end
      end
    end
  end
end