Commit 3adfa65f authored by Alex Kalderimis's avatar Alex Kalderimis

Explain what to do if our assumptions are violated

This adds a message to the developer on what to do if the (currently)
impossible occurs.
parent efb2e735
...@@ -13,6 +13,16 @@ module Gitlab ...@@ -13,6 +13,16 @@ module Gitlab
# are guarded with an assertion that our assumptions are not violated. # are guarded with an assertion that our assumptions are not violated.
ViolatedAssumption = Class.new(StandardError) ViolatedAssumption = Class.new(StandardError)
SUGGESTED_ACTION = <<~MSG
We expect it to be impossible to violate our assumptions about
how mutation arguments work.
If that is not the case, then something has probably changed in the
way we generate our schema, perhaps in the library we use: graphql-ruby
Please ask for help in the #f_graphql or #backend channels.
MSG
CONNECTION_ARGS = %w[after before first last].to_set CONNECTION_ARGS = %w[after before first last].to_set
FIELD_HEADER = <<~MD FIELD_HEADER = <<~MD
...@@ -150,12 +160,12 @@ module Gitlab ...@@ -150,12 +160,12 @@ module Gitlab
input = inputs.first input = inputs.first
name = t[:name] name = t[:name]
raise ViolatedAssumption, "Expected exactly 1 input field named #{name}. Found #{inputs.count} instead." unless inputs.one? assert!(inputs.one?, "Expected exactly 1 input field named #{name}. Found #{inputs.count} instead.")
raise ViolatedAssumption, "Expected the input of #{name} to be named 'input'" if input[:name] != 'input' assert!(input[:name] == 'input', "Expected the input of #{name} to be named 'input'")
input_type_name = input[:type][:name] input_type_name = input[:type][:name]
input_type = graphql_input_object_types.find { |t| t[:name] == input_type_name } input_type = graphql_input_object_types.find { |t| t[:name] == input_type_name }
raise ViolatedAssumption, "Cannot find #{input_type_name}" unless input_type assert!(input_type.present?, "Cannot find #{input_type_name} for #{name}.input")
arguments = input_type[:input_fields] arguments = input_type[:input_fields]
seen_type!(input_type_name) seen_type!(input_type_name)
...@@ -391,6 +401,10 @@ module Gitlab ...@@ -391,6 +401,10 @@ module Gitlab
mapping.compact mapping.compact
end end
end end
def assert!(claim, message)
raise ViolatedAssumption, "#{message}\n#{SUGGESTED_ACTION}" unless claim
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment