diff --git a/packages/endpoint/src/schemas/Invalidate.ts b/packages/endpoint/src/schemas/Invalidate.ts index 40e8f0b686ff..09d766edc956 100644 --- a/packages/endpoint/src/schemas/Invalidate.ts +++ b/packages/endpoint/src/schemas/Invalidate.ts @@ -86,8 +86,8 @@ export default class Invalidate< args: readonly any[], unvisit: (schema: any, input: any) => any, ): AbstractInstanceType { - // TODO: is this really always going to be the full object - validate that calling fetch will give this even when input is a string - return unvisit(this._entity, id) as any; + // TODO: this return type should offer string, but we need to figure out an ergonomic way to do this + return unvisit(this._entity, id) ?? id; } /* istanbul ignore next */ diff --git a/packages/react/src/hooks/__tests__/useController/fetch.tsx b/packages/react/src/hooks/__tests__/useController/fetch.tsx index d709b7539743..8d8c1885ff8b 100644 --- a/packages/react/src/hooks/__tests__/useController/fetch.tsx +++ b/packages/react/src/hooks/__tests__/useController/fetch.tsx @@ -333,6 +333,51 @@ describe.each([ expect(warnSpy.mock.calls.length).toBe(0); }); + it('should return denormalized value when schema is present (delete)', async () => { + const { controller } = renderDataClient( + () => { + return 'hi'; + }, + { + resolverFixtures: [ + { + endpoint: CoolerArticleResource.delete, + args: [{ id: payload.id }], + response: payload, + }, + ], + }, + ); + const ret = await controller.fetch(CoolerArticleResource.delete, { + id: payload.id, + }); + expect(ret.content).toEqual(payload.content); + expect(ret).toBeInstanceOf(CoolerArticle); + expect(warnSpy.mock.calls.length).toBe(0); + }); + + it('should return denormalized value when schema is present (delete with string response)', async () => { + const { controller } = renderDataClient( + () => { + return 'hi'; + }, + { + resolverFixtures: [ + { + endpoint: CoolerArticleResource.delete, + args: [{ id: payload.id }], + response: payload.id, + }, + ], + }, + ); + const ret = await controller.fetch(CoolerArticleResource.delete, { + id: payload.id, + }); + expect(ret).toEqual(payload.id); + expect(warnSpy.mock.calls.length).toBe(0); + }); + it('should return denormalized value when schema is present (unions)', async () => { const response = [ null,