1
- import { readCompressedJsonFileFallbackLazily } from '../../lib/read-json-file.js'
1
+ import {
2
+ readCompressedJsonFileFallbackLazily ,
3
+ readCompressedJsonFileFallback ,
4
+ } from '../../lib/read-json-file.js'
2
5
import { allVersions } from '../../lib/all-versions.js'
3
6
const previews = readCompressedJsonFileFallbackLazily ( './lib/graphql/static/previews.json' )
4
7
const upcomingChanges = readCompressedJsonFileFallbackLazily (
@@ -20,6 +23,17 @@ const explorerUrl =
20
23
? 'https://graphql.github.com/explorer'
21
24
: 'http://localhost:3000'
22
25
26
+ const graphQLVersionSchemaCache = new Map ( )
27
+ function readGraphQLVersionSchema ( graphqlVersion ) {
28
+ if ( ! graphQLVersionSchemaCache . has ( graphqlVersion ) ) {
29
+ graphQLVersionSchemaCache . set (
30
+ graphqlVersion ,
31
+ readCompressedJsonFileFallback ( `lib/graphql/static/schema-${ graphqlVersion } .json` )
32
+ )
33
+ }
34
+ return graphQLVersionSchemaCache . get ( graphqlVersion )
35
+ }
36
+
23
37
export default function graphqlContext ( req , res , next ) {
24
38
const currentVersionObj = allVersions [ req . context . currentVersion ]
25
39
// ignore requests to non-GraphQL reference paths
@@ -34,9 +48,7 @@ export default function graphqlContext(req, res, next) {
34
48
const graphqlVersion = currentVersionObj . miscVersionName
35
49
36
50
req . context . graphql = {
37
- schemaForCurrentVersion : readCompressedJsonFileFallbackLazily (
38
- `lib/graphql/static/schema-${ graphqlVersion } .json`
39
- ) ( ) ,
51
+ schemaForCurrentVersion : readGraphQLVersionSchema ( graphqlVersion ) ,
40
52
previewsForCurrentVersion : previews ( ) [ graphqlVersion ] ,
41
53
upcomingChangesForCurrentVersion : upcomingChanges ( ) [ graphqlVersion ] ,
42
54
prerenderedObjectsForCurrentVersion : prerenderedObjects ( ) [ graphqlVersion ] ,
0 commit comments