Skip to content

Commit 363fd30

Browse files
bonniciglasser
andauthored
Added unit tests for masked and unmodified error logging options (#6795)
Co-authored-by: David Glasser <[email protected]>
1 parent e271815 commit 363fd30

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

.changeset/ninety-tips-unite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/server-integration-testsuite": patch
3+
---
4+
5+
Added unit tests to cover `unmodified` and `masked` error reporting options

packages/integration-testsuite/src/apolloServerTests.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,108 @@ export function defineIntegrationTestSuiteApolloServerTests(
13101310
},
13111311
]);
13121312
});
1313+
1314+
it('unmodified', async () => {
1315+
throwError.mockImplementationOnce(() => {
1316+
throw new GraphQLError('should be unmodified', {
1317+
extensions: { custom: 'extension' },
1318+
});
1319+
});
1320+
1321+
await setupApolloServerAndFetchPair({
1322+
sendErrorsInTraces: {
1323+
unmodified: true,
1324+
},
1325+
});
1326+
1327+
const result = await apolloFetch({
1328+
query: `{fieldWhichWillError}`,
1329+
});
1330+
expect(result.data).toEqual({
1331+
fieldWhichWillError: null,
1332+
});
1333+
expect(result.errors).toBeDefined();
1334+
expect(result.errors[0].message).toEqual('should be unmodified');
1335+
expect(throwError).toHaveBeenCalledTimes(1);
1336+
1337+
const reports = await reportIngress.promiseOfReports;
1338+
expect(reports.length).toBe(1);
1339+
const trace = Object.values(reports[0].tracesPerQuery)[0]
1340+
.trace![0] as Trace;
1341+
1342+
// There should be no error at the root, our error is a child.
1343+
expect(trace.root!.error).toStrictEqual([]);
1344+
1345+
// There should only be one child.
1346+
expect(trace.root!.child!.length).toBe(1);
1347+
1348+
// The child should maintain the path and message
1349+
expect(trace.root!.child![0].error).toMatchInlineSnapshot(`
1350+
Array [
1351+
Object {
1352+
"json": "{\\"message\\":\\"should be unmodified\\",\\"locations\\":[{\\"line\\":1,\\"column\\":2}],\\"path\\":[\\"fieldWhichWillError\\"],\\"extensions\\":{\\"custom\\":\\"extension\\"}}",
1353+
"location": Array [
1354+
Object {
1355+
"column": 2,
1356+
"line": 1,
1357+
},
1358+
],
1359+
"message": "should be unmodified",
1360+
},
1361+
]
1362+
`);
1363+
});
1364+
1365+
it('masked', async () => {
1366+
throwError.mockImplementationOnce(() => {
1367+
throw new GraphQLError('should be masked', {
1368+
extensions: { custom: 'extension' },
1369+
});
1370+
});
1371+
1372+
await setupApolloServerAndFetchPair({
1373+
sendErrorsInTraces: {
1374+
masked: true,
1375+
},
1376+
});
1377+
1378+
const result = await apolloFetch({
1379+
query: `{fieldWhichWillError}`,
1380+
});
1381+
expect(result.data).toEqual({
1382+
fieldWhichWillError: null,
1383+
});
1384+
expect(result.errors).toBeDefined();
1385+
expect(result.errors[0].message).toEqual('should be masked');
1386+
expect(throwError).toHaveBeenCalledTimes(1);
1387+
1388+
const reports = await reportIngress.promiseOfReports;
1389+
expect(reports.length).toBe(1);
1390+
const trace = Object.values(reports[0].tracesPerQuery)[0]
1391+
.trace![0] as Trace;
1392+
1393+
// There should be no error at the root, our error is a child.
1394+
expect(trace.root!.error).toStrictEqual([]);
1395+
1396+
// There should only be one child.
1397+
expect(trace.root!.child!.length).toBe(1);
1398+
1399+
// The child should maintain the path, but have its message masked
1400+
expect(trace.root!.child![0].error).toMatchInlineSnapshot(`
1401+
Array [
1402+
Object {
1403+
"json": "{\\"message\\":\\"<masked>\\",\\"locations\\":[{\\"line\\":1,\\"column\\":2}],\\"path\\":[\\"fieldWhichWillError\\"],\\"extensions\\":{\\"maskedBy\\":\\"ApolloServerPluginUsageReporting\\"}}",
1404+
"location": Array [
1405+
Object {
1406+
"column": 2,
1407+
"line": 1,
1408+
},
1409+
],
1410+
"message": "<masked>",
1411+
},
1412+
]
1413+
`);
1414+
});
13131415
});
13141416
});
13151417
});

0 commit comments

Comments
 (0)