Backport apollo_entity_ref_field to pre-1.0#612
Merged
myronmarston merged 9 commits intopre-1.0from Jun 19, 2025
Merged
Conversation
…dex`. This can be used, for example, when migrating a field in an index to a new GraphQL field name. Previously, we were not able to correctly determine the mapping of the field in this case (since it's graphql-only). With this fix, we now use the mapping of the indexing field with the same name. This ensures we treat `text` and `nested` fields correctly, for example.
For a custom GraphQL resolver it can be useful to define an object
field that has a `name_in_index` of a scalar field. When a client
requests subfields of the object field, we want to request the scalar
field from the datastore. Previously, we requested non-existent
subfields.
For example, given these two fields:
```
t.field "owner_id", "ID", indexing_only: true
t.field "owner", "ComponentOwner", name_in_index: "owner_id", graphql_only: true
```
...when a client requests `owner { id }`, we want to request `owner_id`
from the datastore rather than `owner_id.id` (which does not exist, and
is what ElasticGraph did before this fix).
- Validate that an existing indexing field exists at the provided `name_in_index` since we don't define an indexing field for a `graphql_only` field and the referenced field must already exist. - Fix `backing_indexing_field` to correctly handle nested field paths. This allows us to support `graphql_only` fields with a nested `name_in_index` field path under `highlights`.
- Fix `total_edge_count` so it returns the count of the entire collection, rather than just the number of nodes on the current page. - Fix handling of `before`/`after` args, converting them to the form required by the GraphQL gem. Previously, a `NoMethodError` was thrown because the GraphQL gem expects `String` arguments but we were providing `DecodedCursor` objects.
Instead of an assignment API that looks like this:
```ruby
schema.object_type "MyType" do |t|
t.default_graphql_resolver = :my_resolver
t.field "field1", "String"
t.field "field2", "String" do |f|
f.resolver = :my_other_resolver
end
end
```
It now looks like this:
```ruby
schema.object_type "MyType" do |t|
t.resolve_fields_with :my_resolver
t.field "field1", "String"
t.field "field2", "String" do |f|
f.resolve_with :my_other_resolver
end
end
```
This is more in keeping with our other schema definition APIs (e.g.
`f.documentation "docstring" instead of `f.documentation = "docstring"`)
and paves the way for these APIs to accept additional arguments.
While this is a breaking change, now is an ideal time to break things,
in the runup to the 1.0.0 release.
This allows us to pair a `name` of a GraphQL resolver with `config`. We'll be using this in a later PR to allow GraphQL resolvers to be parameterized at the field level.
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.
…ref. When plugging into an Apollo supergraph, it's quite useful to be able to expoes "entity reference" types (e.g. a type with just an id field, that refers to an entity owned by another subgraph) rather than just exposing an id field. This allows Apollo to federate the type. This adds two new APIs to support this: * `apollo_entity_ref_field` * `apollo_entity_ref_paginated_collection_field` The latter exposes a list of ids as a paginated relay connection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains backports of the following PRs:
name_in_index. #572paginated_collection_field: support more field options. #606name_in_indexon agraphql_onlyfield. #609paginated_collection_fieldfields. #610ConfiguredGraphQLResolver. #603apollo_entity_ref_fieldto expose an id field as an entity ref. #611This is being done so that we can offer the new
apollo_entity_ref_fieldfeature in ElasticGraph 0.19.3.0.