@tinacms/graphql 0.0.0-e70425b-20241028042614 → 0.0.0-e96d36b-20251210035710
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/ast-builder/index.d.ts +2 -3
- package/dist/build.d.ts +2 -4
- package/dist/builder/index.d.ts +2 -2
- package/dist/database/alias-utils.d.ts +1 -1
- package/dist/database/bridge/filesystem.d.ts +1 -1
- package/dist/database/datalayer.d.ts +5 -1
- package/dist/database/index.d.ts +2 -0
- package/dist/database/util.d.ts +6 -9
- package/dist/index.d.ts +1 -4
- package/dist/index.js +4044 -3272
- package/dist/mdx/index.d.ts +2 -7
- package/dist/resolver/auth-fields.d.ts +31 -0
- package/dist/resolver/error.d.ts +1 -8
- package/dist/resolver/index.d.ts +42 -7
- package/dist/resolver/media-utils.d.ts +3 -3
- package/dist/schema/createSchema.d.ts +0 -3
- package/dist/schema/validate.d.ts +0 -3
- package/package.json +25 -32
- package/dist/index.mjs +0 -7313
- package/readme.md +0 -194
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @tinacms/graphql
|
|
2
|
+
|
|
3
|
+
[Tina](https://tina.io) is a headless content management system with support for Markdown, MDX, JSON, YAML, and more. This package contains the logic required to turn a collection of folders and files into a database that can be queried using [GraphQL](https://tina.io/docs/graphql/queries).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Query Markdown, MDX, JSON, YAML and more using GraphQL
|
|
8
|
+
- Supports references between documents
|
|
9
|
+
- Pre-generation of schema and query data to expedite website compilation
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
The easiest way to use this package is as part of a broader TinaCMS site. The starter can be tested locally using:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npx create-tina-app@latest
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Alternatively, you can directly install and use this package.
|
|
20
|
+
|
|
21
|
+
### Install @tinacms/graphql
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
pnpm install
|
|
25
|
+
pnpm add @tinacms/graphql
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Build your program
|
|
29
|
+
|
|
30
|
+
The following example demonstrates how to use this package.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { MemoryLevel } from 'memory-level';
|
|
34
|
+
import {
|
|
35
|
+
Database,
|
|
36
|
+
FilesystemBridge,
|
|
37
|
+
buildSchema,
|
|
38
|
+
resolve
|
|
39
|
+
} from '@tinacms/graphql';
|
|
40
|
+
import {
|
|
41
|
+
Schema
|
|
42
|
+
} from '@tinacms/schema-tools';
|
|
43
|
+
|
|
44
|
+
const dir = 'content';
|
|
45
|
+
|
|
46
|
+
// Where to source content from
|
|
47
|
+
const bridge = new FilesystemBridge(dir);
|
|
48
|
+
// Where to store the index data
|
|
49
|
+
const indexStorage = new MemoryLevel<string, Record<string, string>>();
|
|
50
|
+
|
|
51
|
+
// Create the schema/structure of the database
|
|
52
|
+
const rawSchema: Schema = {
|
|
53
|
+
collections: [
|
|
54
|
+
{
|
|
55
|
+
name: 'post',
|
|
56
|
+
path: '', // Don't require content to be placed within a subdirectory
|
|
57
|
+
fields: [
|
|
58
|
+
{
|
|
59
|
+
type: 'string',
|
|
60
|
+
name: 'title',
|
|
61
|
+
isTitle: true,
|
|
62
|
+
required: true
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
};
|
|
68
|
+
const schema = await buildSchema({
|
|
69
|
+
schema: rawSchema,
|
|
70
|
+
build: {
|
|
71
|
+
publicFolder: '',
|
|
72
|
+
outputFolder: ''
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Create the object for editing and querying your repository
|
|
77
|
+
const database = new Database({
|
|
78
|
+
bridge,
|
|
79
|
+
level: indexStorage,
|
|
80
|
+
tinaDirectory: 'tina'
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Generate the index data required to support querying
|
|
84
|
+
await database.indexContent(schema)
|
|
85
|
+
|
|
86
|
+
// Query the database and output the result
|
|
87
|
+
// In this case, it will retrieve the title of the post 'in.md'
|
|
88
|
+
const graphQLQuery = `
|
|
89
|
+
query {
|
|
90
|
+
document(collection: "post", relativePath: "in.md") {
|
|
91
|
+
...on Document {
|
|
92
|
+
_values,
|
|
93
|
+
_sys { title }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
`
|
|
98
|
+
const result = await resolve({
|
|
99
|
+
database,
|
|
100
|
+
query: graphQLQuery,
|
|
101
|
+
variables: {}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Output the result
|
|
105
|
+
console.log(JSON.stringify(result))
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
For the program to work:
|
|
109
|
+
|
|
110
|
+
1. Install packages:
|
|
111
|
+
- [`@tinacms/schema-tools`](https://www.npmjs.com/package/@tinacms/schema-tools)
|
|
112
|
+
- [`memory-level`](https://www.npmjs.com/package/memory-level)
|
|
113
|
+
2. Add a file `content/in.md` of the following form:
|
|
114
|
+
|
|
115
|
+
```md
|
|
116
|
+
---
|
|
117
|
+
title: Hello
|
|
118
|
+
---
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The output should be:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{"data":{"document":{"_values":{"_collection":"post","_template":"post","title":"Hello"},"_sys":{"title":"Hello"}}}}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
The package is part of the [TinaCMS repository](https://github.com/tinacms/tinacms/).
|
|
130
|
+
|
|
131
|
+
## Documentation
|
|
132
|
+
|
|
133
|
+
Visit [Tina's documentation](https://tina.io/docs/) to learn more.
|
|
134
|
+
|
|
135
|
+
## Questions?
|
|
136
|
+
|
|
137
|
+
[](https://twitter.com/intent/tweet?url=https%3A%2F%2Ftinacms.org&text=I%20just%20checked%20out%20@tinacms%20on%20GitHub%20and%20it%20is%20sweet%21&hashtags=TinaCMS%2Cjamstack%2Cheadlesscms)
|
|
138
|
+
[](https://github.com/tinacms/tinacms/discussions)
|
|
139
|
+
|
|
140
|
+
Visit the [GitHub Discussions](https://github.com/tinacms/tinacms/discussions) or our [Community Discord](https://discord.com/invite/zumN63Ybpf) to ask questions, or look us up on on Twitter at [@tinacms](https://twitter.com/tinacms).
|
|
141
|
+
|
|
142
|
+
## Contributing
|
|
143
|
+
|
|
144
|
+
Please see our [./CONTRIBUTING.md](https://github.com/tinacms/tinacms/blob/main/CONTRIBUTING.md)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
|
-
import { type FieldDefinitionNode, type ScalarTypeDefinitionNode, type InputValueDefinitionNode, type ObjectTypeDefinitionNode, type InterfaceTypeDefinitionNode, type NamedTypeNode, type UnionTypeDefinitionNode, type TypeDefinitionNode, type DirectiveNode, type EnumTypeDefinitionNode, type InputObjectTypeDefinitionNode, type DocumentNode, type FragmentDefinitionNode, type SelectionNode, type FieldNode, type InlineFragmentNode, type OperationDefinitionNode } from 'graphql';
|
|
4
|
+
import { type FieldDefinitionNode, type ScalarTypeDefinitionNode, type InputValueDefinitionNode, type ObjectTypeDefinitionNode, type InterfaceTypeDefinitionNode, type NamedTypeNode, type UnionTypeDefinitionNode, type TypeDefinitionNode, type DirectiveNode, type EnumTypeDefinitionNode, type InputObjectTypeDefinitionNode, type DocumentNode, type FragmentDefinitionNode, type SelectionNode, type FieldNode, type InlineFragmentNode, type OperationDefinitionNode, type DefinitionNode } from 'graphql';
|
|
5
5
|
export declare const SysFieldDefinition: {
|
|
6
6
|
kind: "Field";
|
|
7
7
|
name: {
|
|
@@ -153,9 +153,8 @@ export declare const astBuilder: {
|
|
|
153
153
|
}) => DocumentNode;
|
|
154
154
|
};
|
|
155
155
|
type scalarNames = 'string' | 'boolean' | 'datetime' | 'image' | 'text' | 'number';
|
|
156
|
-
export declare const extractInlineTypes: (item:
|
|
156
|
+
export declare const extractInlineTypes: (item: DefinitionNode | DefinitionNode[]) => DefinitionNode[];
|
|
157
157
|
export declare function walk(maybeNode: TypeDefinitionNode, visited?: WeakSet<WeakKey>): IterableIterator<TypeDefinitionNode>;
|
|
158
|
-
export declare function addNamespaceToSchema<T extends object | string>(maybeNode: T, namespace?: string[]): T;
|
|
159
158
|
export declare const NAMER: {
|
|
160
159
|
dataFilterTypeNameOn: (namespace: string[]) => string;
|
|
161
160
|
dataFilterTypeName: (namespace: string[]) => string;
|
package/dist/build.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
|
+
import { type DocumentNode } from 'graphql';
|
|
4
5
|
import type { TinaSchema, Config } from '@tinacms/schema-tools';
|
|
5
6
|
export declare const buildDotTinaFiles: ({ config, flags, buildSDK, }: {
|
|
6
7
|
config: Config;
|
|
7
8
|
flags?: string[];
|
|
8
9
|
buildSDK?: boolean;
|
|
9
10
|
}) => Promise<{
|
|
10
|
-
graphQLSchema:
|
|
11
|
-
kind: "Document";
|
|
12
|
-
definitions: any;
|
|
13
|
-
};
|
|
11
|
+
graphQLSchema: DocumentNode;
|
|
14
12
|
tinaSchema: TinaSchema;
|
|
15
13
|
lookup: Record<string, import("./database").LookupMapType>;
|
|
16
14
|
fragDoc: string;
|
package/dist/builder/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
4
|
import { LookupMapType } from '../database';
|
|
5
|
-
import type {
|
|
5
|
+
import type { FieldDefinitionNode, InlineFragmentNode, ObjectTypeDefinitionNode } from 'graphql';
|
|
6
6
|
import type { Collection, Template } from '@tinacms/schema-tools';
|
|
7
7
|
import { TinaSchema } from '@tinacms/schema-tools';
|
|
8
8
|
export declare const createBuilder: ({ tinaSchema, }: {
|
|
@@ -177,7 +177,7 @@ export declare class Builder {
|
|
|
177
177
|
* ```
|
|
178
178
|
*
|
|
179
179
|
* @public
|
|
180
|
-
* @param collection a
|
|
180
|
+
* @param collection a TinaCloud collection
|
|
181
181
|
*/
|
|
182
182
|
collectionFragment: (collection: Collection<true>) => Promise<import("graphql").FragmentDefinitionNode>;
|
|
183
183
|
/**
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Template } from '@tinacms/schema-tools
|
|
1
|
+
import { Template } from '@tinacms/schema-tools';
|
|
2
2
|
export declare const replaceNameOverrides: (template: Template, obj: any) => object;
|
|
3
3
|
export declare const applyNameOverrides: (template: Template, obj: any) => object;
|
|
@@ -6,7 +6,7 @@ import type { Bridge } from './index';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class FilesystemBridge implements Bridge {
|
|
8
8
|
rootPath: string;
|
|
9
|
-
outputPath
|
|
9
|
+
outputPath: string;
|
|
10
10
|
constructor(rootPath: string, outputPath?: string);
|
|
11
11
|
glob(pattern: string, extension: string): Promise<string[]>;
|
|
12
12
|
delete(filepath: string): Promise<void>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
4
|
import { BatchOp, Level } from './level';
|
|
5
|
-
import { Collection } from '@tinacms/schema-tools';
|
|
5
|
+
import type { Collection } from '@tinacms/schema-tools';
|
|
6
6
|
export declare enum OP {
|
|
7
7
|
EQ = "eq",
|
|
8
8
|
GT = "gt",
|
|
@@ -49,6 +49,9 @@ export type FilterCondition = {
|
|
|
49
49
|
};
|
|
50
50
|
type StringEscaper = <T extends string | string[]>(input: T) => T;
|
|
51
51
|
export declare const DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
|
|
52
|
+
export declare const REFS_COLLECTIONS_SORT_KEY = "__refs__";
|
|
53
|
+
export declare const REFS_REFERENCE_FIELD = "__tina_ref__";
|
|
54
|
+
export declare const REFS_PATH_FIELD = "__tina_ref_path__";
|
|
52
55
|
export declare const DEFAULT_NUMERIC_LPAD = 4;
|
|
53
56
|
export declare const coerceFilterChainOperands: (filterChain: (BinaryFilter | TernaryFilter)[], escapeString?: StringEscaper) => (BinaryFilter | TernaryFilter)[];
|
|
54
57
|
export declare const makeFilter: ({ filterChain, }: {
|
|
@@ -71,6 +74,7 @@ export declare class FolderTreeBuilder {
|
|
|
71
74
|
}
|
|
72
75
|
export declare const makeFolderOpsForCollection: <T extends object>(folderTree: FolderTree, collection: Collection<true>, indexDefinitions: Record<string, IndexDefinition>, opType: "put" | "del", level: Level, escapeStr?: StringEscaper) => BatchOp[];
|
|
73
76
|
export declare const makeIndexOpsForDocument: <T extends object>(filepath: string, collection: string | undefined, indexDefinitions: Record<string, IndexDefinition>, data: T, opType: "put" | "del", level: Level, escapeStr?: StringEscaper) => BatchOp[];
|
|
77
|
+
export declare const makeRefOpsForDocument: <T extends object>(filepath: string, collection: string | undefined, references: Record<string, string[]> | undefined | null, data: T, opType: "put" | "del", level: Level) => BatchOp[];
|
|
74
78
|
export declare const makeStringEscaper: (regex: RegExp, replacement: string) => StringEscaper;
|
|
75
79
|
export declare const stringEscaper: StringEscaper;
|
|
76
80
|
export {};
|
package/dist/database/index.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export declare class Database {
|
|
|
72
72
|
private tinaSchema;
|
|
73
73
|
private contentNamespace;
|
|
74
74
|
private collectionIndexDefinitions;
|
|
75
|
+
private collectionReferences;
|
|
75
76
|
private _lookup;
|
|
76
77
|
constructor(config: DatabaseArgs);
|
|
77
78
|
private collectionForPath;
|
|
@@ -125,6 +126,7 @@ export declare class Database {
|
|
|
125
126
|
getGraphQLSchemaFromBridge: () => Promise<DocumentNode>;
|
|
126
127
|
getTinaSchema: (level?: Level) => Promise<Schema>;
|
|
127
128
|
getSchema: (level?: Level, existingSchema?: Schema) => Promise<TinaSchema>;
|
|
129
|
+
getCollectionReferences: (level?: Level) => Promise<Record<string, Record<string, string[]>>>;
|
|
128
130
|
getIndexDefinitions: (level?: Level) => Promise<Record<string, Record<string, IndexDefinition>>>;
|
|
129
131
|
documentExists: (fullpath: unknown) => Promise<boolean>;
|
|
130
132
|
query: (queryOptions: QueryOptions, hydrator: any) => Promise<{
|
package/dist/database/util.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
1
|
+
import { Collection, CollectionTemplateable, TinaSchema, normalizePath } from '@tinacms/schema-tools';
|
|
4
2
|
import * as yup from 'yup';
|
|
5
|
-
import {
|
|
3
|
+
import { ContentFormat, ContentFrontmatterFormat } from '@tinacms/schema-tools';
|
|
6
4
|
import { Bridge } from './bridge';
|
|
7
5
|
export { normalizePath };
|
|
8
|
-
export declare const stringifyFile: (content: object, format:
|
|
9
|
-
frontmatterFormat?:
|
|
6
|
+
export declare const stringifyFile: (content: object, format: ContentFormat | string, keepTemplateKey: boolean, markdownParseConfig?: {
|
|
7
|
+
frontmatterFormat?: ContentFrontmatterFormat;
|
|
10
8
|
frontmatterDelimiters?: [string, string] | string;
|
|
11
9
|
}) => string;
|
|
12
|
-
export declare const parseFile: <T extends object>(content: string, format:
|
|
13
|
-
frontmatterFormat?:
|
|
10
|
+
export declare const parseFile: <T extends object>(content: string, format: ContentFormat | string, yupSchema: (args: typeof yup) => yup.ObjectSchema<any>, markdownParseConfig?: {
|
|
11
|
+
frontmatterFormat?: ContentFrontmatterFormat;
|
|
14
12
|
frontmatterDelimiters?: [string, string] | string;
|
|
15
13
|
}) => T;
|
|
16
|
-
export type FormatType = 'json' | 'md' | 'mdx' | 'markdown';
|
|
17
14
|
export declare const atob: (b64Encoded: string) => string;
|
|
18
15
|
export declare const btoa: (string: string) => string;
|
|
19
16
|
export declare const scanAllContent: (tinaSchema: TinaSchema, bridge: Bridge, callback: (collection: Collection<true>, contentPaths: string[]) => Promise<void>) => Promise<string[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -16,10 +16,7 @@ export { createSchema } from './schema/createSchema';
|
|
|
16
16
|
export { buildDotTinaFiles };
|
|
17
17
|
export type DummyType = unknown;
|
|
18
18
|
export declare const buildSchema: (config: Config, flags?: string[]) => Promise<{
|
|
19
|
-
graphQLSchema:
|
|
20
|
-
kind: "Document";
|
|
21
|
-
definitions: any;
|
|
22
|
-
};
|
|
19
|
+
graphQLSchema: import("graphql").DocumentNode;
|
|
23
20
|
tinaSchema: import("@tinacms/schema-tools").TinaSchema;
|
|
24
21
|
lookup: Record<string, import("./database").LookupMapType>;
|
|
25
22
|
fragDoc: string;
|