Skip to content

Commit 81a9415

Browse files
authored
fix GraphQL exception (#17274)
1 parent 8f47b9d commit 81a9415

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

middleware/contextualizers/graphql.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ const explorerUrl = process.env.NODE_ENV === 'production'
99
: 'http://localhost:3000'
1010

1111
module.exports = async (req, res, next) => {
12+
const currentVersionObj = allVersions[req.context.currentVersion]
1213
// ignore requests to non-GraphQL reference paths
13-
if (!req.path.includes('/graphql/')) return next()
14-
14+
// and to versions that don't exist
15+
if (!req.path.includes('/graphql/') || !currentVersionObj) {
16+
return next()
17+
}
1518
// Get the relevant name of the GraphQL schema files for the current version
1619
// For example, free-pro-team@latest corresponds to dotcom,
1720
// enterprise-server@2.22 corresponds to ghes-2.22,
1821
// and github-ae@latest corresponds to ghae
19-
const graphqlVersion = allVersions[req.context.currentVersion].miscVersionName
22+
const graphqlVersion = currentVersionObj.miscVersionName
2023

2124
req.context.graphql = {
2225
schemaForCurrentVersion: require(`../../lib/graphql/static/schema-${graphqlVersion}`),

middleware/contextualizers/webhooks.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-ve
55
const allVersions = require('../../lib/all-versions')
66

77
module.exports = async (req, res, next) => {
8-
if (!req.path.includes('webhook')) return next()
8+
const currentVersionObj = allVersions[req.context.currentVersion]
9+
// ignore requests to non-webhook reference paths
10+
// and to versions that don't exist
11+
if (!req.path.includes('webhook') || !currentVersionObj) {
12+
return next()
13+
}
914

1015
// Get the name of the dir under lib/webhooks/static
1116
// For example, free-pro-team@latest corresponds to dotcom,
1217
// enterprise-server@2.22 corresponds to ghes-2.22,
1318
// and github-ae@latest corresponds to ghae
14-
if (!allVersions[req.context.currentVersion]) return next()
15-
const webhookPayloadDir = allVersions[req.context.currentVersion].miscVersionName
19+
const webhookPayloadDir = currentVersionObj.miscVersionName
1620

1721
const webhookPayloadsForCurrentVersion = webhookPayloads[webhookPayloadDir]
1822

0 commit comments

Comments
 (0)