Skip to content

fix: handle directive conditions on fragments when building query graphs#2875

Merged
dariuszkuc merged 6 commits intomainfrom
fragments_with_directives
Dec 5, 2023
Merged

fix: handle directive conditions on fragments when building query graphs#2875
dariuszkuc merged 6 commits intomainfrom
fragments_with_directives

Conversation

@dariuszkuc
Copy link
Member

@dariuszkuc dariuszkuc commented Dec 5, 2023

This PR addresses issues with handling fragments when they specify directive conditions:

  • when exploding the types we were not propagating directive conditions
  • when processing fragment that specifies super type of an existing type and also specifies directive condition, we were incorrectly preserving the unnecessary type condition. This type condition was problematic as it could be referencing types from supergraph that were not available in the local schema. Instead, we now drop the redundant type condition and only preserve the directives (if specified).

Related:

@dariuszkuc dariuszkuc requested a review from a team as a code owner December 5, 2023 00:50
@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2023

🦋 Changeset detected

Latest commit: 5077c5c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@apollo/query-graphs Patch
@apollo/composition Patch
@apollo/query-planner Patch
@apollo/gateway Patch
@apollo/federation-internals Patch
@apollo/subgraph Patch
apollo-federation-integration-testsuite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Dec 5, 2023

Deploy Preview for apollo-federation-docs canceled.

Name Link
🔨 Latest commit 5077c5c
🔍 Latest deploy log https://app.netlify.com/sites/apollo-federation-docs/deploys/656f80ee335f96000897a172

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 5, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

… query graphs

This PR addresses issues with handling fragments when they specify directive conditions:
* when exploding the types we were not propagating directive conditions
* when processing fragment that specifies super type of an existing type and also specifies directive condition, we were incorrectly preserving the unnecessary type condition. This type condition was problematic as it could be referecing types from supergraph that were not available in the local schema. Instead, we now drop the redundant type condition and only preserve the directives (if specified).

Related:
* fixes #2862
* supersedes #2864
@dariuszkuc dariuszkuc force-pushed the fragments_with_directives branch from b086574 to 0f7283d Compare December 5, 2023 19:50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a dumb question, but how do we restrict the types that the directive can be assigned to in the query? I assume the answer is "you can't"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK you can only specify the locations so you cannot restrict it by types. Guessing you would need some external linter/validation logic to enforce it by type.

dariuszkuc and others added 2 commits December 5, 2023 13:57
Co-authored-by: Chris Lenfest <clenfest@apollographql.com>
@dariuszkuc dariuszkuc enabled auto-merge (squash) December 5, 2023 19:59
@dariuszkuc dariuszkuc merged commit 3f7392b into main Dec 5, 2023
@dariuszkuc dariuszkuc deleted the fragments_with_directives branch December 5, 2023 20:02
This was referenced Dec 5, 2023
dariuszkuc pushed a commit that referenced this pull request Dec 11, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @apollo/composition@2.6.2

### Patch Changes

- Updated dependencies
\[[`7b5b836d15247c997712a47847f603aa5887312e`](7b5b836),
[`74ca7dd617927a20d79b824851f7651ef3c40a4e`](74ca7dd),
[`3f7392b84f8b626b248b59ce81f193d0f0272045`](3f7392b)]:
    -   @apollo/federation-internals@2.6.2
    -   @apollo/query-graphs@2.6.2

## @apollo/gateway@2.6.2

### Patch Changes

- Updated dependencies
\[[`7b5b836d15247c997712a47847f603aa5887312e`](7b5b836),
[`74ca7dd617927a20d79b824851f7651ef3c40a4e`](74ca7dd),
[`ffe67dfbdb77d15dde2ab6dee66dba05c7b5c037`](ffe67df)]:
    -   @apollo/federation-internals@2.6.2
    -   @apollo/query-planner@2.6.2
    -   @apollo/composition@2.6.2

## @apollo/federation-internals@2.6.2

### Patch Changes

- Avoid `>=` comparison for `FeatureVersion` objects
([#2883](#2883))

- Fix query planning bug where `__typename` on interface object types in
named fragments can cause query plan execution to fail.
([#2886](#2886))
([#2886](#2886))

## @apollo/query-graphs@2.6.2

### Patch Changes

- fix: handle directive conditions on fragments when building query
graphs ([#2875](#2875))

This fix addresses issues with handling fragments when they specify
directive conditions:

- when exploding the types we were not propagating directive conditions
- when processing fragment that specifies super type of an existing type
and also specifies directive condition, we were incorrectly preserving
the unnecessary type condition. This type condition was problematic as
it could be referencing types from supergraph that were not available in
the local schema. Instead, we now drop the redundant type condition and
only preserve the directives (if specified).

- Updated dependencies
\[[`7b5b836d15247c997712a47847f603aa5887312e`](7b5b836),
[`74ca7dd617927a20d79b824851f7651ef3c40a4e`](74ca7dd)]:
    -   @apollo/federation-internals@2.6.2

## @apollo/query-planner@2.6.2

### Patch Changes

- Add a limit to the number of options for a selection. In some cases,
we will generate a lot of possible paths to access a field. There is a
process to remove redundant paths, but when the list is too large, that
process gets very expensive. To prevent that, we introduce an optional
limit that will reject the query if too many paths are generated
([#2880](#2880))

- Updated dependencies
\[[`7b5b836d15247c997712a47847f603aa5887312e`](7b5b836),
[`74ca7dd617927a20d79b824851f7651ef3c40a4e`](74ca7dd),
[`3f7392b84f8b626b248b59ce81f193d0f0272045`](3f7392b)]:
    -   @apollo/federation-internals@2.6.2
    -   @apollo/query-graphs@2.6.2

## @apollo/subgraph@2.6.2

### Patch Changes

- Updated dependencies
\[[`7b5b836d15247c997712a47847f603aa5887312e`](7b5b836),
[`74ca7dd617927a20d79b824851f7651ef3c40a4e`](74ca7dd)]:
    -   @apollo/federation-internals@2.6.2

## apollo-federation-integration-testsuite@2.6.2

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build Plan failure when using fragments and @include

2 participants