You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support resolver config parameters when configuring it for use.
Previously, we supported resolver parameters provided when registering
the resolver, but it's quite useful to be able to provide them when
configuring a type or field to use a resolver. This allows resolver
params to be provided in all 3 spots.
Copy file name to clipboardExpand all lines: config/site/src/guides/custom-graphql-resolvers.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ which allows you to inspect the child field selections. However, providing it im
50
50
more performant if you omit it from your `resolve` definition.
51
51
52
52
In this case, our `RollDiceResolver` simulates the rolling of the configured `number_of_dice`, each of which has a number of `sides`
53
-
provided as a query argument.
53
+
provided as a query argument. Finally, it multiplies the dice roll by a configured `multiplier`.
54
54
55
55
### Step 2: Register the Resolver
56
56
@@ -66,7 +66,13 @@ In this case, we've registered the resolver to roll two dice.
66
66
{% include copyable_code_snippet.html language="ruby" data="custom_resolver.snippets.schema_rb.on_root_query_type" %}
67
67
68
68
Here we've defined a field on `Query` using [`on_root_query_type`](/elasticgraph/api-docs/{{ site.data.doc_versions.latest_version }}/ElasticGraph/SchemaDefinition/API.html#on_root_query_type-instance_method),
69
-
and configured it to use the `:roll_dice` resolver.
69
+
and configured it to use the `:roll_dice` resolver. Extra arguments (`multiplier: 3`, in this case) will be passed to the resolver in `config`.
70
+
71
+
{: .alert-note}
72
+
**Note**{: .alert-title}
73
+
Resolver config values can be provided both when registering the resolver (via `schema.register_graphql_resolver`)
74
+
and when configuring a field to use the resolver (via `field.resolve_with`). These configuration options will be
75
+
merged together to provide `config` when instantiating the resolver.
0 commit comments