-
Notifications
You must be signed in to change notification settings - Fork 242
/
composedSdl.test.ts
44 lines (37 loc) 路 1.21 KB
/
composedSdl.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { ApolloGateway } from '@apollo/gateway';
import { ApolloServer } from 'apollo-server';
import { fetch } from '../../__mocks__/apollo-server-env';
import { getTestingSupergraphSdl } from '../execution-utils';
async function getSupergraphSdlGatewayServer() {
const server = new ApolloServer({
gateway: new ApolloGateway({
supergraphSdl: getTestingSupergraphSdl(),
}),
});
await server.listen({ port: 0 });
return server;
}
describe('Using supergraphSdl configuration', () => {
it('successfully starts and serves requests to the proper services', async () => {
const server = await getSupergraphSdlGatewayServer();
fetch.mockJSONResponseOnce({
data: { me: { username: '@jbaxleyiii' } },
});
const result = await server.executeOperation({
query: '{ me { username } }',
});
expect(result.data).toMatchInlineSnapshot(`
Object {
"me": Object {
"username": "@jbaxleyiii",
},
}
`);
const [url, request] = fetch.mock.calls[0];
expect(url).toEqual('https://accounts.api.com');
expect(request?.body).toEqual(
JSON.stringify({ query: '{me{username}}', variables: {} }),
);
await server.stop();
});
});