federation
federation copied to clipboard
[docs] Add __typename example to advanced entity docs
In some cases it may be useful to define an entity as a singleton. The @key directive supports the __typename meta field to declare an entity as a singleton.
In the following example, the Meta entity can be uniquely identified by its __typename (because there is only ever one instance):
type Meta @key(fields: "__typename") {
version: String!
}
I was able to confirm this works as expected in a repro: https://codesandbox.io/p/sandbox/tender-engelbart-wympgk?file=%2Ftsconfig.json%3A1%2C1
@rhino88: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/
Deploy request for apollo-federation-docs pending review.
Visit the deploys page to approve it
| Name | Link |
|---|---|
| Latest commit | cd503cc133697180da21a36b9927a0f2c2ebc2df |
⚠️ No Changeset found
Latest commit: cd503cc133697180da21a36b9927a0f2c2ebc2df
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
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.
Thanks for this @rhino88 ! The team is discussing whether this is a pattern we want to promote, we'll keep you updated.
Thanks @Meschreiber.
This is something we've found useful for a number of scenarios in production (e.g HomePage entities). The only current alternative we found would be to introduce another dummy field to use as a @key, which isn't really desirable.