-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen.js
executable file
·85 lines (72 loc) · 2.49 KB
/
gen.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
const fs = require('fs')
const _ = require('lodash')
// const Diff = require('diff')
const { graphql, buildSchema, buildClientSchema, printSchema, introspectionQuery } = require('graphql')
const { createSchema } = require('./')
const models = require('./models')
const rethrow = (err) => {
if (err) throw err
}
// fs.writeFile('./schema-graphql', printSchema(createSchema().addModels(models).schema), rethrow)
let modelsCount = Object.keys(models).length
let counter = 0
while (modelsCount < 1000) {
counter++
let more = models//{}
Object.keys(models).forEach(id => {
modelsCount++
const model = models[id]
const copy = _.cloneDeep(model)
copy.id = id + '.' + counter
more[copy.id] = copy
})
}
console.log(Object.keys(models).length, 'models')
console.time('gen')
const tradleGraphql = createSchema()
tradleGraphql.addModels(models)
// let counter = 0
// while (modelsCount < 1000) {
// counter++
// let more = {}
// Object.keys(models).forEach(id => {
// modelsCount++
// const model = models[id]
// const copy = _.clone(model)
// copy.id = id + counter
// more[copy.id] = copy
// })
// console.log('added')
// tradleGraphql.addModels(more)
// }
tradleGraphql.schema
console.timeEnd('gen')
process.exit(0)
// const { schema } = tradleGraphql
// const str = printSchema(tradleGraphql.schema)
// // process.stdout.write(str)
// // process.stdout.write(JSON.stringify(schema, null, 2))
// graphql(schema, introspectionQuery)
// .then(result => {
// // process.stdout.write(JSON.stringify(result.data, null, 2))
// // debugger
// console.time('fromJson')
// const fromJson = buildClientSchema(result.data)
// console.timeEnd('fromJson')
// console.time('fromString')
// const fromString = buildSchema(str)
// console.timeEnd('fromString')
// // const printedFromJsonStr = printSchema(fromJson)
// // const printedFromStringStr = printSchema(fromString)
// // const diff = Diff.diffLines(printedFromJsonStr, printedFromStringStr, {
// // ignoreWhitespace: true
// // })
// // console.log('diff', diff)
// // console.log(printedFromJsonStr === printedFromStringStr)
// // if (printedFromJsonStr !== printedFromStringStr) {
// // fs.writeFile('./from-json.graphql', printedFromJsonStr, rethrow)
// // fs.writeFile('./from-str.graphql', printedFromStringStr, rethrow)
// // }
// })
// // const toJSON = schema => graphql(schema, introspectionQuery).then(result => result.data)