@tinacms/app 2.2.2 → 2.2.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/CHANGELOG.md +13 -6
- package/package.json +2 -2
- package/src/App.tsx +24 -24
- package/src/Playground.tsx +54 -54
- package/src/dummy-client.ts +1 -1
- package/src/fields/rich-text/index.tsx +2 -2
- package/src/fields/rich-text/monaco/error-message.tsx +54 -54
- package/src/fields/rich-text/monaco/index.tsx +56 -56
- package/src/fields/rich-text/monaco/use-debounce.ts +8 -8
- package/src/global.css +3 -3
- package/src/index.css +15 -15
- package/src/lib/build-form.ts +24 -24
- package/src/lib/errors.tsx +7 -7
- package/src/lib/expand-query.ts +66 -61
- package/src/lib/graphql-reducer.ts +272 -265
- package/src/lib/types.ts +34 -34
- package/src/lib/util.ts +41 -41
- package/src/main.tsx +7 -7
- package/src/preflight.css +10 -10
- package/src/preview.tsx +12 -12
- package/src/vite-env.d.ts +3 -3
package/src/lib/expand-query.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import * as G from 'graphql'
|
|
1
|
+
import * as G from 'graphql';
|
|
2
2
|
|
|
3
3
|
export const expandQuery = ({
|
|
4
4
|
schema,
|
|
5
5
|
documentNode,
|
|
6
6
|
}: {
|
|
7
|
-
schema: G.GraphQLSchema
|
|
8
|
-
documentNode: G.DocumentNode
|
|
7
|
+
schema: G.GraphQLSchema;
|
|
8
|
+
documentNode: G.DocumentNode;
|
|
9
9
|
}): G.DocumentNode => {
|
|
10
|
-
const documentNodeWithTypenames = addTypenameToDocument(documentNode)
|
|
11
|
-
return addMetaFieldsToQuery(
|
|
12
|
-
|
|
10
|
+
const documentNodeWithTypenames = addTypenameToDocument(documentNode);
|
|
11
|
+
return addMetaFieldsToQuery(
|
|
12
|
+
documentNodeWithTypenames,
|
|
13
|
+
new G.TypeInfo(schema)
|
|
14
|
+
);
|
|
15
|
+
};
|
|
13
16
|
|
|
14
17
|
const addTypenameToDocument = (doc: G.DocumentNode) => {
|
|
15
18
|
function isField(selection: G.SelectionNode): selection is G.FieldNode {
|
|
16
|
-
return selection.kind === 'Field'
|
|
19
|
+
return selection.kind === 'Field';
|
|
17
20
|
}
|
|
18
21
|
return G.visit(doc, {
|
|
19
22
|
SelectionSet: {
|
|
@@ -24,13 +27,13 @@ const addTypenameToDocument = (doc: G.DocumentNode) => {
|
|
|
24
27
|
(parent as G.OperationDefinitionNode).kind ===
|
|
25
28
|
G.Kind.OPERATION_DEFINITION
|
|
26
29
|
) {
|
|
27
|
-
return
|
|
30
|
+
return;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
// No changes if no selections.
|
|
31
|
-
const { selections } = node
|
|
34
|
+
const { selections } = node;
|
|
32
35
|
if (!selections) {
|
|
33
|
-
return
|
|
36
|
+
return;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
// If selections already have a __typename, or are part of an
|
|
@@ -40,32 +43,32 @@ const addTypenameToDocument = (doc: G.DocumentNode) => {
|
|
|
40
43
|
isField(selection) &&
|
|
41
44
|
(selection.name.value === '__typename' ||
|
|
42
45
|
selection.name.value.lastIndexOf('__', 0) === 0)
|
|
43
|
-
)
|
|
44
|
-
})
|
|
46
|
+
);
|
|
47
|
+
});
|
|
45
48
|
if (skip) {
|
|
46
|
-
return
|
|
49
|
+
return;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
// If this SelectionSet is @export-ed as an input variable, it should
|
|
50
53
|
// not have a __typename field (see issue #4691).
|
|
51
|
-
const field = parent as G.FieldNode
|
|
54
|
+
const field = parent as G.FieldNode;
|
|
52
55
|
if (
|
|
53
56
|
isField(field) &&
|
|
54
57
|
field.directives &&
|
|
55
58
|
field.directives.some((d) => d.name.value === 'export')
|
|
56
59
|
) {
|
|
57
|
-
return
|
|
60
|
+
return;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
// Create and return a new SelectionSet with a __typename Field.
|
|
61
64
|
return {
|
|
62
65
|
...node,
|
|
63
66
|
selections: [...selections, TYPENAME_FIELD],
|
|
64
|
-
}
|
|
67
|
+
};
|
|
65
68
|
},
|
|
66
69
|
},
|
|
67
|
-
})
|
|
68
|
-
}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
69
72
|
|
|
70
73
|
const CONTENT_SOURCE_FIELD: G.FieldNode = {
|
|
71
74
|
kind: G.Kind.FIELD,
|
|
@@ -73,14 +76,14 @@ const CONTENT_SOURCE_FIELD: G.FieldNode = {
|
|
|
73
76
|
kind: G.Kind.NAME,
|
|
74
77
|
value: '_content_source',
|
|
75
78
|
},
|
|
76
|
-
}
|
|
79
|
+
};
|
|
77
80
|
const METADATA_FIELD: G.FieldNode = {
|
|
78
81
|
kind: G.Kind.FIELD,
|
|
79
82
|
name: {
|
|
80
83
|
kind: G.Kind.NAME,
|
|
81
84
|
value: '_tina_metadata',
|
|
82
85
|
},
|
|
83
|
-
}
|
|
86
|
+
};
|
|
84
87
|
|
|
85
88
|
const TYPENAME_FIELD: G.FieldNode = {
|
|
86
89
|
kind: G.Kind.FIELD,
|
|
@@ -88,7 +91,7 @@ const TYPENAME_FIELD: G.FieldNode = {
|
|
|
88
91
|
kind: G.Kind.NAME,
|
|
89
92
|
value: '__typename',
|
|
90
93
|
},
|
|
91
|
-
}
|
|
94
|
+
};
|
|
92
95
|
|
|
93
96
|
const addMetadataField = (
|
|
94
97
|
node: G.FieldNode | G.InlineFragmentNode | G.FragmentDefinitionNode
|
|
@@ -107,8 +110,8 @@ const addMetadataField = (
|
|
|
107
110
|
CONTENT_SOURCE_FIELD,
|
|
108
111
|
] || [],
|
|
109
112
|
},
|
|
110
|
-
}
|
|
111
|
-
}
|
|
113
|
+
};
|
|
114
|
+
};
|
|
112
115
|
|
|
113
116
|
const addMetaFieldsToQuery = (
|
|
114
117
|
documentNode: G.DocumentNode,
|
|
@@ -127,62 +130,62 @@ const addMetaFieldsToQuery = (
|
|
|
127
130
|
selections:
|
|
128
131
|
[...(node.selectionSet?.selections || []), ...metaFields] || [],
|
|
129
132
|
},
|
|
130
|
-
}
|
|
131
|
-
}
|
|
133
|
+
};
|
|
134
|
+
};
|
|
132
135
|
|
|
133
136
|
const formifyVisitor: G.Visitor<G.ASTKindToNode, G.ASTNode> = {
|
|
134
137
|
FragmentDefinition: {
|
|
135
138
|
enter: (node, key, parent, path, ancestors) => {
|
|
136
|
-
typeInfo.enter(node)
|
|
137
|
-
const type = typeInfo.getType()
|
|
139
|
+
typeInfo.enter(node);
|
|
140
|
+
const type = typeInfo.getType();
|
|
138
141
|
if (type) {
|
|
139
|
-
const namedType = G.getNamedType(type)
|
|
142
|
+
const namedType = G.getNamedType(type);
|
|
140
143
|
if (G.isObjectType(namedType)) {
|
|
141
144
|
if (namedType.getFields()['_tina_metadata']) {
|
|
142
|
-
return addMetadataField(node)
|
|
145
|
+
return addMetadataField(node);
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
|
-
return node
|
|
148
|
+
return node;
|
|
146
149
|
}
|
|
147
150
|
},
|
|
148
151
|
},
|
|
149
152
|
InlineFragment: {
|
|
150
153
|
enter: (node, key, parent, path, ancestors) => {
|
|
151
|
-
typeInfo.enter(node)
|
|
152
|
-
const type = typeInfo.getType()
|
|
154
|
+
typeInfo.enter(node);
|
|
155
|
+
const type = typeInfo.getType();
|
|
153
156
|
if (type) {
|
|
154
|
-
const namedType = G.getNamedType(type)
|
|
157
|
+
const namedType = G.getNamedType(type);
|
|
155
158
|
if (G.isObjectType(namedType)) {
|
|
156
159
|
if (namedType.getFields()['_tina_metadata']) {
|
|
157
|
-
return addMetadataField(node)
|
|
160
|
+
return addMetadataField(node);
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
|
-
return node
|
|
163
|
+
return node;
|
|
161
164
|
}
|
|
162
165
|
},
|
|
163
166
|
},
|
|
164
167
|
Field: {
|
|
165
168
|
enter: (node, key, parent, path, ancestors) => {
|
|
166
|
-
typeInfo.enter(node)
|
|
167
|
-
const type = typeInfo.getType()
|
|
169
|
+
typeInfo.enter(node);
|
|
170
|
+
const type = typeInfo.getType();
|
|
168
171
|
if (type) {
|
|
169
172
|
if (isNodeType(type)) {
|
|
170
|
-
return addMetaFields(node, key, parent, path, ancestors)
|
|
173
|
+
return addMetaFields(node, key, parent, path, ancestors);
|
|
171
174
|
}
|
|
172
|
-
const namedType = G.getNamedType(type)
|
|
175
|
+
const namedType = G.getNamedType(type);
|
|
173
176
|
if (G.isObjectType(namedType)) {
|
|
174
177
|
if (namedType.getFields()['_tina_metadata']) {
|
|
175
|
-
return addMetadataField(node)
|
|
178
|
+
return addMetadataField(node);
|
|
176
179
|
}
|
|
177
|
-
return node
|
|
180
|
+
return node;
|
|
178
181
|
}
|
|
179
182
|
}
|
|
180
|
-
return node
|
|
183
|
+
return node;
|
|
181
184
|
},
|
|
182
185
|
},
|
|
183
|
-
}
|
|
184
|
-
return G.visit(documentNode, G.visitWithTypeInfo(typeInfo, formifyVisitor))
|
|
185
|
-
}
|
|
186
|
+
};
|
|
187
|
+
return G.visit(documentNode, G.visitWithTypeInfo(typeInfo, formifyVisitor));
|
|
188
|
+
};
|
|
186
189
|
/**
|
|
187
190
|
* This is a dummy query which we pull apart and spread
|
|
188
191
|
* back into the the selectionSet for all "Node" fields
|
|
@@ -212,57 +215,59 @@ const node = G.parse(`
|
|
|
212
215
|
}
|
|
213
216
|
}
|
|
214
217
|
}
|
|
215
|
-
}`)
|
|
218
|
+
}`);
|
|
216
219
|
const metaFields: G.SelectionNode[] =
|
|
217
220
|
// @ts-ignore
|
|
218
|
-
node.definitions[0].selectionSet.selections
|
|
221
|
+
node.definitions[0].selectionSet.selections;
|
|
219
222
|
|
|
220
223
|
export const isNodeType = (type: G.GraphQLOutputType) => {
|
|
221
|
-
const namedType = G.getNamedType(type)
|
|
224
|
+
const namedType = G.getNamedType(type);
|
|
222
225
|
if (G.isInterfaceType(namedType)) {
|
|
223
226
|
if (namedType.name === 'Node') {
|
|
224
|
-
return true
|
|
227
|
+
return true;
|
|
225
228
|
}
|
|
226
229
|
}
|
|
227
230
|
if (G.isUnionType(namedType)) {
|
|
228
|
-
const types = namedType.getTypes()
|
|
231
|
+
const types = namedType.getTypes();
|
|
229
232
|
if (
|
|
230
233
|
types.every((type) => {
|
|
231
|
-
return type.getInterfaces().some((intfc) => intfc.name === 'Node')
|
|
234
|
+
return type.getInterfaces().some((intfc) => intfc.name === 'Node');
|
|
232
235
|
})
|
|
233
236
|
) {
|
|
234
|
-
return true
|
|
237
|
+
return true;
|
|
235
238
|
}
|
|
236
239
|
}
|
|
237
240
|
if (G.isObjectType(namedType)) {
|
|
238
241
|
if (namedType.getInterfaces().some((intfc) => intfc.name === 'Node')) {
|
|
239
|
-
return true
|
|
242
|
+
return true;
|
|
240
243
|
}
|
|
241
244
|
}
|
|
242
|
-
}
|
|
245
|
+
};
|
|
243
246
|
|
|
244
247
|
export const isConnectionType = (type: G.GraphQLOutputType) => {
|
|
245
|
-
const namedType = G.getNamedType(type)
|
|
248
|
+
const namedType = G.getNamedType(type);
|
|
246
249
|
if (G.isInterfaceType(namedType)) {
|
|
247
250
|
if (namedType.name === 'Connection') {
|
|
248
|
-
return true
|
|
251
|
+
return true;
|
|
249
252
|
}
|
|
250
253
|
}
|
|
251
254
|
if (G.isUnionType(namedType)) {
|
|
252
|
-
const types = namedType.getTypes()
|
|
255
|
+
const types = namedType.getTypes();
|
|
253
256
|
if (
|
|
254
257
|
types.every((type) => {
|
|
255
|
-
return type
|
|
258
|
+
return type
|
|
259
|
+
.getInterfaces()
|
|
260
|
+
.some((intfc) => intfc.name === 'Connection');
|
|
256
261
|
})
|
|
257
262
|
) {
|
|
258
|
-
return true
|
|
263
|
+
return true;
|
|
259
264
|
}
|
|
260
265
|
}
|
|
261
266
|
if (G.isObjectType(namedType)) {
|
|
262
267
|
if (
|
|
263
268
|
namedType.getInterfaces().some((intfc) => intfc.name === 'Connection')
|
|
264
269
|
) {
|
|
265
|
-
return true
|
|
270
|
+
return true;
|
|
266
271
|
}
|
|
267
272
|
}
|
|
268
|
-
}
|
|
273
|
+
};
|