Skip to content

Commit 374e30b

Browse files
authored
graphql nodejs error testing (#3909)
Adds weblog endpoint for nodejs for graphql error testing
1 parent 564ea43 commit 374e30b

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

manifests/nodejs.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ refs:
4444
- &ref_5_30_0 '>=5.30.0 || ^4.54.0'
4545
- &ref_5_32_0 '>=5.32.0'
4646
- &ref_5_33_0 '>=5.33.0'
47+
- &ref_5_34_0 '>=5.34.0'
4748

4849
tests/:
4950
apm_tracing_e2e/:
@@ -912,7 +913,12 @@ tests/:
912913
Test_Synthetics_APM_Datadog:
913914
'*': *ref_5_25_0
914915
nextjs: bug (APMAPI-939) # the nextjs weblog application changes the sampling priority from 1.0 to 2.0
915-
test_graphql.py: missing_feature
916+
test_graphql.py:
917+
Test_GraphQLQueryErrorReporting:
918+
'*': *ref_5_34_0
919+
express4-typescript: incomplete_test_app (endpoint not implemented)
920+
express5: missing_feature
921+
nextjs: missing_feature
916922
test_identify.py:
917923
Test_Basic: v2.4.0
918924
Test_Propagate: *ref_3_2_0

utils/build/docker/nodejs/express/graphql.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,22 @@ const typeDefs = gql`
2525
user(id: Int!): User
2626
userByName(name: String): [User]
2727
testInjection(path: String): [User]
28+
withError: ID
2829
}
2930
3031
type User {
3132
id: Int
3233
name: String
34+
}
35+
36+
type Error {
37+
message: String
38+
extensions: [Extension]
39+
}
40+
41+
type Extension {
42+
key: String
43+
value: String
3344
}`
3445

3546
function getUser (parent, args) {
@@ -49,16 +60,35 @@ function testInjection (parent, args) {
4960
return users
5061
}
5162

63+
function withError (parent, args) {
64+
throw new Error('test error')
65+
}
66+
5267
const resolvers = {
5368
Query: {
5469
user: getUser,
5570
userByName: getUserByName,
56-
testInjection
71+
testInjection,
72+
withError
73+
}
74+
}
75+
76+
// Custom error formatting
77+
const formatError = (error) => {
78+
return {
79+
message: error.message,
80+
extensions: [
81+
{ key: 'int-1', value: '1' },
82+
{ key: 'str-1', value: '1' },
83+
{ key: 'array-1-2', value: [1, '2'] },
84+
{ key: 'empty', value: 'empty string' },
85+
{ key: 'comma', value: 'comma' }
86+
]
5787
}
5888
}
5989

6090
module.exports = async function (app) {
61-
const server = new ApolloServer({ typeDefs, resolvers })
91+
const server = new ApolloServer({ typeDefs, resolvers, formatError })
6292
await server.start()
6393
server.applyMiddleware({ app })
6494
}

0 commit comments

Comments
 (0)