Skip to content

Commit 9bdf77f

Browse files
committed
node id without dependant fields
1 parent 18afd88 commit 9bdf77f

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

packages/federation/src/globalObjectIdentification.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export function createResolvers({
154154
...resolvers,
155155
[typeName]: {
156156
[nodeIdField]: {
157+
selectionSet: `{ ${keyFieldNames.join(' ')} }`,
157158
resolve(source) {
158159
if (keyFieldNames.length === 1) {
159160
// single field key

packages/federation/tests/globalObjectIdentification.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,40 @@ describe('Global Object Identification', () => {
219219
`);
220220
});
221221

222+
it('should resolve node id without requesting key fields in client query', async () => {
223+
const schema = await getStitchedSchemaFromLocalSchemas({
224+
globalObjectIdentification: true,
225+
localSchemas: {
226+
accounts,
227+
},
228+
});
229+
230+
await expect(
231+
Promise.resolve(
232+
normalizedExecutor({
233+
schema,
234+
document: parse(/* GraphQL */ `
235+
{
236+
accounts {
237+
nodeId
238+
}
239+
}
240+
`),
241+
}),
242+
),
243+
).resolves.toMatchInlineSnapshot(`
244+
{
245+
"data": {
246+
"accounts": [
247+
{
248+
"nodeId": "QWNjb3VudDphMQ==",
249+
},
250+
],
251+
},
252+
}
253+
`);
254+
});
255+
222256
it('should not resolve single field key object from globally unique node when doesnt exist', async () => {
223257
const schema = await getStitchedSchemaFromLocalSchemas({
224258
globalObjectIdentification: true,
@@ -292,6 +326,43 @@ describe('Global Object Identification', () => {
292326
`);
293327
});
294328

329+
it('should resolve node id without requesting key fields in client query', async () => {
330+
const schema = await getStitchedSchemaFromLocalSchemas({
331+
globalObjectIdentification: true,
332+
localSchemas: {
333+
people,
334+
},
335+
});
336+
337+
await expect(
338+
Promise.resolve(
339+
normalizedExecutor({
340+
schema,
341+
document: parse(/* GraphQL */ `
342+
{
343+
people {
344+
nodeId
345+
}
346+
}
347+
`),
348+
}),
349+
),
350+
).resolves.toMatchInlineSnapshot(`
351+
{
352+
"data": {
353+
"people": [
354+
{
355+
"nodeId": "UGVyc29uOnsiZmlyc3ROYW1lIjoiSm9obiIsImxhc3ROYW1lIjoiRG9lIn0=",
356+
},
357+
{
358+
"nodeId": "UGVyc29uOnsiZmlyc3ROYW1lIjoiSmFuZSIsImxhc3ROYW1lIjoiRG9lIn0=",
359+
},
360+
],
361+
},
362+
}
363+
`);
364+
});
365+
295366
it('should resolve node id from object', async () => {
296367
const schema = await getStitchedSchemaFromLocalSchemas({
297368
globalObjectIdentification: true,

0 commit comments

Comments
 (0)