Skip to content

v0.19.3.0

Choose a tag to compare

@github-actions github-actions released this 20 Jun 16:30
· 574 commits to main since this release

ElasticGraph v0.19.3.0 has been released! This release includes a couple of new features, some bug fixes, and a minor breaking change.

New Feature: Field-level Custom Resolver Arguments

We added a custom GraphQL resolver API in ElasticGraph v0.19.2.0. That release allowed the same resolver class to be used with different parameters by registering it multiple times:

require(require_path = "roll_dice_resolver")
schema.register_graphql_resolver :roll_2_dice,
  RollDiceResolver,
  defined_at: require_path,
  number_of_dice: 2

schema.register_graphql_resolver :roll_3_dice,
  RollDiceResolver,
  defined_at: require_path,
  number_of_dice: 3

schema.on_root_query_type do |t|
  t.field "roll2Dice", "Int" do |f|
    f.resolve_with :roll_2_dice
  end

  t.field "roll3Dice", "Int" do |f|
    f.resolve_with :roll_3_dice
  end
end

ElasticGraph v0.19.3.0 allows you to provide these parameters at the field level when configuring a field to use a resolver:

require(require_path = "roll_dice_resolver")
schema.register_graphql_resolver :roll_dice,
  RollDiceResolver,
  defined_at: require_path

schema.on_root_query_type do |t|
  t.field "roll2Dice", "Int" do |f|
    f.resolve_with :roll_dice, number_of_dice: 2
  end

  t.field "roll3Dice", "Int" do |f|
    f.resolve_with :roll_dice, number_of_dice: 3
  end
end

Improved Apollo Federation Support

Apollo Federation provides a powerful way to combine multiple subgraphs into a single supergraph. ElasticGraph has shipped with the elasticgraph-apollo extension for a long time, which makes any ElasticGraph project plug into an Apollo supergraph as a subgraph.

However, ElasticGraph schemas haven't always lined up with Apollo federation idioms. To expose a reference to an Apollo entity, a subgraph needs to expose an entity reference containing a non-resolvable entity with just the @key fields:

type Product @key(fields: "id", resolvable: false) {
  id: ID
}

The ElasticGraph schema would then expose fields like product: Product or products: [Product!]! rather than productId: ID or productIds: [ID!]!. However, if your schema already has a productId field, migrating to the entity reference can be a significant effort, requiring clients to migrate and a backfill.

ElasticGraph v0.19.3.0 includes a new feature to help out in this situation. Here's how to use it:

# Existing field
t.field "productId", "ID"

# New field defined with the new feature
t.apollo_entity_ref_field "product", "Product", id_field_name_in_index: "productId"

This exposes a Product field backed by the productId field.

You can also use this on a collection of IDs:

# Existing field
t.field "productIds", "[ID!]!"

# New field defined with the new feature
t.apollo_entity_ref_field "products", "[Product!]!", id_field_name_in_index: "productIds"

Or, if you want to provide a paginated collection as a relay connection:

# Existing field
t.field "productIds", "[ID!]!"

# New field defined with the new feature
t.apollo_entity_ref_paginated_collection_field "products", "Product", id_field_name_in_index: "productIds"

Upgrade Notes

This release includes a minor breaking change to the custom GraphQL resolver API added in v0.19.2.0. Previously, this was the API to configure a field to use a custom resolver:

schema.on_root_query_type do |t|
  t.field "rollDice", "Int" do |f|
    f.resolver = :roll_dice
  end
end

In ElasticGraph v0.19.3.0, that's changed slightly:

schema.on_root_query_type do |t|
  t.field "rollDice", "Int" do |f|
    f.resolve_with :roll_dice
  end
end

If your project uses custom resolvers (which is not common), you'll need to update to the new API as part of upgrading ElasticGraph.

What's Changed

New Features

Breaking Changes

Bug Fixes

Other Improvements

Full Changelog: v0.19.2.2...v0.19.3.0