forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphql.js
36 lines (32 loc) · 1.59 KB
/
graphql.js
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
const previews = require('../../lib/graphql/static/previews')
const upcomingChanges = require('../../lib/graphql/static/upcoming-changes')
const changelog = require('../../lib/graphql/static/changelog')
const prerenderedObjects = require('../../lib/graphql/static/prerendered-objects')
const prerenderedInputObjects = require('../../lib/graphql/static/prerendered-input-objects')
const allVersions = require('../../lib/all-versions')
const explorerUrl = process.env.NODE_ENV === 'production'
? 'https://graphql.github.com/explorer'
: 'http://localhost:3000'
module.exports = function graphqlContext (req, res, next) {
const currentVersionObj = allVersions[req.context.currentVersion]
// ignore requests to non-GraphQL reference paths
// and to versions that don't exist
if (!req.path.includes('/graphql/') || !currentVersionObj) {
return next()
}
// Get the relevant name of the GraphQL schema files for the current version
// For example, free-pro-team@latest corresponds to dotcom,
// enterprise-server@2.22 corresponds to ghes-2.22,
// and github-ae@latest corresponds to ghae
const graphqlVersion = currentVersionObj.miscVersionName
req.context.graphql = {
schemaForCurrentVersion: require(`../../lib/graphql/static/schema-${graphqlVersion}`),
previewsForCurrentVersion: previews[graphqlVersion],
upcomingChangesForCurrentVersion: upcomingChanges[graphqlVersion],
prerenderedObjectsForCurrentVersion: prerenderedObjects[graphqlVersion],
prerenderedInputObjectsForCurrentVersion: prerenderedInputObjects[graphqlVersion],
explorerUrl,
changelog
}
return next()
}