Skip to content

Commit

Permalink
fix: server/generateModels bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Nov 22, 2023
1 parent b877493 commit 5e4525b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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('subscriptions are disabled', 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 5e4525b

Please sign in to comment.