diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-03 12:10:53 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-03 12:10:53 +0300 |
commit | 74780f24f2005d24a0e0a8fa1b3ae5391ae2928f (patch) | |
tree | 888505246a85ff9e97042b43b18450730586596e /spec/support/graphql | |
parent | ccbe90951fb75b3527eaaad404e6abb6ed09ca8c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/graphql')
-rw-r--r-- | spec/support/graphql/resolver_factories.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/support/graphql/resolver_factories.rb b/spec/support/graphql/resolver_factories.rb new file mode 100644 index 00000000000..8188f17cc43 --- /dev/null +++ b/spec/support/graphql/resolver_factories.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module Graphql + module ResolverFactories + def new_resolver(resolved_value = 'Resolved value', method: :resolve) + case method + when :resolve + simple_resolver(resolved_value) + when :find_object + find_object_resolver(resolved_value) + else + raise "Cannot build a resolver for #{method}" + end + end + + private + + def simple_resolver(resolved_value = 'Resolved value') + Class.new(Resolvers::BaseResolver) do + define_method :resolve do |**_args| + resolved_value + end + end + end + + def find_object_resolver(resolved_value = 'Found object') + Class.new(Resolvers::BaseResolver) do + include ::Gitlab::Graphql::Authorize::AuthorizeResource + + def resolve(**args) + authorized_find!(**args) + end + + define_method :find_object do |**_args| + resolved_value + end + end + end + end +end |