Skip to content

Commit

Permalink
fix: server/generateModelsProperty bug (#12610)
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Nov 22, 2023
1 parent fe5afe6 commit a04a462
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/adapter-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"dist/cjs",
"dist/esm",
"src",
"api"
"api",
"data"
],
"homepage": "https://aws-amplify.github.io/",
"license": "Apache-2.0",
Expand Down
27 changes: 27 additions & 0 deletions packages/api-graphql/__tests__/server/generateClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Schema, V6ClientSSRRequest<Schema>>({
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'),
}),
{}
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export function generateModelsProperty<
| V6ClientSSRRequest<Record<string, any>>
| V6ClientSSRCookies<Record<string, any>> = V6ClientSSRCookies<
Record<string, any>
>
>,
>(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');
Expand Down

0 comments on commit a04a462

Please sign in to comment.