@xyd-js/gql 0.1.0-xyd.9 → 0.1.0-xyd.96
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/CHANGELOG.md +810 -0
- package/LICENSE +21 -0
- package/TODO.md +8 -0
- package/__fixtures__/-1.opendocs.docs-nested/input.graphql +66 -0
- package/__fixtures__/-1.opendocs.docs-nested/output.json +554 -0
- package/__fixtures__/-1.opendocs.flat/input.graphql +19 -0
- package/__fixtures__/-1.opendocs.flat/output.json +243 -0
- package/__fixtures__/-1.opendocs.scopes/input.graphql +33 -0
- package/__fixtures__/-1.opendocs.scopes/output.json +378 -0
- package/__fixtures__/-1.opendocs.sidebar/input.graphql +44 -0
- package/__fixtures__/-1.opendocs.sort/input.graphql +92 -0
- package/__fixtures__/-1.opendocs.sort/output.json +1078 -0
- package/__fixtures__/-1.opendocs.sort+group/input.graphql +111 -0
- package/__fixtures__/-1.opendocs.sort+group/output.json +1114 -0
- package/__fixtures__/-1.opendocs.sort+group+path/input.graphql +118 -0
- package/__fixtures__/-1.opendocs.sort+group+path/output.json +1114 -0
- package/__fixtures__/-2.complex.github/input.graphql +69424 -0
- package/__fixtures__/-2.complex.github/output.json +269874 -0
- package/__fixtures__/-2.complex.livesession/input.graphql +23 -0
- package/__fixtures__/-2.complex.livesession/output.json +302 -0
- package/__fixtures__/-2.complex.monday/input.graphql +6089 -0
- package/__fixtures__/-2.complex.monday/output.json +1 -0
- package/__fixtures__/-3.array-non-null-return/input.graphql +9 -0
- package/__fixtures__/-3.array-non-null-return/output.json +151 -0
- package/__fixtures__/1.basic/input.graphql +118 -0
- package/__fixtures__/1.basic/output.json +630 -0
- package/__fixtures__/2.circular/input.graphql +17 -0
- package/__fixtures__/2.circular/output.json +248 -0
- package/__fixtures__/3.opendocs/input.graphql +27 -0
- package/__fixtures__/3.opendocs/output.json +338 -0
- package/__fixtures__/4.union/input.graphql +19 -0
- package/__fixtures__/4.union/output.json +344 -0
- package/__fixtures__/5.flat/input.graphql +27 -0
- package/__fixtures__/5.flat/output.json +383 -0
- package/__fixtures__/6.default-values/input.graphql +47 -0
- package/__fixtures__/6.default-values/output.json +655 -0
- package/__fixtures__/7.type-args/input.graphql +19 -0
- package/__fixtures__/7.type-args/output.json +301 -0
- package/__fixtures__/8.default-sort/input.graphql +60 -0
- package/__fixtures__/8.default-sort/output.json +1078 -0
- package/__tests__/gqlSchemaToReferences.test.ts +109 -0
- package/__tests__/utils.ts +45 -0
- package/declarations.d.ts +4 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +1334 -19871
- package/dist/index.js.map +1 -1
- package/dist/opendocs.graphql +56 -0
- package/package.json +7 -9
- package/src/context.ts +17 -0
- package/src/converters/gql-arg.ts +51 -0
- package/src/converters/gql-enum.ts +27 -0
- package/src/converters/gql-field.ts +164 -0
- package/src/converters/gql-input.ts +34 -0
- package/src/converters/gql-interface.ts +35 -0
- package/src/converters/gql-mutation.ts +36 -0
- package/src/converters/gql-object.ts +83 -0
- package/src/converters/gql-operation.ts +128 -0
- package/src/converters/gql-query.ts +36 -0
- package/src/converters/gql-sample.ts +159 -0
- package/src/converters/gql-scalar.ts +16 -0
- package/src/converters/gql-subscription.ts +36 -0
- package/src/converters/gql-types.ts +195 -0
- package/src/converters/gql-union.ts +40 -0
- package/src/gql-core.ts +362 -0
- package/src/opendocs.graphql +56 -0
- package/src/opendocs.ts +253 -0
- package/src/schema.ts +253 -67
- package/src/types.ts +103 -0
- package/src/utils.ts +21 -96
- package/tsconfig.json +1 -1
- package/tsup.config.ts +15 -1
- package/vitest.config.ts +15 -1
- package/examples/basic/index.ts +0 -12
- package/examples/basic/schema.graphqls +0 -89
- package/examples/basic/todo-app.graphqls +0 -184
- package/examples/graphql-types/graphql-types.0.basic.graphqls +0 -28
- package/examples/nested/nested-arg.0.not-required.graphqls +0 -8
- package/examples/nested/nested-arg.0.required.graphqls +0 -8
- package/examples/nested/nested-arg.1.deep.graphqls +0 -12
- package/src/hydration/README.md +0 -1
- package/src/hydration/gql-arg.ts +0 -53
- package/src/hydration/gql-field.ts +0 -206
- package/src/hydration/gql-input.ts +0 -67
- package/src/hydration/gql-object.ts +0 -35
- package/src/hydration/gql-types.ts +0 -50
- package/src/samples/index.ts +0 -95
- package/test/graphql-types.0.test.ts +0 -125
- package/test/nested-arg.0.test.ts +0 -208
- package/test/nested-arg.1.test.ts +0 -19
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# TODO: !!! case with circular dependencies !!!
|
|
2
|
-
|
|
3
|
-
"""
|
|
4
|
-
A book type
|
|
5
|
-
"""
|
|
6
|
-
type Book {
|
|
7
|
-
"""
|
|
8
|
-
The title of the book
|
|
9
|
-
"""
|
|
10
|
-
title: String
|
|
11
|
-
|
|
12
|
-
"""
|
|
13
|
-
The author of the book
|
|
14
|
-
"""
|
|
15
|
-
author_name: String
|
|
16
|
-
# author: Author
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
"""
|
|
20
|
-
An author type
|
|
21
|
-
"""
|
|
22
|
-
type Author {
|
|
23
|
-
"""
|
|
24
|
-
The name of the author
|
|
25
|
-
"""
|
|
26
|
-
name: String
|
|
27
|
-
|
|
28
|
-
"""
|
|
29
|
-
The books of the author
|
|
30
|
-
"""
|
|
31
|
-
books: [String]
|
|
32
|
-
# books: [Book]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
"""
|
|
36
|
-
A nested book type
|
|
37
|
-
"""
|
|
38
|
-
input NestedBook {
|
|
39
|
-
"""
|
|
40
|
-
The date of the book
|
|
41
|
-
"""
|
|
42
|
-
date: String
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
"""
|
|
46
|
-
The input object for the getBook query
|
|
47
|
-
"""
|
|
48
|
-
input BookInput {
|
|
49
|
-
"""
|
|
50
|
-
The title of the book
|
|
51
|
-
"""
|
|
52
|
-
title: String
|
|
53
|
-
|
|
54
|
-
"""
|
|
55
|
-
The author of the book
|
|
56
|
-
"""
|
|
57
|
-
nestedBook: NestedBook
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
type Query {
|
|
61
|
-
# books: [Book]
|
|
62
|
-
# authors: [Author]
|
|
63
|
-
"""
|
|
64
|
-
Get a book by title
|
|
65
|
-
"""
|
|
66
|
-
getBook(
|
|
67
|
-
"""
|
|
68
|
-
The title of the book
|
|
69
|
-
"""
|
|
70
|
-
title: String
|
|
71
|
-
|
|
72
|
-
"""
|
|
73
|
-
The author of the book
|
|
74
|
-
"""
|
|
75
|
-
input: BookInput
|
|
76
|
-
): Book
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type Mutation {
|
|
80
|
-
"""
|
|
81
|
-
Add a book
|
|
82
|
-
"""
|
|
83
|
-
addBook(title: String, author: String): Book
|
|
84
|
-
|
|
85
|
-
"""
|
|
86
|
-
Add an author
|
|
87
|
-
"""
|
|
88
|
-
addAuthor(name: String): Author
|
|
89
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
# Define custom scalars for Date and ID
|
|
2
|
-
scalar Date
|
|
3
|
-
scalar ID
|
|
4
|
-
|
|
5
|
-
# Define the User type
|
|
6
|
-
"""
|
|
7
|
-
A user type representing a user in the system
|
|
8
|
-
"""
|
|
9
|
-
type User {
|
|
10
|
-
"""
|
|
11
|
-
The unique ID of the user
|
|
12
|
-
"""
|
|
13
|
-
id: ID!
|
|
14
|
-
|
|
15
|
-
"""
|
|
16
|
-
The name of the user
|
|
17
|
-
"""
|
|
18
|
-
name: String!
|
|
19
|
-
|
|
20
|
-
"""
|
|
21
|
-
The email of the user
|
|
22
|
-
"""
|
|
23
|
-
email: String!
|
|
24
|
-
|
|
25
|
-
"""
|
|
26
|
-
The list of todos created by the user
|
|
27
|
-
"""
|
|
28
|
-
todos: [Todo!]!
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
# Define the Todo type
|
|
32
|
-
"""
|
|
33
|
-
A todo type representing a task to be done
|
|
34
|
-
"""
|
|
35
|
-
type Todo {
|
|
36
|
-
"""
|
|
37
|
-
The unique ID of the todo
|
|
38
|
-
"""
|
|
39
|
-
id: ID!
|
|
40
|
-
|
|
41
|
-
"""
|
|
42
|
-
The title of the todo
|
|
43
|
-
"""
|
|
44
|
-
title: String!
|
|
45
|
-
|
|
46
|
-
"""
|
|
47
|
-
The description of the todo
|
|
48
|
-
"""
|
|
49
|
-
description: String
|
|
50
|
-
|
|
51
|
-
"""
|
|
52
|
-
The status of the todo (completed or not)
|
|
53
|
-
"""
|
|
54
|
-
completed: Boolean!
|
|
55
|
-
|
|
56
|
-
"""
|
|
57
|
-
The due date of the todo
|
|
58
|
-
"""
|
|
59
|
-
dueDate: Date
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
# Define input types for creating and updating todos
|
|
63
|
-
"""
|
|
64
|
-
Input type for creating a new todo
|
|
65
|
-
"""
|
|
66
|
-
input CreateTodoInput {
|
|
67
|
-
title: String!
|
|
68
|
-
description: String
|
|
69
|
-
dueDate: Date
|
|
70
|
-
userId: ID!
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
"""
|
|
74
|
-
Input type for updating an existing todo
|
|
75
|
-
"""
|
|
76
|
-
input UpdateTodoInput {
|
|
77
|
-
id: ID!
|
|
78
|
-
title: String
|
|
79
|
-
description: String
|
|
80
|
-
completed: Boolean
|
|
81
|
-
dueDate: Date
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
# Define the Query type
|
|
85
|
-
"""
|
|
86
|
-
---
|
|
87
|
-
title: Query
|
|
88
|
-
group: [Root Types]
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
The root query type
|
|
92
|
-
"""
|
|
93
|
-
type Query {
|
|
94
|
-
"""
|
|
95
|
-
---
|
|
96
|
-
title: Users
|
|
97
|
-
group: [GraphQL, Users]
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
Get a list of all users
|
|
101
|
-
"""
|
|
102
|
-
users: [User!]!
|
|
103
|
-
|
|
104
|
-
"""
|
|
105
|
-
---
|
|
106
|
-
title: User
|
|
107
|
-
group: [GraphQL, Users]
|
|
108
|
-
---
|
|
109
|
-
|
|
110
|
-
Get a user by ID
|
|
111
|
-
"""
|
|
112
|
-
user(id: ID!): User
|
|
113
|
-
|
|
114
|
-
"""
|
|
115
|
-
---
|
|
116
|
-
title: Todos
|
|
117
|
-
group: [GraphQL, Todos]
|
|
118
|
-
---
|
|
119
|
-
|
|
120
|
-
Get a list of all todos
|
|
121
|
-
"""
|
|
122
|
-
todos: [Todo!]!
|
|
123
|
-
|
|
124
|
-
"""
|
|
125
|
-
---
|
|
126
|
-
title: Todo
|
|
127
|
-
group: [GraphQL, Todos]
|
|
128
|
-
---
|
|
129
|
-
|
|
130
|
-
Get a todo by ID
|
|
131
|
-
"""
|
|
132
|
-
todo(id: ID!): Todo
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
# Define the Mutation type
|
|
136
|
-
"""
|
|
137
|
-
---
|
|
138
|
-
title: Mutation
|
|
139
|
-
group: [Root Types]
|
|
140
|
-
---
|
|
141
|
-
|
|
142
|
-
The root mutation type
|
|
143
|
-
"""
|
|
144
|
-
type Mutation {
|
|
145
|
-
"""
|
|
146
|
-
---
|
|
147
|
-
title: Create User
|
|
148
|
-
group: [GraphQL, Users]
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
Create a new user
|
|
152
|
-
"""
|
|
153
|
-
createUser(name: String!, email: String!): User!
|
|
154
|
-
|
|
155
|
-
"""
|
|
156
|
-
---
|
|
157
|
-
title: Create Todo
|
|
158
|
-
group: [GraphQL, Todos]
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
Create a new todo
|
|
162
|
-
"""
|
|
163
|
-
createTodo(input: CreateTodoInput!): Todo!
|
|
164
|
-
|
|
165
|
-
"""
|
|
166
|
-
---
|
|
167
|
-
title: Update Todo
|
|
168
|
-
group: [GraphQL, Todos]
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
Update an existing todo
|
|
172
|
-
"""
|
|
173
|
-
updateTodo(input: UpdateTodoInput!): Todo!
|
|
174
|
-
|
|
175
|
-
"""
|
|
176
|
-
---
|
|
177
|
-
title: Delete Todo
|
|
178
|
-
group: [GraphQL, Todos]
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
Delete a todo by ID
|
|
182
|
-
"""
|
|
183
|
-
deleteTodo(id: ID!): Boolean!
|
|
184
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
This is a custom scalar type for Date.
|
|
3
|
-
"""
|
|
4
|
-
scalar Date
|
|
5
|
-
|
|
6
|
-
"""
|
|
7
|
-
This is a custom enum type for Role.
|
|
8
|
-
"""
|
|
9
|
-
enum Role {
|
|
10
|
-
ADMIN
|
|
11
|
-
OWNER
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
"""
|
|
15
|
-
This is a custom input type for Book.
|
|
16
|
-
"""
|
|
17
|
-
input BookInput {
|
|
18
|
-
title: String!
|
|
19
|
-
author: String!
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
"""
|
|
23
|
-
This is a custom type for Book.
|
|
24
|
-
"""
|
|
25
|
-
type Book {
|
|
26
|
-
title: String!
|
|
27
|
-
author: String!
|
|
28
|
-
}
|
package/src/hydration/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
`hydration` converts a GraphQL into XYD `uniform` format.
|
package/src/hydration/gql-arg.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {GraphQLArgument} from "graphql/type/definition";
|
|
2
|
-
import {GraphQLInputObjectType} from "graphql/type";
|
|
3
|
-
|
|
4
|
-
import {DefinitionProperty} from "@xyd-js/uniform";
|
|
5
|
-
|
|
6
|
-
import {gqlInputToUniformDefinitionProperty} from "./gql-input";
|
|
7
|
-
|
|
8
|
-
// gqlArgToUniformDefinitionProperty converts GraphQL arguments into xyd 'uniform' definition properties
|
|
9
|
-
export function gqlArgToUniformDefinitionProperty(
|
|
10
|
-
args: readonly GraphQLArgument[]
|
|
11
|
-
): DefinitionProperty[] {
|
|
12
|
-
const resp: DefinitionProperty[] = []
|
|
13
|
-
|
|
14
|
-
args.forEach(arg => {
|
|
15
|
-
let obj: GraphQLInputObjectType | null = null
|
|
16
|
-
|
|
17
|
-
switch (arg.type.constructor.name) {
|
|
18
|
-
case "GraphQLNonNull": {
|
|
19
|
-
if ("ofType" in arg.type) {
|
|
20
|
-
const ofType = arg.type?.ofType
|
|
21
|
-
|
|
22
|
-
if (ofType?.constructor.name === "GraphQLInputObjectType") {
|
|
23
|
-
obj = ofType as GraphQLInputObjectType
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
break
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
case "GraphQLInputObjectType" : {
|
|
30
|
-
obj = arg.type as GraphQLInputObjectType
|
|
31
|
-
|
|
32
|
-
break
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
default: {
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!obj) {
|
|
40
|
-
console.error("unsupported argument type", arg.type.constructor.name)
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
resp.push(gqlInputToUniformDefinitionProperty(
|
|
45
|
-
arg.name,
|
|
46
|
-
arg.description || "",
|
|
47
|
-
obj
|
|
48
|
-
))
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
return resp
|
|
52
|
-
}
|
|
53
|
-
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GraphQLField,
|
|
3
|
-
GraphQLFieldMap,
|
|
4
|
-
GraphQLInputField,
|
|
5
|
-
GraphQLInputFieldMap,
|
|
6
|
-
GraphQLInputObjectType
|
|
7
|
-
} from "graphql/type";
|
|
8
|
-
import {GraphQLObjectType, GraphQLNamedType} from "graphql";
|
|
9
|
-
|
|
10
|
-
import {DefinitionProperty} from "@xyd-js/uniform";
|
|
11
|
-
import {isIntrospectionType, isSpecifiedScalarType} from "graphql/index";
|
|
12
|
-
|
|
13
|
-
// gqlFieldToUniformDefinitionProperty converts GraphQL fields (field or input field) into xyd 'uniform' definition property
|
|
14
|
-
export function gqlFieldToUniformDefinitionProperty(
|
|
15
|
-
fieldName: string,
|
|
16
|
-
field: GraphQLField<any, any> | GraphQLInputField,
|
|
17
|
-
): DefinitionProperty {
|
|
18
|
-
let properties;
|
|
19
|
-
let graphqlTypeFlat: GraphQLNamedType | null = null
|
|
20
|
-
|
|
21
|
-
// if 'ofType' types (non-null values e.g '!<type>')
|
|
22
|
-
if ("ofType" in field.type) {
|
|
23
|
-
switch (field.type.constructor.name) {
|
|
24
|
-
case "GraphQLList": {
|
|
25
|
-
switch (field.type.ofType.constructor.name) {
|
|
26
|
-
case "GraphQLObjectType": {
|
|
27
|
-
const objectType = field.type.ofType as GraphQLObjectType
|
|
28
|
-
|
|
29
|
-
properties = nestedProperties(objectType)
|
|
30
|
-
graphqlTypeFlat = objectType
|
|
31
|
-
|
|
32
|
-
break
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
case "GraphQLInputObjectType": {
|
|
36
|
-
const inputObjectType = field.type.ofType as GraphQLInputObjectType
|
|
37
|
-
|
|
38
|
-
properties = nestedProperties(inputObjectType)
|
|
39
|
-
graphqlTypeFlat = inputObjectType
|
|
40
|
-
|
|
41
|
-
break
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
case "GraphQLScalarType": {
|
|
45
|
-
properties = definitionPropsFromNestedObj(field) || []
|
|
46
|
-
graphqlTypeFlat = field.type.ofType as GraphQLNamedType
|
|
47
|
-
|
|
48
|
-
break
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
case "GraphQLNonNull": {
|
|
52
|
-
properties = definitionPropsFromNestedObj(field) || []
|
|
53
|
-
|
|
54
|
-
if ("ofType" in field.type.ofType) {
|
|
55
|
-
graphqlTypeFlat = field.type.ofType.ofType as GraphQLNamedType
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
break
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
default: {
|
|
62
|
-
console.error("unsupported ofType list", field.type.ofType.constructor.name)
|
|
63
|
-
break
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
break
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
case "GraphQLNonNull": {
|
|
72
|
-
properties = definitionPropsFromNestedObj(field) || []
|
|
73
|
-
graphqlTypeFlat = field.type.ofType as GraphQLNamedType
|
|
74
|
-
|
|
75
|
-
break
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
default: {
|
|
79
|
-
console.error("unsupported ofType", field.type.constructor.name)
|
|
80
|
-
|
|
81
|
-
break
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// if regular object type
|
|
88
|
-
else if (field.type.constructor.name === "GraphQLObjectType") {
|
|
89
|
-
const objectType = field.type as GraphQLObjectType
|
|
90
|
-
graphqlTypeFlat = field.type
|
|
91
|
-
|
|
92
|
-
// TODO: support nested & circular references - ITS JUST A FAST SOLUTION FOR TESTING PURPOSES
|
|
93
|
-
// properties = [
|
|
94
|
-
// {
|
|
95
|
-
// name: fieldName,
|
|
96
|
-
// type: "object",
|
|
97
|
-
// description: objectType.description || "",
|
|
98
|
-
// }
|
|
99
|
-
// ]
|
|
100
|
-
|
|
101
|
-
// TODO: comment if bug with circular references
|
|
102
|
-
properties = nestedProperties(objectType)
|
|
103
|
-
} else if (field.type.constructor.name === "GraphQLInputObjectType") {
|
|
104
|
-
const objectType = field.type as GraphQLInputObjectType
|
|
105
|
-
|
|
106
|
-
graphqlTypeFlat = field.type
|
|
107
|
-
properties = nestedProperties(objectType)
|
|
108
|
-
} else if (field.type.constructor.name === "GraphQLScalarType") {
|
|
109
|
-
graphqlTypeFlat = field.type
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
switch (graphqlTypeFlat?.constructor?.name) {
|
|
114
|
-
case "GraphQLList": {
|
|
115
|
-
if ("ofType" in graphqlTypeFlat) {
|
|
116
|
-
graphqlTypeFlat = graphqlTypeFlat.ofType as GraphQLNamedType
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const builtInType = graphqlTypeFlat ? (isSpecifiedScalarType(graphqlTypeFlat) ||
|
|
122
|
-
isIntrospectionType(graphqlTypeFlat)
|
|
123
|
-
) : undefined
|
|
124
|
-
|
|
125
|
-
let graphqlTypeShort = ""
|
|
126
|
-
|
|
127
|
-
switch (graphqlTypeFlat?.constructor?.name) {
|
|
128
|
-
case "GraphQLObjectType": {
|
|
129
|
-
graphqlTypeShort = "object"
|
|
130
|
-
|
|
131
|
-
break
|
|
132
|
-
}
|
|
133
|
-
case "GraphQLInputObjectType": {
|
|
134
|
-
graphqlTypeShort = "input"
|
|
135
|
-
|
|
136
|
-
break
|
|
137
|
-
}
|
|
138
|
-
case "GraphQLScalarType": {
|
|
139
|
-
graphqlTypeShort = "scalar"
|
|
140
|
-
|
|
141
|
-
break
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
name: fieldName,
|
|
147
|
-
type: field.type.toJSON(),
|
|
148
|
-
context: {
|
|
149
|
-
graphqlBuiltInType: builtInType,
|
|
150
|
-
graphqlName: fieldName,
|
|
151
|
-
graphqlTypeFlat: graphqlTypeFlat && graphqlTypeFlat.toJSON(),
|
|
152
|
-
graphqlTypeShort,
|
|
153
|
-
},
|
|
154
|
-
description: field.description || "",
|
|
155
|
-
properties,
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// TODO: fix any + another more safety solution?
|
|
160
|
-
// definitionPropsFromNestedObj converts graphql nested obj into xyd 'uniform' definition properties
|
|
161
|
-
function definitionPropsFromNestedObj(obj: any): DefinitionProperty[] | null {
|
|
162
|
-
if (!obj) {
|
|
163
|
-
return null
|
|
164
|
-
}
|
|
165
|
-
if (obj.getFields) {
|
|
166
|
-
return nestedProperties(obj)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (obj.ofType) {
|
|
170
|
-
return definitionPropsFromNestedObj(obj.ofType)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (obj.type) {
|
|
174
|
-
return definitionPropsFromNestedObj(obj.type)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return null
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// deepFieldMap iterates over GraphQL field (field or input fields) maps
|
|
181
|
-
function deepFieldMap(
|
|
182
|
-
fieldsMap: GraphQLFieldMap<any, any> | GraphQLInputFieldMap,
|
|
183
|
-
) {
|
|
184
|
-
const properties: DefinitionProperty[] = []
|
|
185
|
-
|
|
186
|
-
for (const [name, field] of Object.entries(fieldsMap)) {
|
|
187
|
-
const prop = gqlFieldToUniformDefinitionProperty(
|
|
188
|
-
name,
|
|
189
|
-
field,
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
if (prop) {
|
|
193
|
-
properties.push(prop)
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return properties
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// nestedProperties get fields from object or input object types and iterates over them
|
|
201
|
-
function nestedProperties(objectType: GraphQLObjectType | GraphQLInputObjectType) {
|
|
202
|
-
const nestedFields = objectType?.getFields?.()
|
|
203
|
-
|
|
204
|
-
return deepFieldMap(nestedFields)
|
|
205
|
-
}
|
|
206
|
-
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {GraphQLInputObjectType} from "graphql/type";
|
|
2
|
-
|
|
3
|
-
import {DefinitionProperty, Reference} from "@xyd-js/uniform";
|
|
4
|
-
|
|
5
|
-
import {gqlFieldToUniformDefinitionProperty} from "./gql-field";
|
|
6
|
-
|
|
7
|
-
// gqlInputToUniformRef is a helper function to convert a GraphQL input object type into a 'uniform' reference.
|
|
8
|
-
export function gqlInputToUniformRef(gqlType: GraphQLInputObjectType): Reference {
|
|
9
|
-
const prop = gqlInputToUniformDefinitionProperty(
|
|
10
|
-
gqlType.name,
|
|
11
|
-
gqlType.description || "",
|
|
12
|
-
gqlType
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
title: gqlType.name,
|
|
17
|
-
description: gqlType.description || "",
|
|
18
|
-
canonical: `input-${gqlType.name}`, // TODO: better solution
|
|
19
|
-
context: {
|
|
20
|
-
graphqlName: gqlType.name,
|
|
21
|
-
graphqlTypeShort: "input" // TODO: better solution
|
|
22
|
-
},
|
|
23
|
-
definitions: [
|
|
24
|
-
{
|
|
25
|
-
title: "Fields",
|
|
26
|
-
properties: prop.properties || []
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
examples: {
|
|
30
|
-
groups: []
|
|
31
|
-
}
|
|
32
|
-
} as Reference
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// gqlInputToUniformDefinitionProperty is a helper function to convert a GraphQL input object into a xyd definition property.
|
|
36
|
-
export function gqlInputToUniformDefinitionProperty(
|
|
37
|
-
name: string,
|
|
38
|
-
description: string,
|
|
39
|
-
obj: GraphQLInputObjectType
|
|
40
|
-
) {
|
|
41
|
-
const inputFields = obj.getFields?.()
|
|
42
|
-
|
|
43
|
-
const nestedProps: DefinitionProperty[] = []
|
|
44
|
-
const nestedDefinitionProperty: DefinitionProperty = {
|
|
45
|
-
name: name,
|
|
46
|
-
type: obj.toJSON(),
|
|
47
|
-
description: description || "",
|
|
48
|
-
context: {
|
|
49
|
-
graphqlName: name,
|
|
50
|
-
graphqlTypeShort: "input"
|
|
51
|
-
},
|
|
52
|
-
properties: nestedProps,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
for (const [name, inputField] of Object.entries(inputFields)) {
|
|
56
|
-
const prop = gqlFieldToUniformDefinitionProperty(
|
|
57
|
-
name,
|
|
58
|
-
inputField,
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
if (prop) {
|
|
62
|
-
nestedProps.push(prop)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return nestedDefinitionProperty
|
|
67
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {GraphQLObjectType} from "graphql";
|
|
2
|
-
|
|
3
|
-
import type {DefinitionProperty} from "@xyd-js/uniform";
|
|
4
|
-
|
|
5
|
-
import {gqlFieldToUniformDefinitionProperty} from "./gql-field";
|
|
6
|
-
|
|
7
|
-
// gqlObjectToUniformRef is a helper function to convert a GraphQL object type into a 'uniform' reference.
|
|
8
|
-
export function gqlObjectToUniformRef(gqlType: GraphQLObjectType) {
|
|
9
|
-
const props: DefinitionProperty[] = []
|
|
10
|
-
|
|
11
|
-
for (const [name, field] of Object.entries(gqlType.getFields())) {
|
|
12
|
-
const prop = gqlFieldToUniformDefinitionProperty(name, field)
|
|
13
|
-
|
|
14
|
-
props.push(prop)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
title: gqlType.name,
|
|
19
|
-
description: gqlType.description || "",
|
|
20
|
-
canonical: `object-${gqlType.name}`, // TODO: better solution
|
|
21
|
-
context: {
|
|
22
|
-
graphqlName: gqlType.name,
|
|
23
|
-
graphqlTypeShort: "object" // TODO: better solution
|
|
24
|
-
},
|
|
25
|
-
definitions: [
|
|
26
|
-
{
|
|
27
|
-
title: "Fields",
|
|
28
|
-
properties: props
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
examples: {
|
|
32
|
-
groups: []
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|