@tinacms/graphql 0.61.6 → 0.62.0

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.
File without changes
@@ -10,11 +10,25 @@ 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 { DocumentNode } from 'graphql';
13
14
  import type { TinaSchema } from './schema';
14
15
  import { Database } from './database';
15
- export declare const indexDB: ({ database, config, flags, buildSDK, }: {
16
+ /**
17
+ *
18
+ * This will build the files (_schema.json, _lookup.json, _graphQL.json)
19
+ */
20
+ export declare const indexDB: (args: {
16
21
  database: Database;
17
22
  config: TinaSchema['config'];
18
23
  flags?: string[];
19
24
  buildSDK?: boolean;
20
25
  }) => Promise<void>;
26
+ export declare const buildFiles: ({ database, config, flags, buildSDK, }: {
27
+ database: Database;
28
+ config: TinaSchema['config'];
29
+ flags?: string[];
30
+ buildSDK?: boolean;
31
+ }) => Promise<{
32
+ graphQLSchema: DocumentNode;
33
+ tinaSchema: TinaSchema;
34
+ }>;
@@ -28,6 +28,7 @@ export declare class Builder {
28
28
  database: Database;
29
29
  tinaSchema: TinaSchema;
30
30
  };
31
+ private maxDepth;
31
32
  tinaSchema: TinaSchema;
32
33
  database: Database;
33
34
  constructor(config: {
@@ -173,8 +174,23 @@ export declare class Builder {
173
174
  * @param collection a Tina Cloud collection
174
175
  */
175
176
  collectionFragment: (collection: TinaCloudCollectionEnriched) => Promise<import("graphql").FragmentDefinitionNode>;
177
+ /**
178
+ * Given a collection this function returns its selections set. For example for Post this would return
179
+ *
180
+ * "
181
+ * body
182
+ * title
183
+ * ... on Author {
184
+ * name
185
+ * heroImg
186
+ * }
187
+ *
188
+ * But in the AST format
189
+ *
190
+ * */
191
+ private _getCollectionFragmentSelections;
176
192
  private _buildFieldNodeForFragments;
177
- buildTemplateFragments(template: Template<true>): Promise<InlineFragmentNode>;
193
+ buildTemplateFragments(template: Template<true>, depth: number): Promise<InlineFragmentNode>;
178
194
  /**
179
195
  * ```graphql
180
196
  * # ex.
File without changes
File without changes
package/dist/index.d.ts CHANGED
@@ -1 +1,32 @@
1
- export * from "../src/index"
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
+ export { indexDB } from './build';
14
+ export { resolve } from './resolve';
15
+ export * from './resolver/error';
16
+ export { createDatabase } from './database';
17
+ export type { QueryOptions } from './database';
18
+ import type { Database } from './database';
19
+ export type { Database } from './database';
20
+ export type { Store } from '@tinacms/datalayer';
21
+ export type { Bridge } from './database/bridge';
22
+ export { sequential, assertShape } from './util';
23
+ export { stringifyFile, parseFile } from './database/util';
24
+ export declare type DummyType = unknown;
25
+ export declare const buildSchema: (rootPath: string, database: Database, flags?: string[], skipIndexing?: boolean) => Promise<import("graphql").GraphQLSchema>;
26
+ import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from './types';
27
+ export declare type TinaCloudSchema = TinaCloudSchemaBase<false>;
28
+ export declare type TinaSchema = TinaCloudSchema;
29
+ export declare type TinaCloudCollection = TinaCloudCollectionBase<false>;
30
+ export declare type TinaCollection = TinaCloudCollectionBase<false>;
31
+ export declare type TinaField = TinaFieldBase;
32
+ export type { TinaTemplate };
package/dist/index.js CHANGED
@@ -7009,32 +7009,30 @@ var Builder = class {
7009
7009
  this.collectionFragment = async (collection) => {
7010
7010
  const name2 = NAMER.dataTypeName(collection.namespace);
7011
7011
  const fragmentName = NAMER.fragmentName(collection.namespace);
7012
+ const selections = await this._getCollectionFragmentSelections(collection, 0);
7013
+ return astBuilder.FragmentDefinition({
7014
+ name: name2,
7015
+ fragmentName,
7016
+ selections: filterSelections(selections)
7017
+ });
7018
+ };
7019
+ this._getCollectionFragmentSelections = async (collection, depth) => {
7020
+ const selections = [];
7012
7021
  if (typeof collection.fields === "object") {
7013
- const selections = [];
7014
7022
  await sequential(collection.fields, async (x) => {
7015
- const field = await this._buildFieldNodeForFragments(x);
7023
+ const field = await this._buildFieldNodeForFragments(x, depth);
7016
7024
  selections.push(field);
7017
7025
  });
7018
- return astBuilder.FragmentDefinition({
7019
- name: name2,
7020
- fragmentName,
7021
- selections: filterSelections(selections)
7022
- });
7023
7026
  } else {
7024
- const selections = [];
7025
7027
  await sequential(collection.templates, async (tem) => {
7026
7028
  if (typeof tem === "object") {
7027
- selections.push(await this.buildTemplateFragments(tem));
7029
+ selections.push(await this.buildTemplateFragments(tem, depth));
7028
7030
  }
7029
7031
  });
7030
- return astBuilder.FragmentDefinition({
7031
- name: name2,
7032
- fragmentName,
7033
- selections: filterSelections(selections)
7034
- });
7035
7032
  }
7033
+ return selections;
7036
7034
  };
7037
- this._buildFieldNodeForFragments = async (field) => {
7035
+ this._buildFieldNodeForFragments = async (field, depth) => {
7038
7036
  switch (field.type) {
7039
7037
  case "string":
7040
7038
  case "image":
@@ -7045,37 +7043,62 @@ var Builder = class {
7045
7043
  return astBuilder.FieldNodeDefinition(field);
7046
7044
  case "object":
7047
7045
  if (typeof field.fields === "object") {
7048
- const selections = [];
7046
+ const selections2 = [];
7049
7047
  await sequential(field.fields, async (item) => {
7050
- const field2 = await this._buildFieldNodeForFragments(item);
7051
- selections.push(field2);
7048
+ const field2 = await this._buildFieldNodeForFragments(item, depth);
7049
+ selections2.push(field2);
7052
7050
  });
7053
7051
  return astBuilder.FieldWithSelectionSetDefinition({
7054
7052
  name: field.name,
7055
7053
  selections: [
7056
7054
  { kind: "Field", name: { kind: "Name", value: "__typename" } },
7057
- ...filterSelections(selections)
7055
+ ...filterSelections(selections2)
7058
7056
  ]
7059
7057
  });
7060
7058
  } else if (typeof field.templates === "object") {
7061
- const selections = [];
7059
+ const selections2 = [];
7062
7060
  await sequential(field.templates, async (tem) => {
7063
7061
  if (typeof tem === "object") {
7064
- selections.push(await this.buildTemplateFragments(tem));
7062
+ selections2.push(await this.buildTemplateFragments(tem, depth));
7065
7063
  }
7066
7064
  });
7067
7065
  return astBuilder.FieldWithSelectionSetDefinition({
7068
7066
  name: field.name,
7069
7067
  selections: [
7070
7068
  { kind: "Field", name: { kind: "Name", value: "__typename" } },
7071
- ...filterSelections(selections)
7069
+ ...filterSelections(selections2)
7072
7070
  ]
7073
7071
  });
7074
7072
  }
7075
7073
  case "reference":
7074
+ if (depth >= this.maxDepth)
7075
+ return false;
7076
+ if (!("collections" in field)) {
7077
+ return false;
7078
+ }
7079
+ const selections = [];
7080
+ await sequential(field.collections, async (col) => {
7081
+ const collection = this.tinaSchema.getCollection(col);
7082
+ selections.push({
7083
+ kind: "InlineFragment",
7084
+ typeCondition: {
7085
+ kind: "NamedType",
7086
+ name: {
7087
+ kind: "Name",
7088
+ value: NAMER.documentTypeName(collection.namespace)
7089
+ }
7090
+ },
7091
+ directives: [],
7092
+ selectionSet: {
7093
+ kind: "SelectionSet",
7094
+ selections: filterSelections(await this._getCollectionFragmentSelections(collection, depth + 1))
7095
+ }
7096
+ });
7097
+ });
7076
7098
  return astBuilder.FieldWithSelectionSetDefinition({
7077
7099
  name: field.name,
7078
7100
  selections: [
7101
+ ...selections,
7079
7102
  {
7080
7103
  kind: "InlineFragment",
7081
7104
  typeCondition: {
@@ -7716,13 +7739,15 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
7716
7739
  ]
7717
7740
  });
7718
7741
  };
7742
+ var _a, _b, _c, _d;
7743
+ this.maxDepth = (_d = (_c = (_b = (_a = config == null ? void 0 : config.tinaSchema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.client) == null ? void 0 : _c.referenceDepth) != null ? _d : 5;
7719
7744
  this.tinaSchema = config.tinaSchema;
7720
7745
  this.database = config.database;
7721
7746
  }
7722
- async buildTemplateFragments(template) {
7747
+ async buildTemplateFragments(template, depth) {
7723
7748
  const selections = [];
7724
7749
  await sequential(template.fields || [], async (item) => {
7725
- const field = await this._buildFieldNodeForFragments(item);
7750
+ const field = await this._buildFieldNodeForFragments(item, depth);
7726
7751
  selections.push(field);
7727
7752
  });
7728
7753
  return astBuilder.InlineFragmentDefinition({
@@ -7873,7 +7898,7 @@ var validateField = async (field) => {
7873
7898
 
7874
7899
  // package.json
7875
7900
  var name = "@tinacms/graphql";
7876
- var version = "0.61.6";
7901
+ var version = "0.62.0";
7877
7902
  var main = "dist/index.js";
7878
7903
  var typings = "dist/index.d.ts";
7879
7904
  var files = [
@@ -8230,7 +8255,11 @@ var TinaSchema = class {
8230
8255
 
8231
8256
  // src/build.ts
8232
8257
  var import_path = __toModule(require("path"));
8233
- var indexDB = async ({
8258
+ var indexDB = async (args) => {
8259
+ const { graphQLSchema, tinaSchema } = await buildFiles(args);
8260
+ await args.database.indexContent({ graphQLSchema, tinaSchema });
8261
+ };
8262
+ var buildFiles = async ({
8234
8263
  database,
8235
8264
  config,
8236
8265
  flags = [],
@@ -8253,11 +8282,11 @@ var indexDB = async ({
8253
8282
  } else {
8254
8283
  graphQLSchema = JSON.parse(await database.bridge.get(".tina/__generated__/_graphql.json"));
8255
8284
  }
8256
- await database.indexContent({ graphQLSchema, tinaSchema });
8257
8285
  if (buildSDK) {
8258
8286
  await _buildFragments(builder, tinaSchema, database.bridge.rootPath);
8259
8287
  await _buildQueries(builder, tinaSchema, database.bridge.rootPath);
8260
8288
  }
8289
+ return { graphQLSchema, tinaSchema };
8261
8290
  };
8262
8291
  var _buildFragments = async (builder, tinaSchema, rootPath) => {
8263
8292
  const fragmentDefinitionsFields = [];
@@ -24469,46 +24498,35 @@ var Resolver = class {
24469
24498
  collection,
24470
24499
  hydrator
24471
24500
  }) => {
24472
- var _a, _b, _c, _d;
24473
- let edges;
24474
- let pageInfo;
24475
- const useDataLayer = Boolean((_d = (_c = (_b = (_a = this.tinaSchema) == null ? void 0 : _a.config) == null ? void 0 : _b.meta) == null ? void 0 : _c.flags) == null ? void 0 : _d.find((x) => x === "experimentalData"));
24476
- if (useDataLayer) {
24477
- let conditions;
24478
- if (args.filter) {
24479
- if (collection.fields) {
24480
- conditions = await this.resolveFilterConditions(args.filter, collection.fields, collection.name);
24481
- } else if (collection.templates) {
24482
- for (const templateName of Object.keys(args.filter)) {
24483
- const template = collection.templates.find((template2) => template2.name === templateName);
24484
- if (template) {
24485
- conditions = await this.resolveFilterConditions(args.filter[templateName], template.fields, `${collection.name}.${templateName}`);
24486
- } else {
24487
- throw new Error(`Error template not found: ${templateName} in collection ${collection.name}`);
24488
- }
24501
+ let conditions;
24502
+ if (args.filter) {
24503
+ if (collection.fields) {
24504
+ conditions = await this.resolveFilterConditions(args.filter, collection.fields, collection.name);
24505
+ } else if (collection.templates) {
24506
+ for (const templateName of Object.keys(args.filter)) {
24507
+ const template = collection.templates.find((template2) => template2.name === templateName);
24508
+ if (template) {
24509
+ conditions = await this.resolveFilterConditions(args.filter[templateName], template.fields, `${collection.name}.${templateName}`);
24510
+ } else {
24511
+ throw new Error(`Error template not found: ${templateName} in collection ${collection.name}`);
24489
24512
  }
24490
24513
  }
24491
24514
  }
24492
- const queryOptions = {
24493
- filterChain: (0, import_datalayer.makeFilterChain)({
24494
- conditions: conditions || []
24495
- }),
24496
- collection: collection.name,
24497
- sort: args.sort,
24498
- first: args.first,
24499
- last: args.last,
24500
- before: args.before,
24501
- after: args.after
24502
- };
24503
- const result = await this.database.query(queryOptions, hydrator ? hydrator : this.getDocument);
24504
- edges = result.edges;
24505
- pageInfo = result.pageInfo;
24506
- } else {
24507
- const ext = (collection == null ? void 0 : collection.format) || ".md";
24508
- edges = (await this.database.store.glob(collection.path, this.getDocument, ext)).map((document3) => ({
24509
- node: document3
24510
- }));
24511
24515
  }
24516
+ const queryOptions = {
24517
+ filterChain: (0, import_datalayer.makeFilterChain)({
24518
+ conditions: conditions || []
24519
+ }),
24520
+ collection: collection.name,
24521
+ sort: args.sort,
24522
+ first: args.first,
24523
+ last: args.last,
24524
+ before: args.before,
24525
+ after: args.after
24526
+ };
24527
+ const result = await this.database.query(queryOptions, hydrator ? hydrator : this.getDocument);
24528
+ const edges = result.edges;
24529
+ const pageInfo = result.pageInfo;
24512
24530
  return {
24513
24531
  totalCount: edges.length,
24514
24532
  edges,
@@ -25422,11 +25440,15 @@ var _deleteIndexContent = async (database, documentPaths, collection) => {
25422
25440
  };
25423
25441
 
25424
25442
  // src/index.ts
25425
- var buildSchema = async (rootPath, database, flags) => {
25443
+ var buildSchema = async (rootPath, database, flags, skipIndexing) => {
25426
25444
  const tempConfig = import_path5.default.join(rootPath, ".tina", "__generated__", "config");
25427
25445
  const config = await import_fs_extra2.default.readFileSync(import_path5.default.join(tempConfig, "schema.json")).toString();
25428
25446
  await import_fs_extra2.default.rm(tempConfig, { recursive: true });
25429
- await indexDB({ database, config: JSON.parse(config), flags });
25447
+ if (skipIndexing != null ? skipIndexing : false) {
25448
+ await buildFiles({ database, config: JSON.parse(config), flags });
25449
+ } else {
25450
+ await indexDB({ database, config: JSON.parse(config), flags });
25451
+ }
25430
25452
  const gqlAst = await database.getGraphQLSchemaFromBridge();
25431
25453
  return (0, import_graphql5.buildASTSchema)(gqlAst);
25432
25454
  };
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -210,9 +210,17 @@ export declare class Resolver {
210
210
  collection: TinaCloudCollection<true>;
211
211
  hydrator?: (string: any) => any;
212
212
  }) => Promise<{
213
- totalCount: any;
214
- edges: any;
215
- pageInfo: any;
213
+ totalCount: number;
214
+ edges: {
215
+ node: any;
216
+ cursor: string;
217
+ }[];
218
+ pageInfo: {
219
+ hasPreviousPage: boolean;
220
+ hasNextPage: boolean;
221
+ startCursor: string;
222
+ endCursor: string;
223
+ };
216
224
  }>;
217
225
  private buildFieldMutations;
218
226
  private resolveFieldData;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.61.6",
3
+ "version": "0.62.0",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
42
- "@tinacms/datalayer": "0.2.1",
43
- "@tinacms/schema-tools": "0.0.8",
42
+ "@tinacms/datalayer": "0.2.2",
43
+ "@tinacms/schema-tools": "0.0.9",
44
44
  "body-parser": "^1.19.0",
45
45
  "cors": "^2.8.5",
46
46
  "dataloader": "^2.0.0",
@@ -90,8 +90,8 @@
90
90
  "directory": "packages/tina-graphql"
91
91
  },
92
92
  "devDependencies": {
93
- "@tinacms/datalayer": "0.2.1",
94
- "@tinacms/schema-tools": "0.0.8",
93
+ "@tinacms/datalayer": "0.2.2",
94
+ "@tinacms/schema-tools": "0.0.9",
95
95
  "@tinacms/scripts": "0.50.9",
96
96
  "@types/cors": "^2.8.7",
97
97
  "@types/estree": "^0.0.50",
@@ -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
- export { indexDB } from './build';
14
- export { resolve } from './resolve';
15
- export * from './resolver/error';
16
- export { createDatabase } from './database';
17
- export type { QueryOptions } from './database';
18
- import type { Database } from './database';
19
- export type { Database } from './database';
20
- export type { Store } from '@tinacms/datalayer';
21
- export type { Bridge } from './database/bridge';
22
- export { sequential, assertShape } from './util';
23
- export { stringifyFile, parseFile } from './database/util';
24
- export declare const buildSchema: (rootPath: string, database: Database, flags?: string[]) => Promise<import("graphql").GraphQLSchema>;
25
- import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from './types';
26
- export declare type TinaCloudSchema = TinaCloudSchemaBase<false>;
27
- export declare type TinaSchema = TinaCloudSchema;
28
- export declare type TinaCloudCollection = TinaCloudCollectionBase<false>;
29
- export declare type TinaCollection = TinaCloudCollectionBase<false>;
30
- export declare type TinaField = TinaFieldBase;
31
- export type { TinaTemplate };