diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/support/helpers/graphql_helpers.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/support/helpers/graphql_helpers.rb')
-rw-r--r-- | spec/support/helpers/graphql_helpers.rb | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index db769041f1e..a1b4e6eee92 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -17,8 +17,8 @@ module GraphqlHelpers # ready, then the early return is returned instead. # # Then the resolve method is called. - def resolve(resolver_class, obj: nil, args: {}, ctx: {}, field: nil) - resolver = resolver_class.new(object: obj, context: ctx, field: field) + def resolve(resolver_class, args: {}, **resolver_args) + resolver = resolver_instance(resolver_class, **resolver_args) ready, early_return = sync_all { resolver.ready?(**args) } return early_return unless ready @@ -26,6 +26,15 @@ module GraphqlHelpers resolver.resolve(**args) end + def resolver_instance(resolver_class, obj: nil, ctx: {}, field: nil, schema: GitlabSchema) + if ctx.is_a?(Hash) + q = double('Query', schema: schema) + ctx = GraphQL::Query::Context.new(query: q, object: obj, values: ctx) + end + + resolver_class.new(object: obj, context: ctx, field: field) + end + # Eagerly run a loader's named resolver # (syncs any lazy values returned by resolve) def eager_resolve(resolver_class, **opts) @@ -112,6 +121,16 @@ module GraphqlHelpers end end + def resolve_field(name, object, args = {}) + context = double("Context", + schema: GitlabSchema, + query: GraphQL::Query.new(GitlabSchema), + parent: nil) + field = described_class.fields[name] + instance = described_class.authorized_new(object, context) + field.resolve_field(instance, {}, context) + end + # Recursively convert a Hash with Ruby-style keys to GraphQL fieldname-style keys # # prepare_input_for_mutation({ 'my_key' => 1 }) @@ -468,6 +487,8 @@ module GraphqlHelpers use Gitlab::Graphql::Authorize use Gitlab::Graphql::Pagination::Connections + lazy_resolve ::Gitlab::Graphql::Lazy, :force + query(query_type) end |