-
Couldn't load subscription status.
- Fork 25
Automatic Global Object Identification #1232
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
Open
enisdenjo
wants to merge
44
commits into
main
Choose a base branch
from
global-object-identification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
8618e06
bigan
enisdenjo 9871737
begin
enisdenjo 1380a58
start setting up tests
enisdenjo bb9ad3a
lets try node froid
enisdenjo 09b9ce6
global object ident
enisdenjo 696e55a
revert getstitched
enisdenjo 4ca1d97
begin
enisdenjo 992a6d7
schema with node
enisdenjo 23f0c36
point to graphql org
enisdenjo 80dede9
unused
enisdenjo 2e5e663
resolve basic person hardcoded
enisdenjo 1a0a0d1
progress progress
enisdenjo f8c5400
handle multiple fields keys
enisdenjo 9904c23
people
enisdenjo a092309
test for nodeid
enisdenjo a3e6c23
resolve nodeId
enisdenjo c52d431
accounts
enisdenjo a074530
multiple fields key
enisdenjo 07fcd8a
use additional resolvers, better
enisdenjo b5cdb7c
handle remainders
enisdenjo 5ec5fbf
batch deleg
enisdenjo 55c410f
option
enisdenjo bff6b2b
merge resolvers
enisdenjo 2a0ff27
global object ident e2e
enisdenjo c77d0ea
specify return type
enisdenjo c3c5449
resolve from other subgraphs too
enisdenjo d9d5509
correct returntype
enisdenjo 6f0c11a
changeseet
enisdenjo 64f3817
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] b35033b
resolve func
enisdenjo b5cbb77
node id without dependant fields
enisdenjo 44f4a9a
add graphl
enisdenjo db46408
no generator
enisdenjo d865803
properly merge resolvers
enisdenjo bd7834d
simpler lol
enisdenjo e7e9e64
improve tests
enisdenjo 3ecd0fa
interfaces should implement node too
enisdenjo 96e0a18
improvements
enisdenjo 68b99cb
interface support
enisdenjo ac30464
configurable
enisdenjo 1561952
nodeidfield in args
enisdenjo 1cf5266
no Query.nodes for now
enisdenjo 2d32ff6
configurable from/to id
enisdenjo 528b9ad
no node collision
enisdenjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@graphql-tools/federation': patch | ||
| --- | ||
|
|
||
| dependencies updates: | ||
|
|
||
| - Added dependency [`@graphql-tools/batch-delegate@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/batch-delegate/v/workspace:^) (to `dependencies`) | ||
| - Added dependency [`graphql-relay@^0.10.2` ↗︎](https://www.npmjs.com/package/graphql-relay/v/0.10.2) (to `dependencies`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --- | ||
| '@graphql-mesh/fusion-runtime': minor | ||
| '@graphql-tools/federation': minor | ||
| '@graphql-hive/gateway-runtime': minor | ||
| --- | ||
|
|
||
| Automatic Global Object Identification | ||
|
|
||
| Setting the `globalObjectIdentification` option to true will automatically implement the | ||
| GraphQL Global Object Identification Specification by adding a `Node` interface and `node(id: ID!): Node` field to the `Query` type. | ||
|
|
||
| The `Node` interface will have a `nodeId` (not `id`!) field used as the global identifier. It | ||
| is intentionally not `id` to avoid collisions with existing `id` fields in subgraphs. | ||
|
|
||
| ```graphql | ||
| """ | ||
| An object with a globally unique `ID`. | ||
| """ | ||
| interface Node { | ||
| """ | ||
| A globally unique identifier. Can be used in various places throughout the system to identify this single value. | ||
| """ | ||
| nodeId: ID! | ||
| } | ||
|
|
||
| extend type Query { | ||
| """ | ||
| Fetches an object given its globally unique `ID`. | ||
| """ | ||
| node( | ||
| """ | ||
| The globally unique `ID`. | ||
| """ | ||
| nodeId: ID! | ||
| ): Node | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { defineConfig } from '@graphql-hive/gateway'; | ||
|
|
||
| export const gatewayConfig = defineConfig({ | ||
| globalObjectIdentification: true, | ||
| }); |
55 changes: 55 additions & 0 deletions
55
e2e/global-object-identification/global-object-identification.e2e.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { createExampleSetup, createTenv } from '@internal/e2e'; | ||
| import { toGlobalId } from 'graphql-relay'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| const { gateway } = createTenv(__dirname); | ||
| const { supergraph, query, result } = createExampleSetup(__dirname); | ||
|
|
||
| it('should execute as usual', async () => { | ||
| const { execute } = await gateway({ | ||
| supergraph: await supergraph(), | ||
| }); | ||
| await expect( | ||
| execute({ | ||
| query, | ||
| }), | ||
| ).resolves.toEqual(result); | ||
| }); | ||
|
|
||
| it('should find objects through node', async () => { | ||
| const { execute } = await gateway({ | ||
| supergraph: await supergraph(), | ||
| }); | ||
| await expect( | ||
| execute({ | ||
| query: /* GraphQL */ ` | ||
| query ($nodeId: ID!) { | ||
| node(nodeId: $nodeId) { | ||
| ... on Product { | ||
| nodeId | ||
| upc | ||
| name | ||
| price | ||
| weight | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| variables: { | ||
| nodeId: toGlobalId('Product', '2'), | ||
| }, | ||
| }), | ||
| ).resolves.toMatchInlineSnapshot(` | ||
| { | ||
| "data": { | ||
| "node": { | ||
| "name": "Couch", | ||
| "nodeId": "UHJvZHVjdDoy", | ||
| "price": 1299, | ||
| "upc": "2", | ||
| "weight": 1000, | ||
| }, | ||
| }, | ||
| } | ||
| `); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "name": "@e2e/global-object-identification", | ||
| "private": true, | ||
| "dependencies": { | ||
| "graphql": "^16.11.0", | ||
| "graphql-relay": "^0.10.2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.