-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix trace placement for errors occurring in lists (#7699)
Previously, when errors occurred while resolving a list item, the trace builder would fail to place the error at the correct path and just default to the root node with a warning message: > `Could not find node with path x.y.1, defaulting to put errors on root node.` This change places these errors at their correct paths and removes the log.
- Loading branch information
1 parent
6df54b8
commit 62e7d94
Showing
9 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'@apollo/server': patch | ||
--- | ||
|
||
Fix error path attachment for list items | ||
|
||
Previously, when errors occurred while resolving a list item, the trace builder would fail to place the error at the correct path and just default to the root node with a warning message: | ||
|
||
> `Could not find node with path x.y.1, defaulting to put errors on root node.` | ||
This change places these errors at their correct paths and removes the log. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,7 @@ tsconfig | |
tsconfigs | ||
typecheck | ||
typeis | ||
typenames | ||
typeof | ||
typesafe | ||
unawaited | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/server/src/__tests__/plugin/inlineTrace/inlineTracePlugin.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { ApolloServer, HeaderMap } from '@apollo/server'; | ||
import { gql } from 'graphql-tag'; | ||
import { buildSubgraphSchema } from '@apollo/subgraph'; | ||
import { describe, it, expect } from '@jest/globals'; | ||
import assert from 'assert'; | ||
import { Trace } from '@apollo/usage-reporting-protobuf'; | ||
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace'; | ||
|
||
describe('ApolloServerPluginInlineTrace', () => { | ||
it('Adds errors within lists to the correct path rather than the root', async () => { | ||
const server = new ApolloServer({ | ||
schema: buildSubgraphSchema({ | ||
typeDefs: gql` | ||
type Query { | ||
a: A! | ||
} | ||
type A { | ||
brokenList: [String!]! | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
a: () => ({}), | ||
}, | ||
A: { | ||
brokenList() { | ||
return ['hello world!', null]; | ||
}, | ||
}, | ||
}, | ||
}), | ||
plugins: [ | ||
// silence logs about the plugin being enabled | ||
ApolloServerPluginInlineTrace(), | ||
], | ||
}); | ||
await server.start(); | ||
const result = await server.executeHTTPGraphQLRequest({ | ||
httpGraphQLRequest: { | ||
body: { query: '{a{brokenList}}' }, | ||
headers: new HeaderMap([ | ||
['content-type', 'application/json'], | ||
['apollo-federation-include-trace', 'ftv1'], | ||
]), | ||
method: 'POST', | ||
search: '', | ||
}, | ||
context: async () => ({}), | ||
}); | ||
assert(result.body.kind === 'complete'); | ||
const trace = Trace.decode( | ||
Buffer.from(JSON.parse(result.body.string).extensions?.ftv1, 'base64'), | ||
); | ||
expect(trace.root?.error).toHaveLength(0); | ||
// error is found at path a.brokenList.1 | ||
expect(trace.root?.child?.[0].child?.[0].child?.[0].error) | ||
.toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"json": "{"message":"<masked>","locations":[{"line":1,"column":4}],"path":["a","brokenList",1],"extensions":{"maskedBy":"ApolloServerPluginInlineTrace"}}", | ||
"location": [ | ||
{ | ||
"column": 4, | ||
"line": 1, | ||
}, | ||
], | ||
"message": "<masked>", | ||
}, | ||
] | ||
`); | ||
|
||
await server.stop(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters