diff --git a/.changeset/rude-years-melt.md b/.changeset/rude-years-melt.md new file mode 100644 index 000000000..368c9fd95 --- /dev/null +++ b/.changeset/rude-years-melt.md @@ -0,0 +1,5 @@ +--- +'houdini': patch +--- + +Fix bug when inserting data into abstract list diff --git a/packages/houdini/src/codegen/transforms/lists.test.ts b/packages/houdini/src/codegen/transforms/lists.test.ts index cb4162f66..0aaca9364 100644 --- a/packages/houdini/src/codegen/transforms/lists.test.ts +++ b/packages/houdini/src/codegen/transforms/lists.test.ts @@ -479,8 +479,8 @@ test('cannot use list directive if id is not a valid field', async function () { } catch (error: unknown) { nbError++ // @ts-ignore - expect(error[0].description).toMatchInlineSnapshot( - '"@list on Legend as a configuration issue. Object identification missing: \\"id\\". Check \'Custom IDs\' if needed."' + expect(error[0].message).toMatchInlineSnapshot( + '"@list on Legend has a configuration issue: Legend dos not have a valid key. Please check this link for more information: https://houdinigraphql.com/guides/caching-data#custom-ids"' ) } expect(nbError).toBe(1) diff --git a/packages/houdini/src/codegen/validators/typeCheck.ts b/packages/houdini/src/codegen/validators/typeCheck.ts index e026e32e5..a5a0b4a10 100755 --- a/packages/houdini/src/codegen/validators/typeCheck.ts +++ b/packages/houdini/src/codegen/validators/typeCheck.ts @@ -1,4 +1,4 @@ -import { logGreen, logYellow } from '@kitql/helper' +import { logGreen } from '@kitql/helper' import * as graphql from 'graphql' import { @@ -263,16 +263,15 @@ export default async function typeCheck(config: Config, docs: Document[]): Promi .filter((fieldName) => !targetType.getFields()[fieldName]) if (missingIDFields.length > 0) { - const message = `@${config.listDirective} on ${logGreen( - targetType.name - )} as a configuration issue. Object identification missing: ${missingIDFields - .map((c) => `"${logYellow(c)}"`) - .join(', ')}. Check 'Custom IDs' if needed.` errors.push( new HoudiniError({ filepath: filename, - message, - description: message, + message: + `@${config.listDirective} on ${logGreen( + targetType.name + )} has a configuration issue: ` + + `${targetType} dos not have a valid key. ` + + `Please check this link for more information: https://houdinigraphql.com/guides/caching-data#custom-ids`, }) ) return diff --git a/packages/houdini/src/runtime/cache/lists.ts b/packages/houdini/src/runtime/cache/lists.ts index 957d8e01a..9e4edbf3b 100644 --- a/packages/houdini/src/runtime/cache/lists.ts +++ b/packages/houdini/src/runtime/cache/lists.ts @@ -260,6 +260,10 @@ export class List { updates: ['append', 'prepend'], selection: { fields: { + __typename: { + keyRaw: '__typename', + type: 'String', + }, node: { type: listType, keyRaw: 'node', @@ -284,7 +288,15 @@ export class List { } insertData = { newEntry: { - edges: [{ node: { ...data, __typename: listType } }], + edges: [ + { + __typename: listType + 'Edge', + node: { + ...data, + __typename: listType, + }, + }, + ], }, } } else { diff --git a/packages/houdini/src/runtime/cache/tests/list.test.ts b/packages/houdini/src/runtime/cache/tests/list.test.ts index e9556fefd..67ba1ec95 100644 --- a/packages/houdini/src/runtime/cache/tests/list.test.ts +++ b/packages/houdini/src/runtime/cache/tests/list.test.ts @@ -1300,6 +1300,11 @@ test('append in connection', function () { keyRaw: 'edges', selection: { fields: { + __typename: { + type: 'String', + visible: true, + keyRaw: '__typename', + }, node: { type: 'Node', visible: true, @@ -1346,6 +1351,7 @@ test('append in connection', function () { friends: { edges: [ { + __typename: 'UserEdge', node: { __typename: 'User', id: '2', @@ -1389,6 +1395,7 @@ test('append in connection', function () { friends: { edges: [ { + __typename: 'UserEdge', node: { __typename: 'User', id: '2', @@ -1396,6 +1403,7 @@ test('append in connection', function () { }, }, { + __typename: 'UserEdge', node: { __typename: 'User', id: '3', @@ -1406,6 +1414,41 @@ test('append in connection', function () { }, }, }) + + // make sure we set an typename on the edge (so it has a value when we read back) + expect( + cache.read({ + selection, + }) + ).toEqual({ + data: { + viewer: { + id: '1', + friends: { + edges: [ + { + __typename: 'UserEdge', + node: { + __typename: 'User', + id: '2', + firstName: 'jane', + }, + }, + { + __typename: 'UserEdge', + node: { + __typename: 'User', + id: '3', + firstName: 'mary', + }, + }, + ], + }, + }, + }, + partial: false, + stale: false, + }) }) test('inserting data with an update overwrites a record inserted with list.append', function () {