@tinacms/app 0.0.0-d7c745e-20250102002342 → 0.0.0-d94de9b-20250707010010
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 +137 -11
- package/package.json +13 -11
- package/src/App.tsx +24 -24
- package/src/Playground.tsx +56 -56
- 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 +59 -59
- package/src/fields/rich-text/monaco/index.tsx +59 -61
- 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 +74 -69
- package/src/lib/graphql-reducer.ts +301 -276
- package/src/lib/types.ts +35 -33
- package/src/lib/util.ts +48 -53
- 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
|
|
@@ -100,15 +103,14 @@ const addMetadataField = (
|
|
|
100
103
|
kind: 'SelectionSet',
|
|
101
104
|
selections: [],
|
|
102
105
|
}),
|
|
103
|
-
selections:
|
|
104
|
-
[
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
] || [],
|
|
106
|
+
selections: [
|
|
107
|
+
...(node.selectionSet?.selections || []),
|
|
108
|
+
METADATA_FIELD,
|
|
109
|
+
CONTENT_SOURCE_FIELD,
|
|
110
|
+
],
|
|
109
111
|
},
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
+
};
|
|
113
|
+
};
|
|
112
114
|
|
|
113
115
|
const addMetaFieldsToQuery = (
|
|
114
116
|
documentNode: G.DocumentNode,
|
|
@@ -124,65 +126,64 @@ const addMetaFieldsToQuery = (
|
|
|
124
126
|
kind: 'SelectionSet',
|
|
125
127
|
selections: [],
|
|
126
128
|
}),
|
|
127
|
-
selections:
|
|
128
|
-
[...(node.selectionSet?.selections || []), ...metaFields] || [],
|
|
129
|
+
selections: [...(node.selectionSet?.selections || []), ...metaFields],
|
|
129
130
|
},
|
|
130
|
-
}
|
|
131
|
-
}
|
|
131
|
+
};
|
|
132
|
+
};
|
|
132
133
|
|
|
133
134
|
const formifyVisitor: G.Visitor<G.ASTKindToNode, G.ASTNode> = {
|
|
134
135
|
FragmentDefinition: {
|
|
135
136
|
enter: (node, key, parent, path, ancestors) => {
|
|
136
|
-
typeInfo.enter(node)
|
|
137
|
-
const type = typeInfo.getType()
|
|
137
|
+
typeInfo.enter(node);
|
|
138
|
+
const type = typeInfo.getType();
|
|
138
139
|
if (type) {
|
|
139
|
-
const namedType = G.getNamedType(type)
|
|
140
|
+
const namedType = G.getNamedType(type);
|
|
140
141
|
if (G.isObjectType(namedType)) {
|
|
141
142
|
if (namedType.getFields()['_tina_metadata']) {
|
|
142
|
-
return addMetadataField(node)
|
|
143
|
+
return addMetadataField(node);
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
|
-
return node
|
|
146
|
+
return node;
|
|
146
147
|
}
|
|
147
148
|
},
|
|
148
149
|
},
|
|
149
150
|
InlineFragment: {
|
|
150
151
|
enter: (node, key, parent, path, ancestors) => {
|
|
151
|
-
typeInfo.enter(node)
|
|
152
|
-
const type = typeInfo.getType()
|
|
152
|
+
typeInfo.enter(node);
|
|
153
|
+
const type = typeInfo.getType();
|
|
153
154
|
if (type) {
|
|
154
|
-
const namedType = G.getNamedType(type)
|
|
155
|
+
const namedType = G.getNamedType(type);
|
|
155
156
|
if (G.isObjectType(namedType)) {
|
|
156
157
|
if (namedType.getFields()['_tina_metadata']) {
|
|
157
|
-
return addMetadataField(node)
|
|
158
|
+
return addMetadataField(node);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
|
-
return node
|
|
161
|
+
return node;
|
|
161
162
|
}
|
|
162
163
|
},
|
|
163
164
|
},
|
|
164
165
|
Field: {
|
|
165
166
|
enter: (node, key, parent, path, ancestors) => {
|
|
166
|
-
typeInfo.enter(node)
|
|
167
|
-
const type = typeInfo.getType()
|
|
167
|
+
typeInfo.enter(node);
|
|
168
|
+
const type = typeInfo.getType();
|
|
168
169
|
if (type) {
|
|
169
170
|
if (isNodeType(type)) {
|
|
170
|
-
return addMetaFields(node, key, parent, path, ancestors)
|
|
171
|
+
return addMetaFields(node, key, parent, path, ancestors);
|
|
171
172
|
}
|
|
172
|
-
const namedType = G.getNamedType(type)
|
|
173
|
+
const namedType = G.getNamedType(type);
|
|
173
174
|
if (G.isObjectType(namedType)) {
|
|
174
175
|
if (namedType.getFields()['_tina_metadata']) {
|
|
175
|
-
return addMetadataField(node)
|
|
176
|
+
return addMetadataField(node);
|
|
176
177
|
}
|
|
177
|
-
return node
|
|
178
|
+
return node;
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
|
-
return node
|
|
181
|
+
return node;
|
|
181
182
|
},
|
|
182
183
|
},
|
|
183
|
-
}
|
|
184
|
-
return G.visit(documentNode, G.visitWithTypeInfo(typeInfo, formifyVisitor))
|
|
185
|
-
}
|
|
184
|
+
};
|
|
185
|
+
return G.visit(documentNode, G.visitWithTypeInfo(typeInfo, formifyVisitor));
|
|
186
|
+
};
|
|
186
187
|
/**
|
|
187
188
|
* This is a dummy query which we pull apart and spread
|
|
188
189
|
* back into the the selectionSet for all "Node" fields
|
|
@@ -212,57 +213,61 @@ const node = G.parse(`
|
|
|
212
213
|
}
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
|
-
}`)
|
|
216
|
+
}`);
|
|
216
217
|
const metaFields: G.SelectionNode[] =
|
|
217
218
|
// @ts-ignore
|
|
218
|
-
node.definitions[0].selectionSet.selections
|
|
219
|
+
node.definitions[0].selectionSet.selections;
|
|
219
220
|
|
|
220
221
|
export const isNodeType = (type: G.GraphQLOutputType) => {
|
|
221
|
-
const namedType = G.getNamedType(type)
|
|
222
|
+
const namedType = G.getNamedType(type);
|
|
222
223
|
if (G.isInterfaceType(namedType)) {
|
|
223
224
|
if (namedType.name === 'Node') {
|
|
224
|
-
return true
|
|
225
|
+
return true;
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
if (G.isUnionType(namedType)) {
|
|
228
|
-
const types = namedType.getTypes()
|
|
229
|
+
const types = namedType.getTypes();
|
|
229
230
|
if (
|
|
230
231
|
types.every((type) => {
|
|
231
|
-
return type.getInterfaces().some((intfc) => intfc.name === 'Node')
|
|
232
|
+
return type.getInterfaces().some((intfc) => intfc.name === 'Node');
|
|
232
233
|
})
|
|
233
234
|
) {
|
|
234
|
-
return true
|
|
235
|
+
return true;
|
|
235
236
|
}
|
|
236
237
|
}
|
|
237
238
|
if (G.isObjectType(namedType)) {
|
|
238
239
|
if (namedType.getInterfaces().some((intfc) => intfc.name === 'Node')) {
|
|
239
|
-
return true
|
|
240
|
+
return true;
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
|
-
|
|
243
|
+
return false;
|
|
244
|
+
};
|
|
243
245
|
|
|
244
246
|
export const isConnectionType = (type: G.GraphQLOutputType) => {
|
|
245
|
-
const namedType = G.getNamedType(type)
|
|
247
|
+
const namedType = G.getNamedType(type);
|
|
246
248
|
if (G.isInterfaceType(namedType)) {
|
|
247
249
|
if (namedType.name === 'Connection') {
|
|
248
|
-
return true
|
|
250
|
+
return true;
|
|
249
251
|
}
|
|
250
252
|
}
|
|
251
253
|
if (G.isUnionType(namedType)) {
|
|
252
|
-
const types = namedType.getTypes()
|
|
254
|
+
const types = namedType.getTypes();
|
|
253
255
|
if (
|
|
254
256
|
types.every((type) => {
|
|
255
|
-
return type
|
|
257
|
+
return type
|
|
258
|
+
.getInterfaces()
|
|
259
|
+
.some((intfc) => intfc.name === 'Connection');
|
|
256
260
|
})
|
|
257
261
|
) {
|
|
258
|
-
return true
|
|
262
|
+
return true;
|
|
259
263
|
}
|
|
260
264
|
}
|
|
261
265
|
if (G.isObjectType(namedType)) {
|
|
262
266
|
if (
|
|
263
267
|
namedType.getInterfaces().some((intfc) => intfc.name === 'Connection')
|
|
264
268
|
) {
|
|
265
|
-
return true
|
|
269
|
+
return true;
|
|
266
270
|
}
|
|
267
271
|
}
|
|
268
|
-
|
|
272
|
+
return false;
|
|
273
|
+
};
|