@tinacms/app 0.0.12 → 0.0.14
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/assets/out.es.js +122042 -0
- package/dist/assets/style.css +651 -0
- package/dist/assets/webfontloader.js +620 -0
- package/{appFiles → dist}/index.dev.html +4 -1
- package/{appFiles → dist}/index.html +1 -1
- package/dist/index.js +22 -8
- package/dist/prebuild.d.ts +1 -0
- package/dist/prebuild.js +302 -0
- package/package.json +14 -15
- package/appFiles/lib/formify/formify-utils.ts +0 -299
- package/appFiles/lib/formify/formify.ts +0 -574
- package/appFiles/lib/formify/index.ts +0 -67
- package/appFiles/lib/formify/types.ts +0 -130
- package/appFiles/lib/formify/util.ts +0 -598
- package/appFiles/lib/machines/document-machine.ts +0 -351
- package/appFiles/lib/machines/query-machine.ts +0 -728
- package/appFiles/lib/machines/util.ts +0 -205
- package/appFiles/src/App.tsx +0 -52
- package/appFiles/src/assets/tina.svg +0 -6
- package/appFiles/src/index.css +0 -3
- package/appFiles/src/main.tsx +0 -24
- package/appFiles/src/preview/index.tsx +0 -150
- package/appFiles/src/vite-env.d.ts +0 -16
- package/tsconfig.json +0 -20
- package/tsconfig.node.json +0 -9
package/dist/prebuild.js
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __reExport = (target, module2, desc) => {
|
|
9
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(module2))
|
|
11
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
12
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
var __toModule = (module2) => {
|
|
17
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/prebuild.ts
|
|
21
|
+
var import_plugin_react = __toModule(require("@vitejs/plugin-react"));
|
|
22
|
+
var import_vite = __toModule(require("vite"));
|
|
23
|
+
var import_path2 = __toModule(require("path"));
|
|
24
|
+
var import_fs_extra = __toModule(require("fs-extra"));
|
|
25
|
+
|
|
26
|
+
// src/tailwind.ts
|
|
27
|
+
var import_tailwindcss = __toModule(require("tailwindcss"));
|
|
28
|
+
var import_postcss_nested = __toModule(require("postcss-nested/index.js"));
|
|
29
|
+
var import_nesting = __toModule(require("tailwindcss/nesting/index.js"));
|
|
30
|
+
var import_defaultTheme = __toModule(require("tailwindcss/defaultTheme.js"));
|
|
31
|
+
var import_typography = __toModule(require("@tailwindcss/typography"));
|
|
32
|
+
var import_line_clamp = __toModule(require("@tailwindcss/line-clamp"));
|
|
33
|
+
var import_aspect_ratio = __toModule(require("@tailwindcss/aspect-ratio"));
|
|
34
|
+
var import_path = __toModule(require("path"));
|
|
35
|
+
var viteTina = () => {
|
|
36
|
+
return {
|
|
37
|
+
name: "vite-plugin-tina",
|
|
38
|
+
config: () => {
|
|
39
|
+
const plugins = [];
|
|
40
|
+
const tw = (0, import_tailwindcss.default)({
|
|
41
|
+
important: ".tina-tailwind",
|
|
42
|
+
theme: {
|
|
43
|
+
columns: {
|
|
44
|
+
auto: "auto",
|
|
45
|
+
1: "1",
|
|
46
|
+
2: "2",
|
|
47
|
+
3: "3",
|
|
48
|
+
4: "4",
|
|
49
|
+
5: "5",
|
|
50
|
+
6: "6",
|
|
51
|
+
7: "7",
|
|
52
|
+
8: "8",
|
|
53
|
+
9: "9",
|
|
54
|
+
10: "10",
|
|
55
|
+
11: "11",
|
|
56
|
+
12: "12",
|
|
57
|
+
"3xs": "256px",
|
|
58
|
+
"2xs": "288px",
|
|
59
|
+
xs: "320px",
|
|
60
|
+
sm: "384px",
|
|
61
|
+
md: "448px",
|
|
62
|
+
lg: "512px",
|
|
63
|
+
xl: "576px",
|
|
64
|
+
"2xl": "672px",
|
|
65
|
+
"3xl": "768px",
|
|
66
|
+
"4xl": "896px",
|
|
67
|
+
"5xl": "1024px",
|
|
68
|
+
"6xl": "1152px",
|
|
69
|
+
"7xl": "1280px"
|
|
70
|
+
},
|
|
71
|
+
spacing: {
|
|
72
|
+
px: "1px",
|
|
73
|
+
0: "0px",
|
|
74
|
+
0.5: "2px",
|
|
75
|
+
1: "4px",
|
|
76
|
+
1.5: "6px",
|
|
77
|
+
2: "8px",
|
|
78
|
+
2.5: "10px",
|
|
79
|
+
3: "12px",
|
|
80
|
+
3.5: "14px",
|
|
81
|
+
4: "16px",
|
|
82
|
+
5: "20px",
|
|
83
|
+
6: "24px",
|
|
84
|
+
7: "28px",
|
|
85
|
+
8: "32px",
|
|
86
|
+
9: "36px",
|
|
87
|
+
10: "40px",
|
|
88
|
+
11: "44px",
|
|
89
|
+
12: "48px",
|
|
90
|
+
14: "56px",
|
|
91
|
+
16: "64px",
|
|
92
|
+
18: "72px",
|
|
93
|
+
20: "80px",
|
|
94
|
+
24: "96px",
|
|
95
|
+
28: "114px",
|
|
96
|
+
32: "128px",
|
|
97
|
+
36: "144px",
|
|
98
|
+
40: "160px",
|
|
99
|
+
44: "176px",
|
|
100
|
+
48: "192px",
|
|
101
|
+
52: "208px",
|
|
102
|
+
56: "224px",
|
|
103
|
+
60: "240px",
|
|
104
|
+
64: "256px",
|
|
105
|
+
72: "288px",
|
|
106
|
+
80: "320px",
|
|
107
|
+
96: "384px"
|
|
108
|
+
},
|
|
109
|
+
borderRadius: {
|
|
110
|
+
none: "0px",
|
|
111
|
+
sm: "2px",
|
|
112
|
+
DEFAULT: "4px",
|
|
113
|
+
md: "6px",
|
|
114
|
+
lg: "8px",
|
|
115
|
+
xl: "12px",
|
|
116
|
+
"2xl": "16px",
|
|
117
|
+
"3xl": "24px",
|
|
118
|
+
full: "9999px"
|
|
119
|
+
},
|
|
120
|
+
borderWidth: {
|
|
121
|
+
DEFAULT: "1px",
|
|
122
|
+
0: "0",
|
|
123
|
+
2: "2px",
|
|
124
|
+
3: "3px",
|
|
125
|
+
4: "4px",
|
|
126
|
+
6: "6px",
|
|
127
|
+
8: "8px"
|
|
128
|
+
},
|
|
129
|
+
fontSize: {
|
|
130
|
+
xs: ["13px", { lineHeight: "1.33" }],
|
|
131
|
+
sm: ["14px", { lineHeight: "1.43" }],
|
|
132
|
+
base: ["16px", { lineHeight: "1.5" }],
|
|
133
|
+
md: ["16px", { lineHeight: "1.5" }],
|
|
134
|
+
lg: ["18px", { lineHeight: "1.55" }],
|
|
135
|
+
xl: ["20px", { lineHeight: "1.4" }],
|
|
136
|
+
"2xl": ["24px", { lineHeight: "1.33" }],
|
|
137
|
+
"3xl": ["30px", { lineHeight: "1.2" }],
|
|
138
|
+
"4xl": ["36px", { lineHeight: "1.1" }],
|
|
139
|
+
"5xl": ["48px", { lineHeight: "1" }],
|
|
140
|
+
"6xl": ["60px", { lineHeight: "1" }],
|
|
141
|
+
"7xl": ["72px", { lineHeight: "1" }],
|
|
142
|
+
"8xl": ["96px", { lineHeight: "1" }],
|
|
143
|
+
"9xl": ["128px", { lineHeight: "1" }]
|
|
144
|
+
},
|
|
145
|
+
opacity: {
|
|
146
|
+
0: "0",
|
|
147
|
+
5: ".05",
|
|
148
|
+
7: ".07",
|
|
149
|
+
10: ".1",
|
|
150
|
+
15: ".15",
|
|
151
|
+
20: ".2",
|
|
152
|
+
25: ".25",
|
|
153
|
+
30: ".3",
|
|
154
|
+
40: ".4",
|
|
155
|
+
50: ".5",
|
|
156
|
+
60: ".6",
|
|
157
|
+
70: ".7",
|
|
158
|
+
75: ".75",
|
|
159
|
+
80: ".8",
|
|
160
|
+
90: ".9",
|
|
161
|
+
100: "1"
|
|
162
|
+
},
|
|
163
|
+
zIndex: {
|
|
164
|
+
"-1": "-1",
|
|
165
|
+
base: "9000",
|
|
166
|
+
panel: "9400",
|
|
167
|
+
menu: "9800",
|
|
168
|
+
chrome: "10200",
|
|
169
|
+
overlay: "10600",
|
|
170
|
+
modal: "10800",
|
|
171
|
+
0: "0",
|
|
172
|
+
10: "10",
|
|
173
|
+
20: "20",
|
|
174
|
+
30: "30",
|
|
175
|
+
40: "40",
|
|
176
|
+
25: "25",
|
|
177
|
+
50: "50",
|
|
178
|
+
75: "75",
|
|
179
|
+
100: "100",
|
|
180
|
+
auto: "auto"
|
|
181
|
+
},
|
|
182
|
+
extend: {
|
|
183
|
+
scale: {
|
|
184
|
+
97: ".97",
|
|
185
|
+
103: "1.03"
|
|
186
|
+
},
|
|
187
|
+
transitionDuration: {
|
|
188
|
+
0: "0ms",
|
|
189
|
+
2e3: "2000ms"
|
|
190
|
+
},
|
|
191
|
+
boxShadow: {
|
|
192
|
+
xs: "0 0 0 1px rgba(0, 0, 0, 0.05)",
|
|
193
|
+
outline: "0 0 0 3px rgba(66, 153, 225, 0.5)"
|
|
194
|
+
},
|
|
195
|
+
colors: {
|
|
196
|
+
blue: {
|
|
197
|
+
50: "#DCEEFF",
|
|
198
|
+
100: "#B4DBFF",
|
|
199
|
+
200: "#85C5FE",
|
|
200
|
+
300: "#4EABFE",
|
|
201
|
+
400: "#2296fe",
|
|
202
|
+
500: "#0084FF",
|
|
203
|
+
600: "#0574e4",
|
|
204
|
+
700: "#0D5DBD",
|
|
205
|
+
800: "#144696",
|
|
206
|
+
900: "#1D2C6C",
|
|
207
|
+
1e3: "#241748"
|
|
208
|
+
},
|
|
209
|
+
gray: {
|
|
210
|
+
50: "#F6F6F9",
|
|
211
|
+
100: "#EDECF3",
|
|
212
|
+
150: "#E6E3EF",
|
|
213
|
+
200: "#E1DDEC",
|
|
214
|
+
250: "#C9C5D5",
|
|
215
|
+
300: "#b2adbe",
|
|
216
|
+
400: "#918c9e",
|
|
217
|
+
500: "#716c7f",
|
|
218
|
+
600: "#565165",
|
|
219
|
+
700: "#433e52",
|
|
220
|
+
800: "#363145",
|
|
221
|
+
900: "#252336",
|
|
222
|
+
1e3: "#1c1b2e"
|
|
223
|
+
},
|
|
224
|
+
orange: {
|
|
225
|
+
400: "#EB6337",
|
|
226
|
+
500: "#EC4815",
|
|
227
|
+
600: "#DC4419"
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
fontFamily: {
|
|
231
|
+
sans: ["Inter", ...import_defaultTheme.default.fontFamily.sans]
|
|
232
|
+
},
|
|
233
|
+
lineHeight: {
|
|
234
|
+
3: "12px",
|
|
235
|
+
4: "16px",
|
|
236
|
+
5: "20px",
|
|
237
|
+
6: "24px",
|
|
238
|
+
7: "28px",
|
|
239
|
+
8: "32px",
|
|
240
|
+
9: "36px",
|
|
241
|
+
10: "40px"
|
|
242
|
+
},
|
|
243
|
+
maxWidth: {
|
|
244
|
+
form: "900px"
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
content: [
|
|
249
|
+
import_path.default.join(__dirname, "../appFiles/src/**/*.{vue,js,ts,jsx,tsx,svelte}")
|
|
250
|
+
],
|
|
251
|
+
plugins: [
|
|
252
|
+
(0, import_typography.default)({ className: "tina-prose" }),
|
|
253
|
+
import_line_clamp.default,
|
|
254
|
+
import_aspect_ratio.default
|
|
255
|
+
]
|
|
256
|
+
});
|
|
257
|
+
plugins.push(import_nesting.default);
|
|
258
|
+
plugins.push(import_postcss_nested.default);
|
|
259
|
+
plugins.push(tw);
|
|
260
|
+
return {
|
|
261
|
+
css: {
|
|
262
|
+
postcss: {
|
|
263
|
+
plugins
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/prebuild.ts
|
|
272
|
+
var prebuild = async () => {
|
|
273
|
+
const outDir = import_path2.default.join(__dirname, "../dist/assets");
|
|
274
|
+
const outDevHTML = import_path2.default.join(__dirname, "../dist/index.dev.html");
|
|
275
|
+
await import_fs_extra.default.copyFileSync(import_path2.default.join(__dirname, "../appFiles/index.dev.html"), outDevHTML);
|
|
276
|
+
const outHTML = import_path2.default.join(__dirname, "../dist/index.html");
|
|
277
|
+
await import_fs_extra.default.copyFileSync(import_path2.default.join(__dirname, "../appFiles/index.html"), outHTML);
|
|
278
|
+
const entry = import_path2.default.join(__dirname, "../appFiles/src/main.tsx");
|
|
279
|
+
const libConfig = {
|
|
280
|
+
plugins: [(0, import_plugin_react.default)(), viteTina()],
|
|
281
|
+
define: {
|
|
282
|
+
__API_URL__: `__API_URL__`
|
|
283
|
+
},
|
|
284
|
+
build: {
|
|
285
|
+
minify: false,
|
|
286
|
+
sourcemap: false,
|
|
287
|
+
rollupOptions: {
|
|
288
|
+
external: "TINA_IMPORT"
|
|
289
|
+
},
|
|
290
|
+
outDir,
|
|
291
|
+
emptyOutDir: true,
|
|
292
|
+
lib: {
|
|
293
|
+
entry,
|
|
294
|
+
formats: ["es"],
|
|
295
|
+
fileName: "out"
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
logLevel: "silent"
|
|
299
|
+
};
|
|
300
|
+
await (0, import_vite.build)(libConfig);
|
|
301
|
+
};
|
|
302
|
+
prebuild();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -11,14 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"typings": "dist/index.d.ts",
|
|
13
13
|
"files": [
|
|
14
|
-
"dist"
|
|
15
|
-
"script.mjs",
|
|
16
|
-
"package.json",
|
|
17
|
-
"public",
|
|
18
|
-
"appFiles",
|
|
19
|
-
"tsconfig.json",
|
|
20
|
-
"tsconfig.node.json",
|
|
21
|
-
"vite.config.ts"
|
|
14
|
+
"dist"
|
|
22
15
|
],
|
|
23
16
|
"license": "Apache-2.0",
|
|
24
17
|
"buildConfig": {
|
|
@@ -26,6 +19,10 @@
|
|
|
26
19
|
{
|
|
27
20
|
"name": "src/index.ts",
|
|
28
21
|
"target": "node"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "src/prebuild.ts",
|
|
25
|
+
"target": "node"
|
|
29
26
|
}
|
|
30
27
|
]
|
|
31
28
|
},
|
|
@@ -40,9 +37,9 @@
|
|
|
40
37
|
"@tailwindcss/aspect-ratio": "^0.4.0",
|
|
41
38
|
"@tailwindcss/line-clamp": "^0.3.1",
|
|
42
39
|
"@tailwindcss/typography": "^0.5.4",
|
|
43
|
-
"@tinacms/schema-tools": "0.1.
|
|
40
|
+
"@tinacms/schema-tools": "0.1.4",
|
|
44
41
|
"@tinacms/scripts": "0.51.1",
|
|
45
|
-
"@vitejs/plugin-react": "1.3.2",
|
|
42
|
+
"@vitejs/plugin-react": "^1.3.2",
|
|
46
43
|
"@xstate/react": "^3.0.0",
|
|
47
44
|
"autoprefixer": "^10.4.0",
|
|
48
45
|
"final-form": "^4.20.7",
|
|
@@ -54,16 +51,18 @@
|
|
|
54
51
|
"postcss-nested": "^5.0.6",
|
|
55
52
|
"react": "17.0.2",
|
|
56
53
|
"react-dom": "17.0.2",
|
|
54
|
+
"react-is": "18.2.0",
|
|
57
55
|
"react-router-dom": "6",
|
|
56
|
+
"styled-components": "5.3.5",
|
|
58
57
|
"tailwindcss": "^3.1.6",
|
|
59
|
-
"tinacms": "0.69.
|
|
58
|
+
"tinacms": "0.69.9",
|
|
60
59
|
"typescript": "^4.6.4",
|
|
61
|
-
"vite": "
|
|
62
|
-
"vite-node": "^0.
|
|
60
|
+
"vite": "2.9.15",
|
|
61
|
+
"vite-node": "^0.23.4",
|
|
63
62
|
"xstate": "^4.32.1"
|
|
64
63
|
},
|
|
65
64
|
"scripts": {
|
|
66
65
|
"types": "rm dist/index.d.ts && touch dist/index.d.ts && echo \"export declare const viteBuild: (args: any) => any\" > dist/index.d.ts",
|
|
67
|
-
"build": "tinacms-scripts build"
|
|
66
|
+
"build": "tinacms-scripts build && node dist/prebuild.js"
|
|
68
67
|
}
|
|
69
68
|
}
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
Copyright 2021 Forestry.io Holdings, Inc.
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
See the License for the specific language governing permissions and
|
|
11
|
-
limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import * as G from 'graphql'
|
|
15
|
-
|
|
16
|
-
import type { BlueprintPath } from './types'
|
|
17
|
-
import { getBlueprintNamePath } from './util'
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* This check ensures that at type is a Document, but only one
|
|
22
|
-
* that can be "formified". When using `Node` or `Document`, those
|
|
23
|
-
* query fields should not have forms generated since they can't contain
|
|
24
|
-
* fields.
|
|
25
|
-
*
|
|
26
|
-
* ```graphql
|
|
27
|
-
* # Can be formified
|
|
28
|
-
* {
|
|
29
|
-
* getPostDocument(relativePath: "") {
|
|
30
|
-
* data {
|
|
31
|
-
* title
|
|
32
|
-
* }
|
|
33
|
-
* }
|
|
34
|
-
* }
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* ```graphql
|
|
38
|
-
* # cannot be formified, even though it is a document field
|
|
39
|
-
* {
|
|
40
|
-
* getPostDocument(relativePath: "") {
|
|
41
|
-
* ...on Document {
|
|
42
|
-
* id
|
|
43
|
-
* }
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export const isFormifiableDocument = (t: G.GraphQLOutputType) => {
|
|
49
|
-
const type = G.getNamedType(t)
|
|
50
|
-
if (G.isUnionType(type)) {
|
|
51
|
-
return type.getTypes().every((type) => {
|
|
52
|
-
return type.getInterfaces().find((intfc) => intfc.name === 'Node')
|
|
53
|
-
})
|
|
54
|
-
} else if (G.isObjectType(type)) {
|
|
55
|
-
return !!type.getInterfaces().find((intfc) => intfc.name === 'Node')
|
|
56
|
-
} else {
|
|
57
|
-
return false
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const isScalarType = (t: G.GraphQLOutputType) => {
|
|
62
|
-
const namedType = G.getNamedType(t)
|
|
63
|
-
return G.isScalarType(namedType)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const isConnectionField = (t: G.GraphQLOutputType) => {
|
|
67
|
-
const type = G.getNamedType(t)
|
|
68
|
-
if (G.isObjectType(type)) {
|
|
69
|
-
return !!type.getInterfaces().find((intfc) => intfc.name === 'Connection')
|
|
70
|
-
} else {
|
|
71
|
-
throw new Error(`Expected GraphQLObjectType for isConnectionField check`)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Selects the appropriate field from a GraphQLObject based on the selection's name
|
|
77
|
-
*/
|
|
78
|
-
export const getObjectField = (
|
|
79
|
-
object: G.GraphQLOutputType,
|
|
80
|
-
selectionNode: G.FieldNode
|
|
81
|
-
) => {
|
|
82
|
-
const namedType = G.getNamedType(object)
|
|
83
|
-
ensureObjectOrInterfaceType(namedType)
|
|
84
|
-
return namedType.getFields()[selectionNode.name.value]
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Selects the appropriate type from a union based on the selection's typeCondition
|
|
89
|
-
*
|
|
90
|
-
* ```graphql
|
|
91
|
-
* post {
|
|
92
|
-
* # would return PostDocument
|
|
93
|
-
* ...on PostDocument { ... }
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
export const getSelectedUnionType = (
|
|
98
|
-
unionType: G.GraphQLOutputType,
|
|
99
|
-
selectionNode: G.InlineFragmentNode
|
|
100
|
-
) => {
|
|
101
|
-
const namedType = G.getNamedType(unionType)
|
|
102
|
-
if (!G.isUnionType(namedType)) {
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
const types = namedType.getTypes()
|
|
106
|
-
|
|
107
|
-
const typeCondition = selectionNode.typeCondition.name.value
|
|
108
|
-
let intfc
|
|
109
|
-
types.forEach((type) => {
|
|
110
|
-
intfc = type.getInterfaces().find((intfc) => intfc.name === typeCondition)
|
|
111
|
-
})
|
|
112
|
-
if (intfc) {
|
|
113
|
-
return intfc
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return namedType.getTypes().find((type) => type.name === typeCondition)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Checks if the given type is a list type. Even though
|
|
121
|
-
* this function is built-in to GraphQL it doesn't handle
|
|
122
|
-
* the scenario where the list type is wrapped in a non-null
|
|
123
|
-
* type, so the extra check here is needed.
|
|
124
|
-
*/
|
|
125
|
-
export function isListType(type: unknown) {
|
|
126
|
-
if (G.isListType(type)) {
|
|
127
|
-
return true
|
|
128
|
-
} else if (G.isNonNullType(type)) {
|
|
129
|
-
if (G.isListType(type.ofType)) {
|
|
130
|
-
return true
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return false
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
*
|
|
138
|
-
* Throws an error if the provided type is not a GraphQLUnionType
|
|
139
|
-
*/
|
|
140
|
-
function ensureUnionType(type: unknown): asserts type is G.GraphQLUnionType {
|
|
141
|
-
if (!G.isUnionType(type)) {
|
|
142
|
-
throw new Error(`Expected type to be GraphQLUnionType`)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
* Throws an error if the provided type is not a GraphQLObjectType or GraphQLInterfaceType
|
|
149
|
-
*/
|
|
150
|
-
function ensureObjectOrInterfaceType(
|
|
151
|
-
type: unknown
|
|
152
|
-
): asserts type is G.GraphQLObjectType | G.GraphQLInterfaceType {
|
|
153
|
-
if (G.isInterfaceType(type) || G.isObjectType(type)) {
|
|
154
|
-
} else {
|
|
155
|
-
console.log(
|
|
156
|
-
'Expected type to be GraphQLObjectType or GraphQLInterfaceType',
|
|
157
|
-
type
|
|
158
|
-
)
|
|
159
|
-
throw new Error(
|
|
160
|
-
`Expected type to be GraphQLObjectType or GraphQLInterfaceType`
|
|
161
|
-
)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
*
|
|
167
|
-
* Throws an error if the provided type is not a GraphQLUnionType
|
|
168
|
-
*/
|
|
169
|
-
export function ensureOperationDefinition(
|
|
170
|
-
type: G.DefinitionNode
|
|
171
|
-
): asserts type is G.OperationDefinitionNode {
|
|
172
|
-
if (type.kind !== 'OperationDefinition') {
|
|
173
|
-
throw new Error(
|
|
174
|
-
`Expected top-level definition to be an OperationDefinition node, ensure your query has been optimized before calling formify`
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Generates the name and alias information for a given field node
|
|
181
|
-
* and appends it to a shallow copy of the path provided
|
|
182
|
-
*/
|
|
183
|
-
export function buildPath({
|
|
184
|
-
fieldNode,
|
|
185
|
-
type,
|
|
186
|
-
parentTypename,
|
|
187
|
-
path,
|
|
188
|
-
}: {
|
|
189
|
-
fieldNode: G.FieldNode
|
|
190
|
-
type: G.GraphQLOutputType
|
|
191
|
-
parentTypename?: string
|
|
192
|
-
path?: BlueprintPath[]
|
|
193
|
-
}): BlueprintPath[] {
|
|
194
|
-
const p = path || []
|
|
195
|
-
const list = isListType(type)
|
|
196
|
-
const isNode = isFormifiableDocument(type)
|
|
197
|
-
return [
|
|
198
|
-
...p,
|
|
199
|
-
{
|
|
200
|
-
name: fieldNode.name.value,
|
|
201
|
-
alias: fieldNode.alias ? fieldNode.alias.value : fieldNode.name.value,
|
|
202
|
-
parentTypename: parentTypename,
|
|
203
|
-
list: !!list,
|
|
204
|
-
isNode: !!isNode,
|
|
205
|
-
},
|
|
206
|
-
]
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* This is a dummy query which we pull apart and spread
|
|
211
|
-
* back into the the selectionSet for all "Node" fields
|
|
212
|
-
*/
|
|
213
|
-
const node = G.parse(`
|
|
214
|
-
query Sample {
|
|
215
|
-
...on Document {
|
|
216
|
-
_internalSys: _sys {
|
|
217
|
-
path
|
|
218
|
-
relativePath
|
|
219
|
-
collection {
|
|
220
|
-
name
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
_values
|
|
224
|
-
}
|
|
225
|
-
}`)
|
|
226
|
-
export const metaFields: G.SelectionNode[] =
|
|
227
|
-
// @ts-ignore
|
|
228
|
-
node.definitions[0].selectionSet.selections
|
|
229
|
-
|
|
230
|
-
export const getRelativeBlueprint = (path: BlueprintPath[]) => {
|
|
231
|
-
let indexOfLastNode = 0
|
|
232
|
-
path.forEach((item, i) => {
|
|
233
|
-
if (item.isNode) {
|
|
234
|
-
if (i === path.length - 1) {
|
|
235
|
-
// skip if the item is a node, we still want to treat it as a field for the parent
|
|
236
|
-
} else {
|
|
237
|
-
indexOfLastNode = i
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
const documentBlueprintPath = path.slice(0, indexOfLastNode + 1)
|
|
243
|
-
return getBlueprintNamePath({ path: documentBlueprintPath })
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export const isSysField = (fieldNode: G.FieldNode) => {
|
|
247
|
-
if (fieldNode.name.value === '__typename') {
|
|
248
|
-
return true
|
|
249
|
-
}
|
|
250
|
-
if (fieldNode.name.value === '_sys') {
|
|
251
|
-
return true
|
|
252
|
-
}
|
|
253
|
-
if (fieldNode.name.value === '_values') {
|
|
254
|
-
return true
|
|
255
|
-
}
|
|
256
|
-
if (fieldNode.name.value === 'id') {
|
|
257
|
-
return true
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return false
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export const getBlueprintId = (path: BlueprintPath[]) => {
|
|
264
|
-
const namePath = []
|
|
265
|
-
const aliasPath = []
|
|
266
|
-
path.forEach((p) => {
|
|
267
|
-
namePath.push(p.name)
|
|
268
|
-
aliasPath.push(p.alias)
|
|
269
|
-
if (p.list) {
|
|
270
|
-
namePath.push('[]')
|
|
271
|
-
aliasPath.push('[]')
|
|
272
|
-
}
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
return namePath.join('.')
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export const getFieldAliasForBlueprint = (path: BlueprintPath[]) => {
|
|
279
|
-
const reversePath = [...path].reverse()
|
|
280
|
-
const accum = []
|
|
281
|
-
reversePath.every((item, index) => {
|
|
282
|
-
if (index === 0) {
|
|
283
|
-
if (item.list) {
|
|
284
|
-
accum.push('[]')
|
|
285
|
-
}
|
|
286
|
-
accum.push(item.alias)
|
|
287
|
-
} else {
|
|
288
|
-
if (item.isNode) {
|
|
289
|
-
return false
|
|
290
|
-
}
|
|
291
|
-
if (item.list) {
|
|
292
|
-
accum.push('[]')
|
|
293
|
-
}
|
|
294
|
-
accum.push(item.alias)
|
|
295
|
-
}
|
|
296
|
-
return true
|
|
297
|
-
})
|
|
298
|
-
return accum.reverse().slice(1).join('.')
|
|
299
|
-
}
|