-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathgenerateExampleData.js
54 lines (43 loc) · 1.62 KB
/
generateExampleData.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This will use the "schema.gql" + "metadata.json" as the source of truth, and
// generate various other possible input examples that should all result in the
// same starting point for the documentation
const path = require('path')
const fs = require('fs')
const root = path.resolve(__dirname, '..')
const pathToExamplesDir = path.resolve(root, 'examples/data')
const pathToExampleSchema = path.resolve(pathToExamplesDir, 'schema.gql')
const pathToMetadata = path.resolve(pathToExamplesDir, 'metadata.json')
const pathToIntrospectionWithMetadata = path.resolve(
pathToExamplesDir,
'introspection-with-metadata.json'
)
const pathToIntrospectionWithoutMetadata = path.resolve(
pathToExamplesDir,
'introspection-without-metadata.json'
)
const {
loadSchemaFromSDLFile,
introspectionResponseFromSchema,
} = require('../dist/spectaql/graphql-loaders')
const { addMetadataFromFile } = require('../dist/spectaql/metadata-loaders')
const schema = loadSchemaFromSDLFile({ pathToFile: pathToExampleSchema })
const introspectionResponse = introspectionResponseFromSchema({ schema })
if (introspectionResponse.errors) {
console.error(introspectionResponse.errors)
throw new Error('Problem with Introspection Query Response')
}
fs.writeFileSync(
pathToIntrospectionWithoutMetadata,
JSON.stringify(introspectionResponse, null, 4)
)
addMetadataFromFile({
pathToFile: pathToMetadata,
introspectionQueryResponse: introspectionResponse,
metadatasReadPath: 'documentation',
metadatasWritePath: 'documentation',
})
fs.writeFileSync(
pathToIntrospectionWithMetadata,
JSON.stringify(introspectionResponse, null, 4)
)
console.log('Done!')