@xyd-js/gql 0.1.0-xyd.1 → 0.1.0-xyd.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +19594 -58
- package/dist/index.js.map +1 -1
- package/examples/graphql-types/graphql-types.0.basic.graphqls +28 -0
- package/examples/nested/nested-arg.0.not-required.graphqls +8 -0
- package/examples/nested/nested-arg.0.required.graphqls +8 -0
- package/examples/nested/nested-arg.1.deep.graphqls +12 -0
- package/package.json +10 -5
- package/src/hydration/README.md +1 -0
- package/src/hydration/gql-arg.ts +53 -0
- package/src/{fields.ts → hydration/gql-field.ts} +60 -10
- package/src/hydration/gql-input.ts +67 -0
- package/src/hydration/gql-object.ts +35 -0
- package/src/hydration/gql-types.ts +50 -0
- package/src/index.ts +1 -1
- package/src/{examples.ts → samples/index.ts} +1 -2
- package/src/schema.ts +67 -7
- package/src/utils.ts +7 -8
- package/test/graphql-types.0.test.ts +125 -0
- package/test/nested-arg.0.test.ts +208 -0
- package/test/nested-arg.1.test.ts +19 -0
- package/vitest.config.ts +7 -0
- package/src/arguments.ts +0 -52
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
import {beforeEach, describe, expect, it} from 'vitest'
|
|
4
|
+
|
|
5
|
+
import {gqlSchemaToReferences} from "../src";
|
|
6
|
+
|
|
7
|
+
describe('graphql-types', async () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('0.basic', async () => {
|
|
12
|
+
const schemaLocation = path.join(process.cwd(), "./examples/graphql-types/graphql-types.0.basic.graphqls")
|
|
13
|
+
|
|
14
|
+
const references = await gqlSchemaToReferences(schemaLocation)
|
|
15
|
+
|
|
16
|
+
const equal = [
|
|
17
|
+
{
|
|
18
|
+
"canonical": "Date",
|
|
19
|
+
"description": "This is a custom scalar type for Date.",
|
|
20
|
+
"context": {
|
|
21
|
+
"graphqlName": "Date",
|
|
22
|
+
"graphqlType": "scalar"
|
|
23
|
+
},
|
|
24
|
+
"definitions": [],
|
|
25
|
+
"examples": {
|
|
26
|
+
"groups": []
|
|
27
|
+
},
|
|
28
|
+
"title": "Date"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"canonical": "Role",
|
|
32
|
+
"description": "This is a custom enum type for Role.",
|
|
33
|
+
"context": {
|
|
34
|
+
"graphqlName": "Role",
|
|
35
|
+
"graphqlType": "enum"
|
|
36
|
+
},
|
|
37
|
+
"definitions": [
|
|
38
|
+
{
|
|
39
|
+
"properties": [
|
|
40
|
+
{
|
|
41
|
+
"description": "",
|
|
42
|
+
"name": "ADMIN",
|
|
43
|
+
"type": "string"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"description": "",
|
|
47
|
+
"name": "OWNER",
|
|
48
|
+
"type": "string"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"title": "Valid values"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"examples": {
|
|
55
|
+
"groups": []
|
|
56
|
+
},
|
|
57
|
+
"title": "Role"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"title": "BookInput",
|
|
61
|
+
"description": "This is a custom input type for Book.",
|
|
62
|
+
"canonical": "BookInput",
|
|
63
|
+
"context": {
|
|
64
|
+
"graphqlName": "BookInput",
|
|
65
|
+
"graphqlType": "input"
|
|
66
|
+
},
|
|
67
|
+
"definitions": [
|
|
68
|
+
{
|
|
69
|
+
"title": "Fields",
|
|
70
|
+
"properties": [
|
|
71
|
+
{
|
|
72
|
+
"name": "title",
|
|
73
|
+
"type": "String!",
|
|
74
|
+
"description": "",
|
|
75
|
+
"properties": []
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "author",
|
|
79
|
+
"type": "String!",
|
|
80
|
+
"description": "",
|
|
81
|
+
"properties": []
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"examples": {
|
|
87
|
+
"groups": []
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"title": "Book",
|
|
92
|
+
"description": "This is a custom type for Book.",
|
|
93
|
+
"canonical": "Book",
|
|
94
|
+
"context": {
|
|
95
|
+
"graphqlName": "Book",
|
|
96
|
+
"graphqlType": "object"
|
|
97
|
+
},
|
|
98
|
+
"definitions": [
|
|
99
|
+
{
|
|
100
|
+
"title": "Fields",
|
|
101
|
+
"properties": [
|
|
102
|
+
{
|
|
103
|
+
"name": "title",
|
|
104
|
+
"type": "String!",
|
|
105
|
+
"description": "",
|
|
106
|
+
"properties": []
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "author",
|
|
110
|
+
"type": "String!",
|
|
111
|
+
"description": "",
|
|
112
|
+
"properties": []
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"examples": {
|
|
118
|
+
"groups": []
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
expect(references).toEqual(equal)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
import {beforeEach, describe, expect, it} from 'vitest'
|
|
4
|
+
|
|
5
|
+
import {gqlSchemaToReferences} from "../src";
|
|
6
|
+
|
|
7
|
+
describe('nested-arg', async () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('0.required', async () => {
|
|
12
|
+
const schemaLocation = path.join(process.cwd(), "./examples/nested/nested-arg.0.required.graphqls")
|
|
13
|
+
|
|
14
|
+
const references = await gqlSchemaToReferences(schemaLocation)
|
|
15
|
+
|
|
16
|
+
const equal = [
|
|
17
|
+
{
|
|
18
|
+
"title": "addBook",
|
|
19
|
+
"canonical": "addBook",
|
|
20
|
+
"description": "",
|
|
21
|
+
"category": "graphql",
|
|
22
|
+
"type": "graphql_mutation",
|
|
23
|
+
"examples": {
|
|
24
|
+
"groups": [
|
|
25
|
+
{
|
|
26
|
+
"description": "Example request",
|
|
27
|
+
"examples": [
|
|
28
|
+
{
|
|
29
|
+
"codeblock": {
|
|
30
|
+
"tabs": [
|
|
31
|
+
{
|
|
32
|
+
"title": "graphql",
|
|
33
|
+
"language": "graphql",
|
|
34
|
+
"code": "mutation addBook ($bookInput: BookInput) {\n addBook (bookInput: $bookInput)\n}"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"definitions": [
|
|
44
|
+
{
|
|
45
|
+
"title": "Arguments",
|
|
46
|
+
"properties": [
|
|
47
|
+
{
|
|
48
|
+
"name": "bookInput",
|
|
49
|
+
"type": "BookInput",
|
|
50
|
+
"description": "",
|
|
51
|
+
"properties": [
|
|
52
|
+
{
|
|
53
|
+
"name": "title",
|
|
54
|
+
"type": "String!",
|
|
55
|
+
"description": "",
|
|
56
|
+
"properties": []
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "author",
|
|
60
|
+
"type": "String!",
|
|
61
|
+
"description": "",
|
|
62
|
+
"properties": []
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"title": "Returns",
|
|
70
|
+
"properties": []
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"title": "BookInput",
|
|
76
|
+
"description": "",
|
|
77
|
+
"canonical": "BookInput",
|
|
78
|
+
"context": {
|
|
79
|
+
"graphqlName": "BookInput",
|
|
80
|
+
"graphqlType": "input"
|
|
81
|
+
},
|
|
82
|
+
"definitions": [
|
|
83
|
+
{
|
|
84
|
+
"title": "Fields",
|
|
85
|
+
"properties": [
|
|
86
|
+
{
|
|
87
|
+
"name": "title",
|
|
88
|
+
"type": "String!",
|
|
89
|
+
"description": "",
|
|
90
|
+
"properties": []
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "author",
|
|
94
|
+
"type": "String!",
|
|
95
|
+
"description": "",
|
|
96
|
+
"properties": []
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"examples": {
|
|
102
|
+
"groups": []
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
expect(references).toEqual(equal)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('0.not-required', async () => {
|
|
111
|
+
const schemaLocation = path.join(process.cwd(), "./examples/nested/nested-arg.0.not-required.graphqls")
|
|
112
|
+
|
|
113
|
+
const references = await gqlSchemaToReferences(schemaLocation)
|
|
114
|
+
|
|
115
|
+
const equal = [
|
|
116
|
+
{
|
|
117
|
+
"title": "addBook",
|
|
118
|
+
"canonical": "addBook",
|
|
119
|
+
"description": "",
|
|
120
|
+
"category": "graphql",
|
|
121
|
+
"type": "graphql_mutation",
|
|
122
|
+
"examples": {
|
|
123
|
+
"groups": [
|
|
124
|
+
{
|
|
125
|
+
"description": "Example request",
|
|
126
|
+
"examples": [
|
|
127
|
+
{
|
|
128
|
+
"codeblock": {
|
|
129
|
+
"tabs": [
|
|
130
|
+
{
|
|
131
|
+
"title": "graphql",
|
|
132
|
+
"language": "graphql",
|
|
133
|
+
"code": "mutation addBook ($bookInput: BookInput) {\n addBook (bookInput: $bookInput)\n}"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
"definitions": [
|
|
143
|
+
{
|
|
144
|
+
"title": "Arguments",
|
|
145
|
+
"properties": [
|
|
146
|
+
{
|
|
147
|
+
"name": "bookInput",
|
|
148
|
+
"type": "BookInput",
|
|
149
|
+
"description": "",
|
|
150
|
+
"properties": [
|
|
151
|
+
{
|
|
152
|
+
"name": "title",
|
|
153
|
+
"type": "String!",
|
|
154
|
+
"description": "",
|
|
155
|
+
"properties": []
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "author",
|
|
159
|
+
"type": "String!",
|
|
160
|
+
"description": "",
|
|
161
|
+
"properties": []
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"title": "Returns",
|
|
169
|
+
"properties": []
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"title": "BookInput",
|
|
175
|
+
"description": "",
|
|
176
|
+
"canonical": "BookInput",
|
|
177
|
+
"context": {
|
|
178
|
+
"graphqlName": "BookInput",
|
|
179
|
+
"graphqlType": "input"
|
|
180
|
+
},
|
|
181
|
+
"definitions": [
|
|
182
|
+
{
|
|
183
|
+
"title": "Fields",
|
|
184
|
+
"properties": [
|
|
185
|
+
{
|
|
186
|
+
"name": "title",
|
|
187
|
+
"type": "String!",
|
|
188
|
+
"description": "",
|
|
189
|
+
"properties": []
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"name": "author",
|
|
193
|
+
"type": "String!",
|
|
194
|
+
"description": "",
|
|
195
|
+
"properties": []
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
"examples": {
|
|
201
|
+
"groups": []
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
expect(references).toEqual(equal)
|
|
207
|
+
})
|
|
208
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
import {beforeEach, describe, expect, it} from 'vitest'
|
|
4
|
+
|
|
5
|
+
import {gqlSchemaToReferences} from "../src";
|
|
6
|
+
|
|
7
|
+
describe('nested-arg', async () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('1.deep', async () => {
|
|
12
|
+
const schemaLocation = path.join(process.cwd(), "./examples/nested/nested-arg.1.deep.graphqls")
|
|
13
|
+
|
|
14
|
+
const references = await gqlSchemaToReferences(schemaLocation)
|
|
15
|
+
|
|
16
|
+
// console.log(JSON.stringify(references, null, 2))
|
|
17
|
+
// expect(references).toEqual()
|
|
18
|
+
})
|
|
19
|
+
})
|
package/vitest.config.ts
ADDED
package/src/arguments.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {GraphQLArgument} from "graphql/type/definition";
|
|
2
|
-
import {GraphQLInputObjectType} from "graphql/type";
|
|
3
|
-
import {DefinitionProperty} from "@xyd-js/uniform";
|
|
4
|
-
|
|
5
|
-
import {fieldIntoDefinitionProperty} from "./fields";
|
|
6
|
-
|
|
7
|
-
// argumentsIntoDefinitionProperty converts GraphQL arguments into xyd 'uniform' definition properties
|
|
8
|
-
export function argumentsIntoDefinitionProperty(
|
|
9
|
-
args: readonly GraphQLArgument[]
|
|
10
|
-
): DefinitionProperty[] {
|
|
11
|
-
const resp: DefinitionProperty[] = []
|
|
12
|
-
|
|
13
|
-
args.forEach(arg => {
|
|
14
|
-
if (arg.type.constructor.name === "GraphQLInputObjectType") {
|
|
15
|
-
const inputObjectType = arg.type as GraphQLInputObjectType
|
|
16
|
-
|
|
17
|
-
const inputFields = inputObjectType.getFields?.()
|
|
18
|
-
|
|
19
|
-
const nestedProps: DefinitionProperty[] = []
|
|
20
|
-
const nestedDefinitionProperty: DefinitionProperty = {
|
|
21
|
-
name: arg.name,
|
|
22
|
-
type: arg.type.toJSON(),
|
|
23
|
-
description: arg.description || "",
|
|
24
|
-
properties: nestedProps,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
for (const [name, inputField] of Object.entries(inputFields)) {
|
|
28
|
-
const prop = fieldIntoDefinitionProperty(
|
|
29
|
-
name,
|
|
30
|
-
inputField,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
if (prop) {
|
|
34
|
-
nestedProps.push(prop)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
resp.push(nestedDefinitionProperty)
|
|
39
|
-
} else {
|
|
40
|
-
const prop: DefinitionProperty = {
|
|
41
|
-
name: arg.name,
|
|
42
|
-
type: arg.type.toJSON(),
|
|
43
|
-
description: arg.description || "",
|
|
44
|
-
properties: [],
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
resp.push(prop)
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
return resp
|
|
52
|
-
}
|