@tinacms/graphql 0.60.2 → 0.60.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # tina-graphql
2
2
 
3
+ ## 0.60.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 57f09bdd7: Always use the query function when the dataLayer in enabled
8
+
9
+ ## 0.60.4
10
+
11
+ ### Patch Changes
12
+
13
+ - d103b27ad: Fix issue where new collections would not be added when CLI restarts
14
+
15
+ ## 0.60.3
16
+
17
+ ### Patch Changes
18
+
19
+ - 79d112d79: Update cli to accept tinaCloudMediaStore flag and add to metadata during schema compilation
20
+ - 3f46c6706: Fixed issue where generated SDK would not work with templates
21
+ - db9168578: Adds support for an `assetsHost` when resolving `image` fields with `useRelativeMedia`
22
+ - 91d6e6758: Fix issues with experimentalData on windows related to path separator inconsistency and interference with the .tina/**generated** folder
23
+
3
24
  ## 0.60.2
4
25
 
5
26
  ### Patch Changes
package/dist/build.d.ts CHANGED
@@ -12,8 +12,9 @@ limitations under the License.
12
12
  */
13
13
  import type { TinaSchema } from './schema';
14
14
  import { Database } from './database';
15
- export declare const indexDB: ({ database, config, buildSDK, }: {
15
+ export declare const indexDB: ({ database, config, flags, buildSDK, }: {
16
16
  database: Database;
17
17
  config: TinaSchema['config'];
18
+ flags?: string[];
18
19
  buildSDK?: boolean;
19
20
  }) => Promise<void>;
@@ -44,8 +44,6 @@ export declare class Database {
44
44
  private tinaSchema;
45
45
  private collectionIndexDefinitions;
46
46
  private _lookup;
47
- private _graphql;
48
- private _tinaSchema;
49
47
  constructor(config: CreateDatabase);
50
48
  private collectionForPath;
51
49
  private partitionPathsByCollection;
@@ -65,6 +63,10 @@ export declare class Database {
65
63
  };
66
64
  keepTemplateKey: boolean;
67
65
  }>;
66
+ /**
67
+ * Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
68
+ */
69
+ clearCache(): void;
68
70
  flush: (filepath: string) => Promise<string>;
69
71
  getLookup: (returnType: string) => Promise<LookupMapType>;
70
72
  getGraphQLSchema: () => Promise<DocumentNode>;
@@ -14,3 +14,4 @@ import * as yup from 'yup';
14
14
  export declare const stringifyFile: (content: object, format: FormatType | string, keepTemplateKey: boolean) => string;
15
15
  export declare const parseFile: <T extends object>(content: string, format: FormatType | string, yupSchema: (args: typeof yup) => yup.ObjectSchema<any>) => T;
16
16
  export declare type FormatType = 'json' | 'md' | 'mdx' | 'markdown';
17
+ export declare const normalizePath: (filepath: string) => string;
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export type { Store } from '@tinacms/datalayer';
20
20
  export type { Bridge } from './database/bridge';
21
21
  export { sequential, assertShape } from './util';
22
22
  export { stringifyFile, parseFile } from './database/util';
23
- export declare const buildSchema: (rootPath: string, database: Database) => Promise<import("graphql").GraphQLSchema>;
23
+ export declare const buildSchema: (rootPath: string, database: Database, flags?: string[]) => Promise<import("graphql").GraphQLSchema>;
24
24
  import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from './types';
25
25
  export declare type TinaCloudSchema = TinaCloudSchemaBase<false>;
26
26
  export declare type TinaSchema = TinaCloudSchema;
package/dist/index.js CHANGED
@@ -10911,15 +10911,31 @@ var astBuilder = {
10911
10911
  selectionSet: {
10912
10912
  kind: "SelectionSet",
10913
10913
  selections: [
10914
- SysFieldDefinition,
10915
10914
  {
10916
- kind: "Field",
10917
- name: {
10918
- kind: "Name",
10919
- value: "id"
10915
+ kind: "InlineFragment",
10916
+ typeCondition: {
10917
+ kind: "NamedType",
10918
+ name: {
10919
+ kind: "Name",
10920
+ value: "Document"
10921
+ }
10920
10922
  },
10921
- arguments: [],
10922
- directives: []
10923
+ directives: [],
10924
+ selectionSet: {
10925
+ kind: "SelectionSet",
10926
+ selections: [
10927
+ SysFieldDefinition,
10928
+ {
10929
+ kind: "Field",
10930
+ name: {
10931
+ kind: "Name",
10932
+ value: "id"
10933
+ },
10934
+ arguments: [],
10935
+ directives: []
10936
+ }
10937
+ ]
10938
+ }
10923
10939
  },
10924
10940
  {
10925
10941
  kind: "FragmentSpread",
@@ -10995,15 +11011,31 @@ var astBuilder = {
10995
11011
  kind: "SelectionSet",
10996
11012
  selections: [
10997
11013
  {
10998
- kind: "Field",
10999
- name: {
11000
- kind: "Name",
11001
- value: "id"
11014
+ kind: "InlineFragment",
11015
+ typeCondition: {
11016
+ kind: "NamedType",
11017
+ name: {
11018
+ kind: "Name",
11019
+ value: "Document"
11020
+ }
11002
11021
  },
11003
- arguments: [],
11004
- directives: []
11022
+ directives: [],
11023
+ selectionSet: {
11024
+ kind: "SelectionSet",
11025
+ selections: [
11026
+ SysFieldDefinition,
11027
+ {
11028
+ kind: "Field",
11029
+ name: {
11030
+ kind: "Name",
11031
+ value: "id"
11032
+ },
11033
+ arguments: [],
11034
+ directives: []
11035
+ }
11036
+ ]
11037
+ }
11005
11038
  },
11006
- SysFieldDefinition,
11007
11039
  {
11008
11040
  kind: "FragmentSpread",
11009
11041
  name: {
@@ -12448,7 +12480,7 @@ var validateField = async (field) => {
12448
12480
 
12449
12481
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/package.json
12450
12482
  var name = "@tinacms/graphql";
12451
- var version = "0.60.2";
12483
+ var version = "0.60.5";
12452
12484
  var main = "dist/index.js";
12453
12485
  var typings = "dist/index.d.ts";
12454
12486
  var files = [
@@ -12490,7 +12522,8 @@ var scripts = {
12490
12522
  build: 'echo "Run `yarn build` from the root of the repository instead"',
12491
12523
  docs: "yarn typedoc",
12492
12524
  serve: "yarn nodemon dist/server.js",
12493
- test: "jest"
12525
+ test: "jest",
12526
+ "test-watch": "jest --watch"
12494
12527
  };
12495
12528
  var dependencies = {
12496
12529
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
@@ -12773,11 +12806,13 @@ var import_path = __toModule(require("path"));
12773
12806
  var indexDB = async ({
12774
12807
  database,
12775
12808
  config,
12809
+ flags = [],
12776
12810
  buildSDK = true
12777
12811
  }) => {
12778
- const flags = [];
12779
12812
  if (database.store.supportsIndexing()) {
12780
- flags.push("experimentalData");
12813
+ if (flags.indexOf("experimentalData") === -1) {
12814
+ flags.push("experimentalData");
12815
+ }
12781
12816
  }
12782
12817
  const tinaSchema = await createSchema({ schema: config, flags });
12783
12818
  const builder = await createBuilder({
@@ -22716,10 +22751,6 @@ var Resolver = class {
22716
22751
  })
22717
22752
  };
22718
22753
  };
22719
- this.getDocumentsForCollection = async (collectionName) => {
22720
- const collection = this.tinaSchema.getCollection(collectionName);
22721
- return this.database.store.glob(collection.path, this.getDocument);
22722
- };
22723
22754
  this.referenceResolver = async (filter, fieldDefinition) => {
22724
22755
  const referencedCollection = this.tinaSchema.getCollection(fieldDefinition.collections[0]);
22725
22756
  if (!referencedCollection) {
@@ -22744,9 +22775,11 @@ var Resolver = class {
22744
22775
  collection,
22745
22776
  hydrator
22746
22777
  }) => {
22778
+ var _a, _b, _c, _d;
22747
22779
  let edges;
22748
22780
  let pageInfo;
22749
- if (args.filter || args.sort) {
22781
+ 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"));
22782
+ if (useDataLayer) {
22750
22783
  let conditions;
22751
22784
  if (args.filter) {
22752
22785
  if (collection.fields) {
@@ -22856,7 +22889,7 @@ var Resolver = class {
22856
22889
  if (this.config.useRelativeMedia === true) {
22857
22890
  accumulator[field.name] = value;
22858
22891
  } else {
22859
- accumulator[field.name] = `https://assets.tina.io/${this.config.clientId}/${value}`;
22892
+ accumulator[field.name] = `https://${this.config.assetsHost}/${this.config.clientId}/${value}`;
22860
22893
  }
22861
22894
  } else {
22862
22895
  accumulator[field.name] = value;
@@ -22970,12 +23003,14 @@ var resolve = async ({
22970
23003
  database,
22971
23004
  silenceErrors
22972
23005
  }) => {
23006
+ var _a;
22973
23007
  try {
22974
23008
  const graphQLSchemaAst = await database.getGraphQLSchema();
22975
23009
  const graphQLSchema = (0, import_graphql3.buildASTSchema)(graphQLSchemaAst);
22976
23010
  const tinaConfig = await database.getTinaSchema();
22977
23011
  const tinaSchema = await createSchema({
22978
- schema: tinaConfig
23012
+ schema: tinaConfig,
23013
+ flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
22979
23014
  });
22980
23015
  const resolver2 = await createResolver2({ config, database, tinaSchema });
22981
23016
  const res = await (0, import_graphql3.graphql)({
@@ -23009,8 +23044,8 @@ var resolve = async ({
23009
23044
  if (info.fieldName === "collections") {
23010
23045
  const collectionNode2 = info.fieldNodes.find((x) => x.name.value === "collections");
23011
23046
  const hasDocuments2 = collectionNode2.selectionSet.selections.find((x) => {
23012
- var _a;
23013
- return ((_a = x == null ? void 0 : x.name) == null ? void 0 : _a.value) === "documents";
23047
+ var _a2;
23048
+ return ((_a2 = x == null ? void 0 : x.name) == null ? void 0 : _a2.value) === "documents";
23014
23049
  });
23015
23050
  return tinaSchema.getCollections().map((collection) => {
23016
23051
  return resolver2.resolveCollection(args, collection.name, Boolean(hasDocuments2));
@@ -23018,8 +23053,8 @@ var resolve = async ({
23018
23053
  }
23019
23054
  const collectionNode = info.fieldNodes.find((x) => x.name.value === "collection");
23020
23055
  const hasDocuments = collectionNode.selectionSet.selections.find((x) => {
23021
- var _a;
23022
- return ((_a = x == null ? void 0 : x.name) == null ? void 0 : _a.value) === "documents";
23056
+ var _a2;
23057
+ return ((_a2 = x == null ? void 0 : x.name) == null ? void 0 : _a2.value) === "documents";
23023
23058
  });
23024
23059
  return resolver2.resolveCollection(args, args.collection, Boolean(hasDocuments));
23025
23060
  }
@@ -23208,6 +23243,7 @@ var parseFile = (content3, format, yupSchema) => {
23208
23243
  throw new Error(`Must specify a valid format, got ${format}`);
23209
23244
  }
23210
23245
  };
23246
+ var normalizePath = (filepath) => filepath.replace(/\\/g, "/");
23211
23247
 
23212
23248
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/database/index.ts
23213
23249
  var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
@@ -23234,7 +23270,7 @@ var Database = class {
23234
23270
  } else {
23235
23271
  const tinaSchema = await this.getSchema();
23236
23272
  const extension2 = import_path4.default.extname(filepath);
23237
- const contentObject = await this.store.get(filepath);
23273
+ const contentObject = await this.store.get(normalizePath(filepath));
23238
23274
  if (!contentObject) {
23239
23275
  throw new import_graphql4.GraphQLError(`Unable to find record ${filepath}`);
23240
23276
  }
@@ -23274,9 +23310,9 @@ var Database = class {
23274
23310
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23275
23311
  }
23276
23312
  if (this.store.supportsSeeding()) {
23277
- await this.bridge.put(filepath, stringifiedFile);
23313
+ await this.bridge.put(normalizePath(filepath), stringifiedFile);
23278
23314
  }
23279
- await this.store.put(filepath, payload, {
23315
+ await this.store.put(normalizePath(filepath), payload, {
23280
23316
  keepTemplateKey,
23281
23317
  collection: collection == null ? void 0 : collection.name,
23282
23318
  indexDefinitions: collectionIndexDefinitions
@@ -23293,9 +23329,9 @@ var Database = class {
23293
23329
  }
23294
23330
  const { stringifiedFile, payload, keepTemplateKey } = await this.stringifyFile(filepath, data);
23295
23331
  if (this.store.supportsSeeding()) {
23296
- await this.bridge.put(filepath, stringifiedFile);
23332
+ await this.bridge.put(normalizePath(filepath), stringifiedFile);
23297
23333
  }
23298
- await this.store.put(filepath, payload, {
23334
+ await this.store.put(normalizePath(filepath), payload, {
23299
23335
  keepTemplateKey,
23300
23336
  collection,
23301
23337
  indexDefinitions: collectionIndexDefinitions
@@ -23360,23 +23396,23 @@ var Database = class {
23360
23396
  this.getLookup = async (returnType) => {
23361
23397
  const lookupPath = import_path4.default.join(GENERATED_FOLDER, `_lookup.json`);
23362
23398
  if (!this._lookup) {
23363
- const _lookup = await this.store.get(lookupPath);
23399
+ const _lookup = await this.store.get(normalizePath(lookupPath));
23364
23400
  this._lookup = _lookup;
23365
23401
  }
23366
23402
  return this._lookup[returnType];
23367
23403
  };
23368
23404
  this.getGraphQLSchema = async () => {
23369
23405
  const graphqlPath = import_path4.default.join(GENERATED_FOLDER, `_graphql.json`);
23370
- return this.store.get(graphqlPath);
23406
+ return this.store.get(normalizePath(graphqlPath));
23371
23407
  };
23372
23408
  this.getGraphQLSchemaFromBridge = async () => {
23373
23409
  const graphqlPath = import_path4.default.join(GENERATED_FOLDER, `_graphql.json`);
23374
- const _graphql = await this.bridge.get(graphqlPath);
23410
+ const _graphql = await this.bridge.get(normalizePath(graphqlPath));
23375
23411
  return JSON.parse(_graphql);
23376
23412
  };
23377
23413
  this.getTinaSchema = async () => {
23378
23414
  const schemaPath = import_path4.default.join(GENERATED_FOLDER, `_schema.json`);
23379
- return this.store.get(schemaPath);
23415
+ return this.store.get(normalizePath(schemaPath));
23380
23416
  };
23381
23417
  this.getSchema = async () => {
23382
23418
  if (this.tinaSchema) {
@@ -23496,8 +23532,8 @@ var Database = class {
23496
23532
  tinaSchema
23497
23533
  }) => {
23498
23534
  if (this.bridge.supportsBuilding()) {
23499
- await this.bridge.putConfig(import_path4.default.join(GENERATED_FOLDER, `_graphql.json`), JSON.stringify(graphQLSchema));
23500
- await this.bridge.putConfig(import_path4.default.join(GENERATED_FOLDER, `_schema.json`), JSON.stringify(tinaSchema.schema));
23535
+ await this.bridge.putConfig(normalizePath(import_path4.default.join(GENERATED_FOLDER, `_graphql.json`)), JSON.stringify(graphQLSchema));
23536
+ await this.bridge.putConfig(normalizePath(import_path4.default.join(GENERATED_FOLDER, `_schema.json`)), JSON.stringify(tinaSchema.schema));
23501
23537
  }
23502
23538
  };
23503
23539
  this.indexContent = async ({
@@ -23505,12 +23541,12 @@ var Database = class {
23505
23541
  tinaSchema
23506
23542
  }) => {
23507
23543
  await this.indexStatusCallbackWrapper(async () => {
23508
- const lookup = JSON.parse(await this.bridge.get(import_path4.default.join(GENERATED_FOLDER, "_lookup.json")));
23544
+ const lookup = JSON.parse(await this.bridge.get(normalizePath(import_path4.default.join(GENERATED_FOLDER, "_lookup.json"))));
23509
23545
  if (this.store.supportsSeeding()) {
23510
23546
  await this.store.clear();
23511
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_graphql.json"), graphQLSchema);
23512
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_schema.json"), tinaSchema.schema);
23513
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_lookup.json"), lookup);
23547
+ await this.store.seed(normalizePath(import_path4.default.join(GENERATED_FOLDER, "_graphql.json")), graphQLSchema);
23548
+ await this.store.seed(normalizePath(import_path4.default.join(GENERATED_FOLDER, "_schema.json")), tinaSchema.schema);
23549
+ await this.store.seed(normalizePath(import_path4.default.join(GENERATED_FOLDER, "_lookup.json")), lookup);
23514
23550
  await this._indexAllContent();
23515
23551
  } else {
23516
23552
  if (this.store.supportsIndexing()) {
@@ -23544,16 +23580,16 @@ var Database = class {
23544
23580
  const indexDefinitions = await this.getIndexDefinitions();
23545
23581
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23546
23582
  }
23547
- await this.store.delete(filepath, {
23583
+ await this.store.delete(normalizePath(filepath), {
23548
23584
  collection: collection.name,
23549
23585
  indexDefinitions: collectionIndexDefinitions
23550
23586
  });
23551
- await this.bridge.delete(filepath);
23587
+ await this.bridge.delete(normalizePath(filepath));
23552
23588
  };
23553
23589
  this._indexAllContent = async () => {
23554
23590
  const tinaSchema = await this.getSchema();
23555
23591
  await sequential(tinaSchema.getCollections(), async (collection) => {
23556
- const documentPaths = await this.bridge.glob(collection.path);
23592
+ const documentPaths = await this.bridge.glob(normalizePath(collection.path));
23557
23593
  await _indexContent(this, documentPaths, collection);
23558
23594
  });
23559
23595
  };
@@ -23561,14 +23597,14 @@ var Database = class {
23561
23597
  const lookupPath = import_path4.default.join(GENERATED_FOLDER, `_lookup.json`);
23562
23598
  let lookupMap;
23563
23599
  try {
23564
- lookupMap = JSON.parse(await this.bridge.get(lookupPath));
23600
+ lookupMap = JSON.parse(await this.bridge.get(normalizePath(lookupPath)));
23565
23601
  } catch (e) {
23566
23602
  lookupMap = {};
23567
23603
  }
23568
23604
  const updatedLookup = __spreadProps(__spreadValues({}, lookupMap), {
23569
23605
  [lookup.type]: lookup
23570
23606
  });
23571
- await this.bridge.putConfig(lookupPath, JSON.stringify(updatedLookup));
23607
+ await this.bridge.putConfig(normalizePath(lookupPath), JSON.stringify(updatedLookup));
23572
23608
  };
23573
23609
  this.bridge = config.bridge;
23574
23610
  this.store = config.store;
@@ -23592,6 +23628,10 @@ var Database = class {
23592
23628
  }
23593
23629
  return { pathsByCollection, nonCollectionPaths, collections };
23594
23630
  }
23631
+ clearCache() {
23632
+ this.tinaSchema = null;
23633
+ this._lookup = null;
23634
+ }
23595
23635
  async indexStatusCallbackWrapper(fn) {
23596
23636
  await this.indexStatusCallback({ status: "inprogress" });
23597
23637
  try {
@@ -23624,10 +23664,10 @@ var _indexContent = async (database, documentPaths, collection) => {
23624
23664
  };
23625
23665
  }
23626
23666
  await sequential(documentPaths, async (filepath) => {
23627
- const dataString = await database.bridge.get(filepath);
23667
+ const dataString = await database.bridge.get(normalizePath(filepath));
23628
23668
  const data = parseFile(dataString, import_path4.default.extname(filepath), (yup3) => yup3.object({}));
23629
23669
  if (database.store.supportsSeeding()) {
23630
- await database.store.seed(filepath, data, seedOptions);
23670
+ await database.store.seed(normalizePath(filepath), data, seedOptions);
23631
23671
  }
23632
23672
  });
23633
23673
  };
@@ -23650,11 +23690,11 @@ var _deleteIndexContent = async (database, documentPaths, collection) => {
23650
23690
  };
23651
23691
 
23652
23692
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/index.ts
23653
- var buildSchema = async (rootPath, database) => {
23693
+ var buildSchema = async (rootPath, database, flags) => {
23654
23694
  const tempConfig = import_path5.default.join(rootPath, ".tina", "__generated__", "config");
23655
23695
  const config = await import_fs_extra2.default.readFileSync(import_path5.default.join(tempConfig, "schema.json")).toString();
23656
23696
  await import_fs_extra2.default.rmdir(tempConfig, { recursive: true });
23657
- await indexDB({ database, config: JSON.parse(config) });
23697
+ await indexDB({ database, config: JSON.parse(config), flags });
23658
23698
  const gqlAst = await database.getGraphQLSchemaFromBridge();
23659
23699
  return (0, import_graphql5.buildASTSchema)(gqlAst);
23660
23700
  };
@@ -203,7 +203,6 @@ export declare class Resolver {
203
203
  };
204
204
  }[];
205
205
  }>;
206
- getDocumentsForCollection: (collectionName: string) => Promise<string[]>;
207
206
  private referenceResolver;
208
207
  private resolveFilterConditions;
209
208
  resolveCollectionConnection: ({ args, collection, hydrator, }: {
package/dist/types.d.ts CHANGED
@@ -268,5 +268,6 @@ export declare type GraphQLConfig = {
268
268
  } | {
269
269
  useRelativeMedia: false;
270
270
  clientId: string;
271
+ assetsHost: string;
271
272
  };
272
273
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.60.2",
3
+ "version": "0.60.5",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -42,7 +42,8 @@
42
42
  "build": "echo \"Run `yarn build` from the root of the repository instead\"",
43
43
  "docs": "yarn typedoc",
44
44
  "serve": "yarn nodemon dist/server.js",
45
- "test": "jest"
45
+ "test": "jest",
46
+ "test-watch": "jest --watch"
46
47
  },
47
48
  "dependencies": {
48
49
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",