diff --git a/packages/adapter-nextjs/package.json b/packages/adapter-nextjs/package.json index 2a5d6f04e4a..d1ec6900399 100644 --- a/packages/adapter-nextjs/package.json +++ b/packages/adapter-nextjs/package.json @@ -50,7 +50,8 @@ "dist/cjs", "dist/esm", "src", - "api" + "api", + "data" ], "homepage": "https://aws-amplify.github.io/", "license": "Apache-2.0", diff --git a/packages/api-graphql/__tests__/server/generateClient.test.ts b/packages/api-graphql/__tests__/server/generateClient.test.ts index 830be38037b..06d7b78ef18 100644 --- a/packages/api-graphql/__tests__/server/generateClient.test.ts +++ b/packages/api-graphql/__tests__/server/generateClient.test.ts @@ -279,5 +279,32 @@ describe('server generateClient', () => { client.models.Note.onCreate().subscribe(); }).toThrowError(); }); + + test('contextSpec param gets passed through to client.graphql', async () => { + Amplify.configure(configFixture as any); + const config = Amplify.getConfig(); + + const client = generateClient>({ + amplify: null, + config: config, + }); + + const mockContextSpec = {}; + + const spy = jest.spyOn(client, 'graphql').mockImplementation(async () => { + const result: any = {}; + return result; + }); + + await client.models.Note.list(mockContextSpec); + + expect(spy).toHaveBeenCalledWith( + mockContextSpec, + expect.objectContaining({ + query: expect.stringContaining('listNotes'), + }), + {} + ); + }); }); }); diff --git a/packages/api-graphql/src/internals/server/generateModelsProperty.ts b/packages/api-graphql/src/internals/server/generateModelsProperty.ts index c8e7a128672..7bc19fba940 100644 --- a/packages/api-graphql/src/internals/server/generateModelsProperty.ts +++ b/packages/api-graphql/src/internals/server/generateModelsProperty.ts @@ -15,11 +15,11 @@ export function generateModelsProperty< | V6ClientSSRRequest> | V6ClientSSRCookies> = V6ClientSSRCookies< Record - > + >, >(client: ClientType, params: ServerClientGenerationParams): ClientType { const models = {} as any; const config = params.config; - const useContext = client === null; + const useContext = params.amplify === null; if (!config) { throw new Error('generateModelsProperty cannot retrieve Amplify config');