@tinacms/graphql 0.0.0-bdc07c1-20250506013835 → 0.0.0-bdea884-20250606054015
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/README.md +144 -0
- package/dist/database/bridge/filesystem.d.ts +1 -1
- package/dist/database/util.d.ts +1 -4
- package/dist/index.d.ts +32 -1
- package/dist/index.js +155 -186
- package/dist/index.mjs +34 -39
- package/dist/resolver/index.d.ts +4 -4
- package/dist/schema/createSchema.d.ts +0 -3
- package/dist/schema/validate.d.ts +0 -3
- package/package.json +5 -10
- package/readme.md +0 -194
package/dist/index.mjs
CHANGED
|
@@ -3019,7 +3019,7 @@ var validateField = async (field) => {
|
|
|
3019
3019
|
// package.json
|
|
3020
3020
|
var package_default = {
|
|
3021
3021
|
name: "@tinacms/graphql",
|
|
3022
|
-
version: "1.5.
|
|
3022
|
+
version: "1.5.18",
|
|
3023
3023
|
main: "dist/index.js",
|
|
3024
3024
|
module: "dist/index.mjs",
|
|
3025
3025
|
typings: "dist/index.d.ts",
|
|
@@ -3045,38 +3045,34 @@ var package_default = {
|
|
|
3045
3045
|
types: "pnpm tsc",
|
|
3046
3046
|
build: "tinacms-scripts build",
|
|
3047
3047
|
docs: "pnpm typedoc",
|
|
3048
|
-
serve: "pnpm nodemon dist/server.js",
|
|
3049
3048
|
test: "vitest run",
|
|
3050
3049
|
"test-watch": "vitest"
|
|
3051
3050
|
},
|
|
3052
3051
|
dependencies: {
|
|
3053
|
-
"@iarna/toml": "
|
|
3052
|
+
"@iarna/toml": "catalog:",
|
|
3054
3053
|
"@tinacms/mdx": "workspace:*",
|
|
3055
3054
|
"@tinacms/schema-tools": "workspace:*",
|
|
3056
|
-
"abstract-level": "
|
|
3055
|
+
"abstract-level": "catalog:",
|
|
3057
3056
|
"date-fns": "^2.30.0",
|
|
3058
|
-
"fast-glob": "
|
|
3059
|
-
"fs-extra": "
|
|
3060
|
-
"glob-parent": "
|
|
3057
|
+
"fast-glob": "catalog:",
|
|
3058
|
+
"fs-extra": "catalog:",
|
|
3059
|
+
"glob-parent": "catalog:",
|
|
3061
3060
|
graphql: "15.8.0",
|
|
3062
|
-
"gray-matter": "
|
|
3063
|
-
"isomorphic-git": "
|
|
3064
|
-
"js-sha1": "
|
|
3061
|
+
"gray-matter": "catalog:",
|
|
3062
|
+
"isomorphic-git": "catalog:",
|
|
3063
|
+
"js-sha1": "catalog:",
|
|
3065
3064
|
"js-yaml": "^3.14.1",
|
|
3066
|
-
"jsonpath-plus": "
|
|
3067
|
-
"lodash.clonedeep": "
|
|
3068
|
-
"lodash.set": "
|
|
3069
|
-
"lodash.uniqby": "
|
|
3070
|
-
"many-level": "
|
|
3071
|
-
micromatch: "
|
|
3072
|
-
"normalize-path": "
|
|
3073
|
-
"readable-stream": "
|
|
3074
|
-
scmp: "
|
|
3065
|
+
"jsonpath-plus": "catalog:",
|
|
3066
|
+
"lodash.clonedeep": "catalog:",
|
|
3067
|
+
"lodash.set": "catalog:",
|
|
3068
|
+
"lodash.uniqby": "catalog:",
|
|
3069
|
+
"many-level": "catalog:",
|
|
3070
|
+
micromatch: "catalog:",
|
|
3071
|
+
"normalize-path": "catalog:",
|
|
3072
|
+
"readable-stream": "catalog:",
|
|
3073
|
+
scmp: "catalog:",
|
|
3075
3074
|
yup: "^0.32.11"
|
|
3076
3075
|
},
|
|
3077
|
-
peerDependencies: {
|
|
3078
|
-
"@tinacms/common": "workspace:*"
|
|
3079
|
-
},
|
|
3080
3076
|
publishConfig: {
|
|
3081
3077
|
registry: "https://registry.npmjs.org"
|
|
3082
3078
|
},
|
|
@@ -3089,21 +3085,20 @@ var package_default = {
|
|
|
3089
3085
|
"@tinacms/scripts": "workspace:*",
|
|
3090
3086
|
"@types/cors": "^2.8.17",
|
|
3091
3087
|
"@types/estree": "^0.0.50",
|
|
3092
|
-
"@types/express": "
|
|
3088
|
+
"@types/express": "catalog:",
|
|
3093
3089
|
"@types/fs-extra": "^9.0.13",
|
|
3094
3090
|
"@types/js-yaml": "^3.12.10",
|
|
3095
|
-
"@types/lodash.camelcase": "
|
|
3096
|
-
"@types/lodash.upperfirst": "
|
|
3097
|
-
"@types/lru-cache": "
|
|
3098
|
-
"@types/mdast": "
|
|
3099
|
-
"@types/micromatch": "
|
|
3091
|
+
"@types/lodash.camelcase": "catalog:",
|
|
3092
|
+
"@types/lodash.upperfirst": "catalog:",
|
|
3093
|
+
"@types/lru-cache": "catalog:",
|
|
3094
|
+
"@types/mdast": "catalog:",
|
|
3095
|
+
"@types/micromatch": "catalog:",
|
|
3100
3096
|
"@types/node": "^22.13.1",
|
|
3101
|
-
"@types/normalize-path": "
|
|
3102
|
-
"@types/ws": "
|
|
3097
|
+
"@types/normalize-path": "catalog:",
|
|
3098
|
+
"@types/ws": "catalog:",
|
|
3103
3099
|
"@types/yup": "^0.29.14",
|
|
3104
3100
|
"jest-file-snapshot": "^0.5.0",
|
|
3105
|
-
"memory-level": "
|
|
3106
|
-
nodemon: "3.1.4",
|
|
3101
|
+
"memory-level": "catalog:",
|
|
3107
3102
|
typescript: "^5.7.3",
|
|
3108
3103
|
vite: "^4.5.9",
|
|
3109
3104
|
vitest: "^0.32.4",
|
|
@@ -7581,8 +7576,8 @@ import path6 from "path";
|
|
|
7581
7576
|
import normalize from "normalize-path";
|
|
7582
7577
|
var FilesystemBridge = class {
|
|
7583
7578
|
constructor(rootPath, outputPath) {
|
|
7584
|
-
this.rootPath = rootPath
|
|
7585
|
-
this.outputPath = outputPath
|
|
7579
|
+
this.rootPath = path6.resolve(rootPath);
|
|
7580
|
+
this.outputPath = outputPath ? path6.resolve(outputPath) : this.rootPath;
|
|
7586
7581
|
}
|
|
7587
7582
|
async glob(pattern, extension) {
|
|
7588
7583
|
const basePath = path6.join(this.outputPath, ...pattern.split("/"));
|
|
@@ -7594,19 +7589,19 @@ var FilesystemBridge = class {
|
|
|
7594
7589
|
}
|
|
7595
7590
|
);
|
|
7596
7591
|
const posixRootPath = normalize(this.outputPath);
|
|
7597
|
-
return items.map(
|
|
7598
|
-
|
|
7599
|
-
|
|
7592
|
+
return items.map(
|
|
7593
|
+
(item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
|
|
7594
|
+
);
|
|
7600
7595
|
}
|
|
7601
7596
|
async delete(filepath) {
|
|
7602
7597
|
await fs2.remove(path6.join(this.outputPath, filepath));
|
|
7603
7598
|
}
|
|
7604
7599
|
async get(filepath) {
|
|
7605
|
-
return fs2.
|
|
7600
|
+
return (await fs2.readFile(path6.join(this.outputPath, filepath))).toString();
|
|
7606
7601
|
}
|
|
7607
7602
|
async put(filepath, data, basePathOverride) {
|
|
7608
7603
|
const basePath = basePathOverride || this.outputPath;
|
|
7609
|
-
await fs2.
|
|
7604
|
+
await fs2.outputFile(path6.join(basePath, filepath), data);
|
|
7610
7605
|
}
|
|
7611
7606
|
};
|
|
7612
7607
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|
package/dist/resolver/index.d.ts
CHANGED
|
@@ -74,10 +74,10 @@ export declare class Resolver {
|
|
|
74
74
|
name: string;
|
|
75
75
|
}[];
|
|
76
76
|
}[];
|
|
77
|
-
format?: import("@tinacms/
|
|
77
|
+
format?: import("@tinacms/schema-tools").ContentFormat;
|
|
78
78
|
ui?: import("@tinacms/schema-tools").UICollection;
|
|
79
79
|
defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
|
|
80
|
-
frontmatterFormat?: import("@tinacms/
|
|
80
|
+
frontmatterFormat?: import("@tinacms/schema-tools").ContentFrontmatterFormat;
|
|
81
81
|
frontmatterDelimiters?: [string, string] | string;
|
|
82
82
|
match?: {
|
|
83
83
|
include?: string;
|
|
@@ -102,10 +102,10 @@ export declare class Resolver {
|
|
|
102
102
|
name: string;
|
|
103
103
|
}[];
|
|
104
104
|
}[];
|
|
105
|
-
format?: import("@tinacms/
|
|
105
|
+
format?: import("@tinacms/schema-tools").ContentFormat;
|
|
106
106
|
ui?: import("@tinacms/schema-tools").UICollection;
|
|
107
107
|
defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
|
|
108
|
-
frontmatterFormat?: import("@tinacms/
|
|
108
|
+
frontmatterFormat?: import("@tinacms/schema-tools").ContentFrontmatterFormat;
|
|
109
109
|
frontmatterDelimiters?: [string, string] | string;
|
|
110
110
|
match?: {
|
|
111
111
|
include?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/graphql",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-bdea884-20250606054015",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -44,11 +44,8 @@
|
|
|
44
44
|
"readable-stream": "^4.7.0",
|
|
45
45
|
"scmp": "^2.1.0",
|
|
46
46
|
"yup": "^0.32.11",
|
|
47
|
-
"@tinacms/
|
|
48
|
-
"@tinacms/
|
|
49
|
-
},
|
|
50
|
-
"peerDependencies": {
|
|
51
|
-
"@tinacms/common": "0.0.0-bdc07c1-20250506013835"
|
|
47
|
+
"@tinacms/schema-tools": "0.0.0-bdea884-20250606054015",
|
|
48
|
+
"@tinacms/mdx": "0.0.0-bdea884-20250606054015"
|
|
52
49
|
},
|
|
53
50
|
"publishConfig": {
|
|
54
51
|
"registry": "https://registry.npmjs.org"
|
|
@@ -74,19 +71,17 @@
|
|
|
74
71
|
"@types/yup": "^0.29.14",
|
|
75
72
|
"jest-file-snapshot": "^0.5.0",
|
|
76
73
|
"memory-level": "^1.0.0",
|
|
77
|
-
"nodemon": "3.1.4",
|
|
78
74
|
"typescript": "^5.7.3",
|
|
79
75
|
"vite": "^4.5.9",
|
|
80
76
|
"vitest": "^0.32.4",
|
|
81
77
|
"zod": "^3.24.2",
|
|
82
|
-
"@tinacms/schema-tools": "0.0.0-
|
|
83
|
-
"@tinacms/scripts": "
|
|
78
|
+
"@tinacms/schema-tools": "0.0.0-bdea884-20250606054015",
|
|
79
|
+
"@tinacms/scripts": "0.0.0-bdea884-20250606054015"
|
|
84
80
|
},
|
|
85
81
|
"scripts": {
|
|
86
82
|
"types": "pnpm tsc",
|
|
87
83
|
"build": "tinacms-scripts build",
|
|
88
84
|
"docs": "pnpm typedoc",
|
|
89
|
-
"serve": "pnpm nodemon dist/server.js",
|
|
90
85
|
"test": "vitest run",
|
|
91
86
|
"test-watch": "vitest"
|
|
92
87
|
}
|
package/readme.md
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
## Getting started
|
|
2
|
-
|
|
3
|
-
There's a serve and watch command, which are separate for now:
|
|
4
|
-
|
|
5
|
-
```sh
|
|
6
|
-
// terminal 1
|
|
7
|
-
cd packages/tina-graphql
|
|
8
|
-
yarn watch
|
|
9
|
-
|
|
10
|
-
// terminal 2
|
|
11
|
-
cd packages/tina-graphql
|
|
12
|
-
yarn serve
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
You can consume this from the `graphiql` app:
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
// terminal 3
|
|
19
|
-
cd apps/graphiql
|
|
20
|
-
yarn start
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Note that this app doesn't use anything from the `client` package right now, it's just an interactive tool to see how things move from the graphql server into tina. That process has been improved in this package but will need to be merged back into the `client` package before this is usable.
|
|
24
|
-
|
|
25
|
-
### Running queries
|
|
26
|
-
|
|
27
|
-
By default the app will redirect to `project1` and display the default query generated from the `graphql-helpers` library - which consumes the fixtures from the `project1` folder the the `gql` package, any number of fixtures can be used if you want to add your own, just ensure the `server.ts` file knows about them.
|
|
28
|
-
|
|
29
|
-
When you run the initial query, you should see the result along with the Tina sidebar toggle, this indicates that the Tina form has now been populated with the query values. If you change some values around and hit submit, the `onSubmit` function will populate the GraphiQL editor instead of sending it off to the server, you can play around with the mutation before sending it off if you'd like.
|
|
30
|
-
|
|
31
|
-
### Tests
|
|
32
|
-
|
|
33
|
-
The most valuable test right now is the `builder.spec.ts`, it's sort of an integration of all the field-level builders. There are also field-level build tests, but not resolvers ones just yet. If you're making changes to the builder just run `yarn test-watch` and hit `p` to provide a pattern, then type "builder", this will isolate that test and if it's passing you probably didn't break anything.
|
|
34
|
-
|
|
35
|
-
## Architecture
|
|
36
|
-
|
|
37
|
-
### Builder
|
|
38
|
-
|
|
39
|
-
The builder service is responsible for building out the entire GraphQL schema for a given `.tina` config. This service can run at any time (but needs to be re-run on each schema change) and it's output is a GraphQL schema which can be stored in the schema definition language (SDL) as a string in a database record or as a `.graphql` file. At the top of the schema is a `document` query, this query returns the document, which can be one of any number of templates defined in the `.tina` config. From there, each field in the given template is used to build out the rest of the schema, so each template field is built by the `type` in it's definition
|
|
40
|
-
|
|
41
|
-
#### Field-level builders
|
|
42
|
-
|
|
43
|
-
Field-level builders take a field definition and produce 4 different GraphQL types:
|
|
44
|
-
|
|
45
|
-
##### `field`
|
|
46
|
-
|
|
47
|
-
Builds the type which fits into Tina's field definition shape:
|
|
48
|
-
|
|
49
|
-
Given:
|
|
50
|
-
|
|
51
|
-
```yaml
|
|
52
|
-
name: Title
|
|
53
|
-
label: title
|
|
54
|
-
type: text
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
text.build.field({ cache, field });
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Produces
|
|
62
|
-
|
|
63
|
-
```graphql
|
|
64
|
-
type TextField {
|
|
65
|
-
name: String
|
|
66
|
-
label: String
|
|
67
|
-
component: String
|
|
68
|
-
description: String
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
##### `initialValue`
|
|
73
|
-
|
|
74
|
-
Tina fields need an initial value when editing existing data. This builder is responsible for providing the shape of that value.
|
|
75
|
-
|
|
76
|
-
For most fields this is the same value as `value` - but if you picture the schema as a "graph" - you can see how the "value" of a document reference (ie. a Post has an Author) is not helpful to Tina. Tina only cares about the stored document value of the reference (in this case `/path/to/author.md`) so it's the `initialValue`'s role to provide what makes sense to Tina, regardless of the schema's relationships.
|
|
77
|
-
|
|
78
|
-
##### `value`
|
|
79
|
-
|
|
80
|
-
The value of the field, it's the role of this function to provide the shape of the data we should expect for a fully resolved graph.
|
|
81
|
-
|
|
82
|
-
For `block` fields, this looks like an array of different shapes, which means it's the `blocks.build.value` function's responsibility to return a `union` array.
|
|
83
|
-
|
|
84
|
-
##### `input`
|
|
85
|
-
|
|
86
|
-
When a mutation is made, the shape of this mutation needs to fit the shape create by this function.
|
|
87
|
-
|
|
88
|
-
### Resolvers
|
|
89
|
-
|
|
90
|
-
`resolvers` can be thought of as the runtime siblings to `builders`. While it's the job of builders to define the "graph", the resolvers are responsible for taking raw values (like those from a `.md` file) and shaping them so they fit the schema.
|
|
91
|
-
|
|
92
|
-
#### Field-level resolvers
|
|
93
|
-
|
|
94
|
-
Again, similar to field-level builders, most of the work for resolving the data is passed on to the appropriate field to handle. So if you have a document like so:
|
|
95
|
-
|
|
96
|
-
```md
|
|
97
|
-
---
|
|
98
|
-
title: Hello, World!
|
|
99
|
-
author: /authors/homer.md
|
|
100
|
-
---
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
It's template definition might look like:
|
|
104
|
-
|
|
105
|
-
```yaml
|
|
106
|
-
label: Post
|
|
107
|
-
---
|
|
108
|
-
fields:
|
|
109
|
-
- name: title
|
|
110
|
-
label: Title
|
|
111
|
-
type: text
|
|
112
|
-
- name: author
|
|
113
|
-
label: Author
|
|
114
|
-
type: select
|
|
115
|
-
config:
|
|
116
|
-
source:
|
|
117
|
-
type: pages
|
|
118
|
-
section: authors
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
The `text.resolver` object will be responsible for resolving the values related to `title`:
|
|
122
|
-
|
|
123
|
-
##### `field`
|
|
124
|
-
|
|
125
|
-
The `field` resolver provides the appropriate values for it's `field` builder counterpart. In the example above the `text.resolve.field` function would return:
|
|
126
|
-
|
|
127
|
-
```json
|
|
128
|
-
{
|
|
129
|
-
"name": "title",
|
|
130
|
-
"label": "Title",
|
|
131
|
-
"component": "text"
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
This would then be passed on to Tina for rendering on the client.
|
|
136
|
-
|
|
137
|
-
##### `initialValue`
|
|
138
|
-
|
|
139
|
-
In the example above the `text.resolve.initialValue` would return "Hello, World!"
|
|
140
|
-
|
|
141
|
-
For blocks we need to return the object along with a `_template` key, this is used downstream to disambiguate which template the value comes from.
|
|
142
|
-
|
|
143
|
-
##### `value`
|
|
144
|
-
|
|
145
|
-
In the example above the `text.resolve.value` would return "Hello, World!", and again, for document references this would return the entire document being referenced, which may or may not be used depending on the graph fields requested
|
|
146
|
-
|
|
147
|
-
##### `input`
|
|
148
|
-
|
|
149
|
-
Input resolvers don't do much (except in the case of blocks described later), since the GraphQL mutataion payload has all the necessary information, we just pass the value into these resolvers as a runtime type-check. In the future, this is where field-level validations can take place.
|
|
150
|
-
|
|
151
|
-
**Caveats with `blocks`**: `blocks` values are an array of unlike objects, meaning in order to enforce type-safe requests coming into the server, we need to use a somewhat awkward pattern ([read more about the trade-offs here](https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md#-5-one-of-tagged-union)) which we sort of need to rearrange once it hits the server.
|
|
152
|
-
|
|
153
|
-
## Architecture Diagram
|
|
154
|
-
|
|
155
|
-
<iframe style="border:none" width="700" height="350" src="https://whimsical.com/embed/Kh28ULaAYKPRpeCLm3VG63@2Ux7TurymMtzhxz2sLxX"></iframe>
|
|
156
|
-
|
|
157
|
-
## Caveats
|
|
158
|
-
|
|
159
|
-
### Why do we use `GraphQLUnion` instead of `GraphQLInterface` for fields?
|
|
160
|
-
|
|
161
|
-
Since `component`, `label`, & `name` are common across all fields, we'd only use a fragment to gather what's unique to that field type, so field definitions using an interface would allow our queries to look like this:
|
|
162
|
-
|
|
163
|
-
```graphql
|
|
164
|
-
fields {
|
|
165
|
-
component
|
|
166
|
-
label
|
|
167
|
-
name
|
|
168
|
-
...on SelectField {
|
|
169
|
-
options
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
Instead, we use a union - which requires us to load each key inside it's respective fragment:
|
|
175
|
-
|
|
176
|
-
```graphql
|
|
177
|
-
fields {
|
|
178
|
-
... on TextareaField {
|
|
179
|
-
name
|
|
180
|
-
label
|
|
181
|
-
component
|
|
182
|
-
}
|
|
183
|
-
... on SelectField {
|
|
184
|
-
name
|
|
185
|
-
label
|
|
186
|
-
component
|
|
187
|
-
options
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
A GraphQL interface allows you to define a heterogeneous set of types, which have some fields in common. This is a textbook usecase for interfaces, and it's something that could change in the future. But the current reason we're using unions is because unions are exhaustive, and they allow us to scope down the possible field types for a given set of fields.
|
|
193
|
-
|
|
194
|
-
An interface would be too broad for our needs, a collection of fields should only contain the types which are possible for that given template config. So while an `interface` would allow us to present **all** possible field types, a `union` gives us the ability to scope down the field list to only allow what the template defines. Using `unions` forces us to be explicit about that in a way that's clear (note: it may be possible to do this with interfaces but there would end up being an interface for each collection of possible fields - making the `interface` term somewhat misleading). Using unions also allows our auto-querybuilder to know that they have populated all possible types of a field, something that seems like it might be more difficult with interfaces.
|