graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Composite computed fields

Open asodeur opened this issue 2 years ago • 5 comments

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.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [x] 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:

  • [x] I have followed the CONTRIBUTING doc and the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] 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
  • [x] 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...

asodeur avatar Apr 11 '23 10:04 asodeur

🦋 Changeset detected

Latest commit: 3669811a6ecd5bb082da69d2b69fb3c315ab8a2a

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

changeset-bot[bot] avatar Apr 11 '23 10:04 changeset-bot[bot]

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

ardatan avatar Apr 23 '23 08:04 ardatan

@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? 😉

MichalLytek avatar May 04 '23 09:05 MichalLytek

@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 avatar May 04 '23 10:05 asodeur

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 avatar May 25 '23 16:05 asodeur