@tinacms/graphql 1.5.16 → 1.5.18

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 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
+ [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](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
+ [![Forum](https://shields.io/github/discussions/tinacms/tinacms)](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)
@@ -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?: string;
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>;
@@ -1,19 +1,16 @@
1
- /**
2
-
3
- */
4
1
  import * as yup from 'yup';
5
2
  import { Collection, CollectionTemplateable, normalizePath, TinaSchema } from '@tinacms/schema-tools';
6
3
  import { Bridge } from './bridge';
4
+ import { ContentFormat, ContentFrontmatterFormat } from '@tinacms/schema-tools';
7
5
  export { normalizePath };
8
- export declare const stringifyFile: (content: object, format: FormatType | string, keepTemplateKey: boolean, markdownParseConfig?: {
9
- frontmatterFormat?: "toml" | "yaml" | "json";
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: FormatType | string, yupSchema: (args: typeof yup) => yup.ObjectSchema<any>, markdownParseConfig?: {
13
- frontmatterFormat?: "toml" | "yaml" | "json";
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[]>;