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

Composite computed fields #5162

Merged
merged 16 commits into from
Apr 8, 2024
Merged

Conversation

asodeur
Copy link
Contributor

@asodeur asodeur commented Apr 11, 2023

Description

This is adding the ability to return non-scalar types from computed fields.

Before this a computed field of non-scalar type would always return null. Now you can do

type S {
   myComputedField: T @computed(selectionSet: "{ fieldA fieldB }")
}

where T is an enum, interface, object, or union type. T does not need to be merged type. However, all types reachable from T will be part of the isolated schema (and potentially the base schema as well).

Related #4554

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate

How Has This Been Tested?

Unit tests (eventually will need more ...)

Test Environment:

  • OS: Windows
  • @graphql-tools/stitch: 8.7.47
  • NodeJS: 18.15

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@changeset-bot
Copy link

changeset-bot bot commented Apr 11, 2023

🦋 Changeset detected

Latest commit: 3669811

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

This PR includes changesets to release 3 packages
Name Type
@graphql-tools/stitch Minor
@graphql-tools/stitching-directives Patch
federation-benchmark 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

@ardatan
Copy link
Owner

ardatan commented Apr 23, 2023

Thanks for the PR!
Is there anything we can help you to get this finished? @asodeur

@MichalLytek
Copy link
Contributor

@asodeur
Correct me if I'm wrong, but your PR adds the ability to enhance other schema types with computed fields when the return type of the computed field is not scalar but some object type (even local, not stitched)?

Like localDependentField: String! works now but otherTypeField: OtherType! does not and your PR will make it work? 😉

@asodeur
Copy link
Contributor Author

asodeur commented May 4, 2023

@MichalLytek yes, that is the plan. As is the PR works in a little in-house PoC but getting all the corner-cases to work required quite some special casing. So there is a lot of clean-up left to do.

@asodeur
Copy link
Contributor Author

asodeur commented May 25, 2023

I hope this is ready for a first round of review now. There are some areas that might need better test coverage:

  1. I am unsure how this might interact with entry points. Which scenarios, if any, would need to be covered here?
  2. do we need to test how circular dependencies among computed fields would behave? Not sure if these can be created in the first place and what would happen.
  3. any other omissions in the test coverage?

@asodeur asodeur marked this pull request as ready for review May 25, 2023 16:37
T: {
selectionSet: '{ id }',
fieldName: 'byRepresentation',
args: ({ id, value }) => ({ representation: { id, value } }),
Copy link
Owner

Choose a reason for hiding this comment

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

How do we expect value here?
Because it is needed for next only, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, should have made clear by proper typing value is optional and will only be filled if available b/c a) value was explicitly queried, or b) the computed field was queried. Fixed the typing and added a test to show value will not be filled when it is not required.

…ot a required argument to the entry point and added a test that shows it is not provided when the computed field is not queried.
@asodeur asodeur requested a review from ardatan June 20, 2023 06:33
@ardatan ardatan merged commit 27b6f49 into ardatan:master Apr 8, 2024
27 checks passed
@theguild-bot theguild-bot mentioned this pull request May 23, 2024
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.

3 participants