Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adds support for defining Interface entities resolvers #262

Closed
wants to merge 4 commits into from

Conversation

moonflare
Copy link
Contributor

Context

As part of the Federation v2.3 spec, the Apollo team added a new feature, to support defining and referencing Entities that are interfaces. You can read more about this here, and check the initial implementation here.

This feature consists of two parts:

  1. An Interface Entity defined in Subgraph A can be referenced from Subgraph B using the @interfaceObject directive. This work was added in feat: adds support for the @interfaceObject directive #218
  2. An Interface Entity can be defined in your subgraph. This part is missing and this is what this PR adds.

Description

  • Updates the Union validation so we can allow an interface to be a union member
    • The main issue here is the fact that an Union in GraphQL can't be an Interface according to the spec, but at the same time, according to the Apollo Federation spec, an interface can be an Entity, and an Entity is an Union. Therefore, we have to extend the validation (assert_valid_union_member) for the Entity union to allow Interfaces (more precisely Modules) as possible types.
  • Adds validation that all implementing types of an Entity Interface also have the @key directive. This is a requirement from the spec.
  • Adds underscore_reference_keys support to interfaces
    • In a previous Pull Request (feat: Optionally underscore _Any keys #248) there was added support for underscoring the keys and while this covered the Object class, it didn't also cover the Interface module. This commit adds the same underscore_reference_keys method to the Interface module.
  • Adds some docs for the Interface Entities feature support.

cc @nogates

moonflare and others added 4 commits September 8, 2023 11:25
Context: In Federation v2.3 there was added support for interfaces to be
Entities. There are two ways to consume this new feature.

1. Extend an Interface Entity with the `@interfaceObject` directive,
   when the Entity is defined by a different subgraph.

2. Implement the Interface Entity with its implementing Type Entitites.

There was previos work into getting the first part covered in this gem,
but we were still lacking support for the 2nd part. This work address
that.

The main issue here is the fact that an `Union` in `GraphQL` can't be an
`Interface` according to the [spec](https://spec.graphql.org/October2021/#sec-Unions.Type-Validation), but at the same time, according to the Apollo Federation [spec](https://www.apollographql.com/docs/federation/federated-types/interfaces), an interface can be an Entity, and an Entity is an Union. Therefore, we have to extend the validation (`assert_valid_union_member`) for the Entity union to allow `Interfaces` (more exactly `Modules`) as possible types.
In a previous Pull Request (Gusto#248) there was added support for underscoring the keys and while this covered the `Object` class, it didn't also cover the `Interface` module. This commit adds the same `underscore_reference_keys` method to the `Interface` module.
Every entity that implements an interface entity must include all `@keys` from the interface definition.
Therefore, we add this extra validation to ensure that.
@moonflare moonflare marked this pull request as ready for review September 13, 2023 06:56
@moonflare moonflare closed this Sep 13, 2023
@moonflare moonflare deleted the fix-interface-entities branch September 13, 2023 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants