forked from mhallin/graphql_ppx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
convertSchema.js
executable file
·108 lines (104 loc) · 2.14 KB
/
convertSchema.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env node
const graphqlTools = require('graphql-tools');
const graphql = require('graphql');
const fs = require('fs');
const argv = require("yargs")
.usage('Usage: $0 <schema>')
.command("schema", "Path to the schema file", { alias: "schema" })
.required(1, "The schema file is required")
.help("?")
.alias("?", "help").argv;
const introspectionQuery = `
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}`;
const typeDefs = fs.readFileSync(argv._[0], {encoding: 'utf-8'});
const schema = graphqlTools.makeExecutableSchema({ typeDefs, resolverValidationOptions: { requireResolversForResolveType: false } });
graphqlTools.addMockFunctionsToSchema({ schema });
graphql.graphql(schema, introspectionQuery).then(result =>
process.stdout.write(JSON.stringify(result, null, ' ')));