@tinacms/graphql 0.56.0 → 0.57.2

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.
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- import { FieldDefinitionNode, ScalarTypeDefinitionNode, InputValueDefinitionNode, ObjectTypeDefinitionNode, InterfaceTypeDefinitionNode, NamedTypeNode, UnionTypeDefinitionNode, TypeDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, InputObjectTypeDefinitionNode, DocumentNode } from 'graphql';
13
+ import { FieldDefinitionNode, ScalarTypeDefinitionNode, InputValueDefinitionNode, ObjectTypeDefinitionNode, InterfaceTypeDefinitionNode, NamedTypeNode, UnionTypeDefinitionNode, TypeDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, InputObjectTypeDefinitionNode, DocumentNode, FragmentDefinitionNode, SelectionNode, FieldNode, InlineFragmentNode, OperationDefinitionNode } from 'graphql';
14
14
  /**
15
15
  * the `gql` module provides functions and types which can be
16
16
  * used to build up the GraphQL AST. The primary reason for us using
@@ -45,6 +45,13 @@ export declare const astBuilder: {
45
45
  required?: boolean;
46
46
  values: string[];
47
47
  }) => EnumTypeDefinitionNode;
48
+ FieldNodeDefinition: ({ name, type, args, list, required, }: {
49
+ name: string;
50
+ type: string | TypeDefinitionNode;
51
+ required?: boolean;
52
+ list?: boolean;
53
+ args?: InputValueDefinitionNode[];
54
+ }) => FieldNode;
48
55
  FieldDefinition: ({ name, type, args, list, required, }: {
49
56
  name: string;
50
57
  type: string | TypeDefinitionNode;
@@ -75,6 +82,29 @@ export declare const astBuilder: {
75
82
  directives?: DirectiveNode[];
76
83
  args?: NamedTypeNode[];
77
84
  }) => ObjectTypeDefinitionNode;
85
+ FieldWithSelectionSetDefinition: ({ name, selections, }: {
86
+ name: string;
87
+ selections: SelectionNode[];
88
+ }) => {
89
+ name: {
90
+ kind: "Name";
91
+ value: string;
92
+ };
93
+ kind: "Field";
94
+ selectionSet: {
95
+ kind: "SelectionSet";
96
+ selections: SelectionNode[];
97
+ };
98
+ };
99
+ InlineFragmentDefinition: ({ name, selections, }: {
100
+ name: string;
101
+ selections: SelectionNode[];
102
+ }) => InlineFragmentNode;
103
+ FragmentDefinition: ({ name, fragmentName, selections, }: {
104
+ name: string;
105
+ fragmentName: string;
106
+ selections: SelectionNode[];
107
+ }) => FragmentDefinitionNode;
78
108
  TYPES: {
79
109
  Scalar: (type: scalarNames) => string;
80
110
  MultiCollectionDocument: string;
@@ -92,6 +122,14 @@ export declare const astBuilder: {
92
122
  Number: string;
93
123
  Document: string;
94
124
  };
125
+ QueryOperationDefinition: ({ queryName, fragName, }: {
126
+ queryName: string;
127
+ fragName: string;
128
+ }) => OperationDefinitionNode;
129
+ ListQueryOperationDefinition: ({ queryName, fragName, }: {
130
+ queryName: string;
131
+ fragName: string;
132
+ }) => OperationDefinitionNode;
95
133
  toGraphQLAst: (ast: {
96
134
  globalTemplates: TypeDefinitionNode[];
97
135
  query: TypeDefinitionNode;
@@ -111,6 +149,7 @@ export declare const NAMER: {
111
149
  createName: (namespace: string[]) => string;
112
150
  queryName: (namespace: string[]) => string;
113
151
  generateQueryListName: (namespace: string[]) => string;
152
+ fragmentName: (namespace: string[]) => string;
114
153
  collectionTypeName: (namespace: string[]) => string;
115
154
  documentTypeName: (namespace: string[]) => string;
116
155
  dataTypeName: (namespace: string[]) => string;
@@ -11,8 +11,8 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import { Database } from '../database';
14
- import type { ObjectTypeDefinitionNode } from 'graphql';
15
- import type { TinaCloudCollectionEnriched } from '../types';
14
+ import type { ObjectTypeDefinitionNode, InlineFragmentNode } from 'graphql';
15
+ import type { TinaCloudCollectionEnriched, Template } from '../types';
16
16
  import { TinaSchema } from '../schema';
17
17
  export declare const createBuilder: ({ database, tinaSchema, }: {
18
18
  database: Database;
@@ -169,6 +169,33 @@ export declare class Builder {
169
169
  * @param collection
170
170
  */
171
171
  collectionDocument: (collection: TinaCloudCollectionEnriched) => Promise<import("graphql").FieldDefinitionNode>;
172
+ /**
173
+ * Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
174
+ * ```graphql
175
+ * # ex.
176
+ * fragment AuthorsParts on Authors {
177
+ * name
178
+ * avatar
179
+ * ...
180
+ * }
181
+ * ```
182
+ *
183
+ * @public
184
+ * @param collection a Tina Cloud collection
185
+ */
186
+ collectionFragment: (collection: TinaCloudCollectionEnriched) => Promise<import("graphql").FragmentDefinitionNode | {
187
+ name: {
188
+ kind: "Name";
189
+ value: string;
190
+ };
191
+ kind: "Field";
192
+ selectionSet: {
193
+ kind: "SelectionSet";
194
+ selections: import("graphql").SelectionNode[];
195
+ };
196
+ }>;
197
+ private _buildFieldNodeForFragments;
198
+ buildTemplateFragments(template: Template<true>): Promise<InlineFragmentNode>;
172
199
  /**
173
200
  * ```graphql
174
201
  * # ex.
@@ -18,35 +18,14 @@ export declare type GithubManagerInit = {
18
18
  owner: string;
19
19
  repo: string;
20
20
  ref: string;
21
- cache?: typeof dummyCache;
22
- };
23
- declare const dummyCache: {
24
- get: <T extends string | string[]>(key: string, setter: () => Promise<T>) => Promise<T>;
25
21
  };
26
22
  export declare class GithubBridge implements Bridge {
27
23
  rootPath: string;
28
24
  repoConfig: Pick<GithubManagerInit, 'owner' | 'ref' | 'repo'>;
29
25
  appOctoKit: Octokit;
30
- cache: typeof dummyCache;
31
- constructor({ rootPath, accessToken, owner, repo, ref, cache, }: GithubManagerInit);
32
- private generateKey;
26
+ constructor({ rootPath, accessToken, owner, repo, ref }: GithubManagerInit);
33
27
  private readDir;
34
28
  glob(pattern: string): Promise<string[]>;
35
29
  get(filepath: string): Promise<string>;
36
30
  put(filepath: string, data: string): Promise<void>;
37
31
  }
38
- export declare const clearCache: ({ owner, repo, ref, path, }: {
39
- owner: string;
40
- repo: string;
41
- ref: string;
42
- path?: string;
43
- }) => void;
44
- /**
45
- * This is just an example of what you can provide for caching
46
- * it should be replaced with a scalable solution which shares a cache
47
- * across lambda instances (like redis)
48
- */
49
- export declare const simpleCache: {
50
- get: (keyName: string, setter: () => Promise<any>) => Promise<any>;
51
- };
52
- export {};
@@ -12,7 +12,6 @@ limitations under the License.
12
12
  */
13
13
  import { indexDB } from './build';
14
14
  import { resolve } from './resolve';
15
- import { simpleCache } from '../cache/lru';
16
15
  import { createDatabase } from './database';
17
16
  export { createDatabase, resolve, indexDB };
18
17
  export type { TinaCloudSchema } from './types';
@@ -25,7 +24,7 @@ export declare const gql: ({ rootPath, query, variables, }: {
25
24
  }, {
26
25
  [key: string]: any;
27
26
  }>>;
28
- export declare const githubRoute: ({ rootPath, query, variables, cacheType, branch, ...githubArgs }: {
27
+ export declare const githubRoute: ({ rootPath, query, variables, branch, ...githubArgs }: {
29
28
  accessToken: string;
30
29
  owner: string;
31
30
  repo: string;
@@ -33,7 +32,6 @@ export declare const githubRoute: ({ rootPath, query, variables, cacheType, bran
33
32
  variables: object;
34
33
  rootPath?: string;
35
34
  branch: string;
36
- cacheType?: typeof simpleCache;
37
35
  }) => Promise<import("graphql").ExecutionResult<{
38
36
  [key: string]: any;
39
37
  }, {
@@ -12,6 +12,7 @@ limitations under the License.
12
12
  */
13
13
  import { TinaSchema } from '../schema';
14
14
  import { Database, CollectionDocumentListLookup } from '../database';
15
+ import type { Collectable, TinaCloudCollection } from '../types';
15
16
  interface ResolverConfig {
16
17
  database: Database;
17
18
  tinaSchema: TinaSchema;
@@ -65,7 +66,7 @@ export declare class Resolver {
65
66
  path: string;
66
67
  relativePath: string;
67
68
  breadcrumbs: string[];
68
- collection: import("../types").TinaCloudCollection<true>;
69
+ collection: TinaCloudCollection<true>;
69
70
  template: string | number;
70
71
  };
71
72
  data: {
@@ -87,12 +88,91 @@ export declare class Resolver {
87
88
  };
88
89
  }>;
89
90
  getDocumentFields: () => Promise<{}>;
90
- resolveDocument: ({ value, args, collection: collectionName, isMutation, isCreation, }: {
91
- value: unknown;
91
+ buildObjectMutations: (fieldValue: any, field: Collectable) => {
92
+ [key: string]: unknown;
93
+ } | {
94
+ [key: string]: unknown;
95
+ }[];
96
+ createResolveDocument: ({ collection, realPath, args, isAddPendingDocument, }: {
97
+ collection: TinaCloudCollection<true>;
98
+ realPath: string;
99
+ args: unknown;
100
+ isAddPendingDocument: boolean;
101
+ }) => Promise<{
102
+ __typename: string;
103
+ id: string;
104
+ sys: {
105
+ basename: string;
106
+ filename: string;
107
+ extension: string;
108
+ path: string;
109
+ relativePath: string;
110
+ breadcrumbs: string[];
111
+ collection: TinaCloudCollection<true>;
112
+ template: string | number;
113
+ };
114
+ data: {
115
+ _collection: string;
116
+ _template: string;
117
+ };
118
+ values: {
119
+ _collection: string;
120
+ _template: string;
121
+ };
122
+ dataJSON: {
123
+ _collection: string;
124
+ _template: string;
125
+ };
126
+ form: {
127
+ label: string;
128
+ name: string;
129
+ fields: unknown[];
130
+ };
131
+ }>;
132
+ updateResolveDocument: ({ collection, realPath, args, isAddPendingDocument, isCollectionSpecific, }: {
133
+ collection: TinaCloudCollection<true>;
134
+ realPath: string;
135
+ args: unknown;
136
+ isAddPendingDocument: boolean;
137
+ isCollectionSpecific: boolean;
138
+ }) => Promise<{
139
+ __typename: string;
140
+ id: string;
141
+ sys: {
142
+ basename: string;
143
+ filename: string;
144
+ extension: string;
145
+ path: string;
146
+ relativePath: string;
147
+ breadcrumbs: string[];
148
+ collection: TinaCloudCollection<true>;
149
+ template: string | number;
150
+ };
151
+ data: {
152
+ _collection: string;
153
+ _template: string;
154
+ };
155
+ values: {
156
+ _collection: string;
157
+ _template: string;
158
+ };
159
+ dataJSON: {
160
+ _collection: string;
161
+ _template: string;
162
+ };
163
+ form: {
164
+ label: string;
165
+ name: string;
166
+ fields: unknown[];
167
+ };
168
+ }>;
169
+ resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isAddPendingDocument, isCollectionSpecific, }: {
92
170
  args: unknown;
93
- collection: string;
171
+ collection?: string;
94
172
  isMutation: boolean;
95
173
  isCreation?: boolean;
174
+ isAddPendingDocument?: boolean;
175
+ isCollectionSpecific?: boolean;
96
176
  }) => Promise<{
97
177
  __typename: string;
98
178
  id: string;
@@ -103,7 +183,7 @@ export declare class Resolver {
103
183
  path: string;
104
184
  relativePath: string;
105
185
  breadcrumbs: string[];
106
- collection: import("../types").TinaCloudCollection<true>;
186
+ collection: TinaCloudCollection<true>;
107
187
  template: string | number;
108
188
  };
109
189
  data: {
@@ -139,7 +219,7 @@ export declare class Resolver {
139
219
  path: string;
140
220
  relativePath: string;
141
221
  breadcrumbs: string[];
142
- collection: import("../types").TinaCloudCollection<true>;
222
+ collection: TinaCloudCollection<true>;
143
223
  template: string | number;
144
224
  };
145
225
  data: {
@@ -178,7 +258,7 @@ export declare class Resolver {
178
258
  path: string;
179
259
  relativePath: string;
180
260
  breadcrumbs: string[];
181
- collection: import("../types").TinaCloudCollection<true>;
261
+ collection: TinaCloudCollection<true>;
182
262
  template: string | number;
183
263
  };
184
264
  data: {
@@ -10,17 +10,5 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- export declare const clearCache: ({ owner, repo, ref, path, }: {
14
- owner: string;
15
- repo: string;
16
- ref: string;
17
- path?: string;
18
- }) => void;
19
- /**
20
- * This is just an example of what you can provide for caching
21
- * it should be replaced with a scalable solution which shares a cache
22
- * across lambda instances (like redis)
23
- */
24
- export declare const simpleCache: {
25
- get: (keyName: string, setter: () => Promise<any>) => Promise<any>;
26
- };
13
+ import type { TinaCloudSchemaBase } from '../types';
14
+ export declare const validateSchema: (schema: TinaCloudSchemaBase) => Promise<TinaCloudSchemaBase>;
@@ -215,7 +215,7 @@ export declare type TinaCloudTemplateEnriched = GlobalTemplate<true>;
215
215
  /**
216
216
  * Templates allow you to define an object as polymorphic
217
217
  */
218
- declare type Template<WithNamespace extends boolean> = WithNamespace extends true ? {
218
+ export declare type Template<WithNamespace extends boolean> = WithNamespace extends true ? {
219
219
  label: string;
220
220
  name: string;
221
221
  fields: TinaFieldInner<WithNamespace>[];
@@ -0,0 +1,14 @@
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
+ import type { TinaSchema } from '../primitives/schema';
14
+ export declare const buildSKD: (tinaSchema: TinaSchema) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.56.0",
3
+ "version": "0.57.2",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -38,9 +38,8 @@
38
38
  ]
39
39
  },
40
40
  "scripts": {
41
- "build": "yarn tsup src/index.ts --format cjs --dts",
42
- "watch": "yarn tsup src/index.ts --watch --format cjs --dts",
43
41
  "types": "yarn tsc --project ./tsconfig.real.json",
42
+ "build": "echo \"Run `yarn build` from the root of the repository instead\"",
44
43
  "docs": "yarn typedoc",
45
44
  "serve": "yarn nodemon dist/server.js",
46
45
  "test": "jest"
@@ -49,11 +48,9 @@
49
48
  "@octokit/auth-app": "^2.6.0",
50
49
  "@octokit/graphql": "^4.5.6",
51
50
  "@octokit/rest": "18.0.6",
52
- "@types/aws-sdk": "^2.7.0",
53
51
  "@types/estree": "^0.0.50",
54
52
  "@types/mdast": "^3.0.10",
55
53
  "@types/node": "^16.9.1",
56
- "aws-sdk": "^2.930.0",
57
54
  "body-parser": "^1.19.0",
58
55
  "cors": "^2.8.5",
59
56
  "dataloader": "^2.0.0",
@@ -68,7 +65,6 @@
68
65
  "gray-matter": "^4.0.2",
69
66
  "js-yaml": "^3.14.0",
70
67
  "lodash": "^4.17.20",
71
- "lru-cache": "^6.0.0",
72
68
  "mdast": "^3.0.0",
73
69
  "mdast-util-from-markdown": "^1.0.0",
74
70
  "mdast-util-mdx": "^1.1.0",
@@ -103,8 +99,7 @@
103
99
  "directory": "packages/tina-graphql"
104
100
  },
105
101
  "devDependencies": {
106
- "@graphql-tools/schema": "^6.2.1",
107
- "@tinacms/scripts": "0.50.3",
102
+ "@tinacms/scripts": "0.50.4",
108
103
  "@types/cors": "^2.8.7",
109
104
  "@types/express": "^4.17.8",
110
105
  "@types/fs-extra": "^9.0.2",
@@ -117,14 +112,11 @@
117
112
  "@types/normalize-path": "^3.0.0",
118
113
  "@types/ws": "^7.2.6",
119
114
  "@types/yup": "^0.29.7",
120
- "graphql-tools": "^6.2.1",
121
115
  "jest": "27.0.6",
122
116
  "jest-diff": "27.0.6",
123
117
  "jest-file-snapshot": "^0.5.0",
124
118
  "jest-matcher-utils": "27.0.6",
125
119
  "nodemon": "^2.0.4",
126
- "ts-jest": "27.0.3",
127
- "tsup": "4.12.5",
128
120
  "typescript": "^4.3.5"
129
121
  }
130
122
  }
@@ -1,31 +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
- import { S3 } from 'aws-sdk';
14
- export declare const clearCacheWith: (cache: S3) => ({ owner, repo, ref, path, }: {
15
- owner: string;
16
- repo: string;
17
- ref: string;
18
- path?: string;
19
- }) => Promise<void>;
20
- export declare const s3CacheWith: (cache: S3) => {
21
- get: (keyName: string, setter: () => Promise<any>) => Promise<any>;
22
- };
23
- export declare const clearCache: ({ owner, repo, ref, path, }: {
24
- owner: string;
25
- repo: string;
26
- ref: string;
27
- path?: string;
28
- }) => Promise<void>;
29
- export declare const s3Cache: {
30
- get: (keyName: string, setter: () => Promise<any>) => Promise<any>;
31
- };