Method: GraphQL::Schema::Validator::RequiredValidator#build_message

Defined in:
lib/graphql/schema/validator/required_validator.rb

#build_message(context) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/graphql/schema/validator/required_validator.rb', line 129

def build_message(context)
  argument_definitions = context.types.arguments(@validated)

  required_names = @one_of.map do |arg_keyword|
    if arg_keyword.is_a?(Array)
      names = arg_keyword.map { |arg| arg_keyword_to_graphql_name(argument_definitions, arg) }
      names.compact! # hidden arguments are `nil`
      "(" + names.join(" and ") + ")"
    else
      arg_keyword_to_graphql_name(argument_definitions, arg_keyword)
    end
  end
  required_names.compact! # remove entries for hidden arguments


  case required_names.size
  when 0
    # The required definitions were hidden from the client.
    # Another option here would be to raise an error in the application....
    "%{validated} is missing a required argument."
  when 1
    "%{validated} must include the following argument: #{required_names.first}."
  else
    "%{validated} must include exactly one of the following arguments: #{required_names.join(", ")}."
  end
end