Class: Types::BaseArgument

Inherits:
GraphQL::Schema::Argument
  • Object
show all
Includes:
Gitlab::Graphql::Deprecations
Defined in:
app/graphql/types/base_argument.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Graphql::Deprecations

#visible?

Constructor Details

#initialize(*args, **kwargs, &block) ⇒ BaseArgument

Returns a new instance of BaseArgument.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/graphql/types/base_argument.rb', line 9

def initialize(*args, **kwargs, &block)
  init_gitlab_deprecation(kwargs)
  @doc_reference = kwargs.delete(:see)

  # our custom addition `nullable` which allows us to declare
  # an argument that must be provided, even if its value is null.
  # When `required: true` then required arguments must not be null.
  @gl_required = !!kwargs[:required]
  @gl_nullable = kwargs[:required] == :nullable

  # Only valid if an argument is also required.
  if @gl_nullable
    # Since the framework asserts that "required" means "cannot be null"
    # we have to switch off "required" but still do the check in `ready?` behind the scenes
    kwargs[:required] = false
  end

  super(*args, **kwargs, &block)
end

Instance Attribute Details

#doc_referenceObject (readonly)

Returns the value of attribute doc_reference.



7
8
9
# File 'app/graphql/types/base_argument.rb', line 7

def doc_reference
  @doc_reference
end

Instance Method Details

#accepts?(value) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'app/graphql/types/base_argument.rb', line 29

def accepts?(value)
  # if the argument is declared as required, it must be included
  return false if @gl_required && value == :not_given
  # if the argument is declared as required, the value can only be null IF it is also nullable.
  return false if @gl_required && value.nil? && !@gl_nullable

  true
end