Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: server/generateModelsProperty bug #12610

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading