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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/graphql/types/range_input_type.rb')
-rw-r--r--app/graphql/types/range_input_type.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/graphql/types/range_input_type.rb b/app/graphql/types/range_input_type.rb
new file mode 100644
index 00000000000..766e523a99e
--- /dev/null
+++ b/app/graphql/types/range_input_type.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Types
+ # rubocop: disable Graphql/AuthorizeTypes
+ class RangeInputType < BaseInputObject
+ def self.[](type, closed = true)
+ @subtypes ||= {}
+
+ @subtypes[[type, closed]] ||= Class.new(self) do
+ argument :start, type,
+ required: closed,
+ description: 'The start of the range'
+
+ argument :end, type,
+ required: closed,
+ description: 'The end of the range'
+ end
+ end
+
+ def prepare
+ if self[:end] && self[:start] && self[:end] < self[:start]
+ raise ::Gitlab::Graphql::Errors::ArgumentError, 'start must be before end'
+ end
+
+ to_h
+ end
+ end
+ # rubocop: enable Graphql/AuthorizeTypes
+end