Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

graphql.js 1.6 KB

You have to be logged in to leave a comment. Sign In
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
  1. const previews = require('../../lib/graphql/static/previews')
  2. const upcomingChanges = require('../../lib/graphql/static/upcoming-changes')
  3. const changelog = require('../../lib/graphql/static/changelog')
  4. const prerenderedObjects = require('../../lib/graphql/static/prerendered-objects')
  5. const prerenderedInputObjects = require('../../lib/graphql/static/prerendered-input-objects')
  6. const allVersions = require('../../lib/all-versions')
  7. const explorerUrl = process.env.NODE_ENV === 'production'
  8. ? 'https://graphql.github.com/explorer'
  9. : 'http://localhost:3000'
  10. module.exports = function graphqlContext (req, res, next) {
  11. const currentVersionObj = allVersions[req.context.currentVersion]
  12. // ignore requests to non-GraphQL reference paths
  13. // and to versions that don't exist
  14. if (!req.path.includes('/graphql/') || !currentVersionObj) {
  15. return next()
  16. }
  17. // Get the relevant name of the GraphQL schema files for the current version
  18. // For example, free-pro-team@latest corresponds to dotcom,
  19. // enterprise-server@2.22 corresponds to ghes-2.22,
  20. // and github-ae@latest corresponds to ghae
  21. const graphqlVersion = currentVersionObj.miscVersionName
  22. req.context.graphql = {
  23. schemaForCurrentVersion: require(`../../lib/graphql/static/schema-${graphqlVersion}`),
  24. previewsForCurrentVersion: previews[graphqlVersion],
  25. upcomingChangesForCurrentVersion: upcomingChanges[graphqlVersion],
  26. prerenderedObjectsForCurrentVersion: prerenderedObjects[graphqlVersion],
  27. prerenderedInputObjectsForCurrentVersion: prerenderedInputObjects[graphqlVersion],
  28. explorerUrl,
  29. changelog
  30. }
  31. return next()
  32. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...