@tinacms/graphql 0.63.3 → 0.63.6

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/dist/build.d.ts CHANGED
@@ -13,17 +13,7 @@ limitations under the License.
13
13
  import { DocumentNode } from 'graphql';
14
14
  import type { TinaSchema } from './schema';
15
15
  import { Database } from './database';
16
- /**
17
- *
18
- * This will build the files (_schema.json, _lookup.json, _graphQL.json)
19
- */
20
- export declare const indexDB: (args: {
21
- database: Database;
22
- config: TinaSchema['config'];
23
- flags?: string[];
24
- buildSDK?: boolean;
25
- }) => Promise<void>;
26
- export declare const buildFiles: ({ database, config, flags, buildSDK, }: {
16
+ export declare const buildDotTinaFiles: ({ database, config, flags, buildSDK, }: {
27
17
  database: Database;
28
18
  config: TinaSchema['config'];
29
19
  flags?: string[];
package/dist/index.d.ts CHANGED
@@ -10,7 +10,6 @@ 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 { indexDB } from './build';
14
13
  export { resolve } from './resolve';
15
14
  export * from './resolver/error';
16
15
  export { createDatabase } from './database';
@@ -22,7 +21,11 @@ export type { Bridge } from './database/bridge';
22
21
  export { sequential, assertShape } from './util';
23
22
  export { stringifyFile, parseFile } from './database/util';
24
23
  export declare type DummyType = unknown;
25
- export declare const buildSchema: (rootPath: string, database: Database, flags?: string[], skipIndexing?: boolean) => Promise<import("graphql").GraphQLSchema>;
24
+ export declare const buildSchema: (rootPath: string, database: Database, flags?: string[]) => Promise<{
25
+ graphQLSchema: import("graphql").DocumentNode;
26
+ tinaSchema: import("./schema").TinaSchema;
27
+ }>;
28
+ export declare const getASTSchema: (database: Database) => Promise<import("graphql").GraphQLSchema>;
26
29
  import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from './types';
27
30
  export declare type TinaCloudSchema = TinaCloudSchemaBase<false>;
28
31
  export declare type TinaSchema = TinaCloudSchema;
package/dist/index.js CHANGED
@@ -60,8 +60,8 @@ __export(exports, {
60
60
  assertShape: () => assertShape,
61
61
  buildSchema: () => buildSchema,
62
62
  createDatabase: () => createDatabase,
63
+ getASTSchema: () => getASTSchema,
63
64
  handleFetchErrorError: () => handleFetchErrorError,
64
- indexDB: () => indexDB,
65
65
  parseFile: () => parseFile,
66
66
  resolve: () => resolve,
67
67
  sequential: () => sequential,
@@ -69,7 +69,7 @@ __export(exports, {
69
69
  });
70
70
  var import_fs_extra2 = __toModule(require("fs-extra"));
71
71
  var import_path4 = __toModule(require("path"));
72
- var import_graphql5 = __toModule(require("graphql"));
72
+ var import_graphql6 = __toModule(require("graphql"));
73
73
 
74
74
  // src/build.ts
75
75
  var import_lodash3 = __toModule(require("lodash"));
@@ -2437,7 +2437,7 @@ var validateField = async (field) => {
2437
2437
 
2438
2438
  // package.json
2439
2439
  var name = "@tinacms/graphql";
2440
- var version = "0.63.3";
2440
+ var version = "0.63.6";
2441
2441
  var main = "dist/index.js";
2442
2442
  var typings = "dist/index.d.ts";
2443
2443
  var files = [
@@ -2578,17 +2578,18 @@ var TinaFetchError = class extends Error {
2578
2578
  };
2579
2579
  var TinaQueryError = class extends TinaFetchError {
2580
2580
  constructor(args) {
2581
- super(`Error querying file ${args.file} collection ${args.collection}. Please run "tinacms audit" or add the --verbose option for more info`, args);
2581
+ super(`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2582
2582
  }
2583
2583
  };
2584
2584
  var TinaParseDocumentError = class extends TinaFetchError {
2585
2585
  constructor(args) {
2586
- super(`Error Parsing file ${args.file} collection ${args.collection}. Please run "tinacms audit" or add the --verbose option for more info`, args);
2586
+ super(`Error Parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2587
2587
  }
2588
2588
  toString() {
2589
2589
  return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
2590
2590
  }
2591
2591
  };
2592
+ var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
2592
2593
  var handleFetchErrorError = (e, verbose) => {
2593
2594
  if (e instanceof Error) {
2594
2595
  if (e instanceof TinaFetchError) {
@@ -2667,9 +2668,9 @@ var TinaSchema = class {
2667
2668
  }
2668
2669
  return globalTemplate;
2669
2670
  };
2670
- this.getCollectionByFullPath = async (filepath) => {
2671
+ this.getCollectionByFullPath = (filepath) => {
2671
2672
  const collection = this.getCollections().find((collection2) => {
2672
- return filepath.replace("\\", "/").startsWith(collection2.path);
2673
+ return filepath.replace("\\", "/").startsWith(collection2.path.replace(/\/?$/, "/"));
2673
2674
  });
2674
2675
  if (!collection) {
2675
2676
  throw new Error(`Unable to find collection for file at ${filepath}`);
@@ -2678,12 +2679,7 @@ var TinaSchema = class {
2678
2679
  };
2679
2680
  this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
2680
2681
  let template;
2681
- const collection = this.getCollections().find((collection2) => {
2682
- return filepath.replace("\\", "/").startsWith(collection2.path);
2683
- });
2684
- if (!collection) {
2685
- throw new Error(`Unable to find collection for file at ${filepath}`);
2686
- }
2682
+ const collection = this.getCollectionByFullPath(filepath);
2687
2683
  const templates = this.getTemplatesForCollectable(collection);
2688
2684
  if (templates.type === "union") {
2689
2685
  if (templateName) {
@@ -2775,11 +2771,7 @@ var TinaSchema = class {
2775
2771
 
2776
2772
  // src/build.ts
2777
2773
  var import_path = __toModule(require("path"));
2778
- var indexDB = async (args) => {
2779
- const { graphQLSchema, tinaSchema } = await buildFiles(args);
2780
- await args.database.indexContent({ graphQLSchema, tinaSchema });
2781
- };
2782
- var buildFiles = async ({
2774
+ var buildDotTinaFiles = async ({
2783
2775
  database,
2784
2776
  config,
2785
2777
  flags = [],
@@ -2904,7 +2896,7 @@ var _buildSchema = async (builder, tinaSchema) => {
2904
2896
  };
2905
2897
 
2906
2898
  // src/resolve.ts
2907
- var import_graphql3 = __toModule(require("graphql"));
2899
+ var import_graphql4 = __toModule(require("graphql"));
2908
2900
 
2909
2901
  // src/resolver/index.ts
2910
2902
  var import_path2 = __toModule(require("path"));
@@ -3059,6 +3051,7 @@ var hasTinaMediaConfig = (schema) => {
3059
3051
  };
3060
3052
 
3061
3053
  // src/resolver/index.ts
3054
+ var import_graphql3 = __toModule(require("graphql"));
3062
3055
  var createResolver = (args) => {
3063
3056
  return new Resolver(args);
3064
3057
  };
@@ -3102,6 +3095,7 @@ var Resolver = class {
3102
3095
  throw new TinaParseDocumentError({
3103
3096
  originalError: e,
3104
3097
  collection: collection.name,
3098
+ includeAuditMessage: !this.isAudit,
3105
3099
  file: relativePath,
3106
3100
  stack: e.stack
3107
3101
  });
@@ -3435,6 +3429,7 @@ var Resolver = class {
3435
3429
  };
3436
3430
  this.resolveFieldData = async (_a, rawData, accumulator) => {
3437
3431
  var _b = _a, { namespace } = _b, field = __objRest(_b, ["namespace"]);
3432
+ var _a2;
3438
3433
  if (!rawData) {
3439
3434
  return void 0;
3440
3435
  }
@@ -3459,6 +3454,12 @@ var Resolver = class {
3459
3454
  break;
3460
3455
  case "rich-text":
3461
3456
  const tree = (0, import_mdx.parseMDX)(value, field, (value2) => resolveMediaRelativeToCloud(value2, this.config, this.tinaSchema.schema));
3457
+ if (((_a2 = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _a2.type) === "invalid_markdown") {
3458
+ if (this.isAudit) {
3459
+ const invalidNode = tree == null ? void 0 : tree.children[0];
3460
+ throw new import_graphql3.GraphQLError(`${invalidNode == null ? void 0 : invalidNode.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`);
3461
+ }
3462
+ }
3462
3463
  accumulator[field.name] = tree;
3463
3464
  break;
3464
3465
  case "object":
@@ -3525,6 +3526,7 @@ var Resolver = class {
3525
3526
  this.config = init.config;
3526
3527
  this.database = init.database;
3527
3528
  this.tinaSchema = init.tinaSchema;
3529
+ this.isAudit = init.isAudit;
3528
3530
  }
3529
3531
  async resolveFilterConditions(filter, fields, collectionName) {
3530
3532
  const conditions = [];
@@ -3564,20 +3566,26 @@ var resolve = async ({
3564
3566
  variables,
3565
3567
  database,
3566
3568
  silenceErrors,
3567
- verbose
3569
+ verbose,
3570
+ isAudit
3568
3571
  }) => {
3569
3572
  var _a;
3570
3573
  try {
3571
3574
  const verboseValue = verbose != null ? verbose : true;
3572
3575
  const graphQLSchemaAst = await database.getGraphQLSchema();
3573
- const graphQLSchema = (0, import_graphql3.buildASTSchema)(graphQLSchemaAst);
3576
+ const graphQLSchema = (0, import_graphql4.buildASTSchema)(graphQLSchemaAst);
3574
3577
  const tinaConfig = await database.getTinaSchema();
3575
3578
  const tinaSchema = await createSchema({
3576
3579
  schema: tinaConfig,
3577
3580
  flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
3578
3581
  });
3579
- const resolver = await createResolver({ config, database, tinaSchema });
3580
- const res = await (0, import_graphql3.graphql)({
3582
+ const resolver = await createResolver({
3583
+ config,
3584
+ database,
3585
+ tinaSchema,
3586
+ isAudit: isAudit || false
3587
+ });
3588
+ const res = await (0, import_graphql4.graphql)({
3581
3589
  schema: graphQLSchema,
3582
3590
  source: query,
3583
3591
  variableValues: variables,
@@ -3587,7 +3595,7 @@ var resolve = async ({
3587
3595
  typeResolver: async (source, _args, info) => {
3588
3596
  if (source.__typename)
3589
3597
  return source.__typename;
3590
- const namedType = (0, import_graphql3.getNamedType)(info.returnType).toString();
3598
+ const namedType = (0, import_graphql4.getNamedType)(info.returnType).toString();
3591
3599
  const lookup = await database.getLookup(namedType);
3592
3600
  if (lookup.resolveType === "unionData") {
3593
3601
  return lookup.typeMap[source._template];
@@ -3598,7 +3606,7 @@ var resolve = async ({
3598
3606
  fieldResolver: async (source = {}, _args = {}, _context, info) => {
3599
3607
  try {
3600
3608
  const args = JSON.parse(JSON.stringify(_args));
3601
- const returnType = (0, import_graphql3.getNamedType)(info.returnType).toString();
3609
+ const returnType = (0, import_graphql4.getNamedType)(info.returnType).toString();
3602
3610
  const lookup = await database.getLookup(returnType);
3603
3611
  const isMutation = info.parentType.toString() === "Mutation";
3604
3612
  const value = source[info.fieldName];
@@ -3625,12 +3633,12 @@ var resolve = async ({
3625
3633
  }
3626
3634
  if (info.fieldName === "getOptimizedQuery") {
3627
3635
  try {
3628
- const [optimizedQuery] = (0, import_relay_operation_optimizer.optimizeDocuments)(info.schema, [(0, import_graphql3.parse)(args.queryString)], {
3636
+ const [optimizedQuery] = (0, import_relay_operation_optimizer.optimizeDocuments)(info.schema, [(0, import_graphql4.parse)(args.queryString)], {
3629
3637
  assumeValid: true,
3630
3638
  includeFragments: false,
3631
3639
  noLocation: true
3632
3640
  });
3633
- return (0, import_graphql3.print)(optimizedQuery);
3641
+ return (0, import_graphql4.print)(optimizedQuery);
3634
3642
  } catch (e) {
3635
3643
  throw new Error(`Invalid query provided, Error message: ${e.message}`);
3636
3644
  }
@@ -3749,7 +3757,7 @@ var resolve = async ({
3749
3757
  if (!silenceErrors) {
3750
3758
  console.error(e);
3751
3759
  }
3752
- if (e instanceof import_graphql3.GraphQLError) {
3760
+ if (e instanceof import_graphql4.GraphQLError) {
3753
3761
  return {
3754
3762
  errors: [e]
3755
3763
  };
@@ -3761,7 +3769,7 @@ var resolve = async ({
3761
3769
 
3762
3770
  // src/database/index.ts
3763
3771
  var import_path3 = __toModule(require("path"));
3764
- var import_graphql4 = __toModule(require("graphql"));
3772
+ var import_graphql5 = __toModule(require("graphql"));
3765
3773
 
3766
3774
  // src/database/util.ts
3767
3775
  var import_gray_matter = __toModule(require("gray-matter"));
@@ -3836,7 +3844,7 @@ var Database = class {
3836
3844
  this.config = config;
3837
3845
  this.collectionForPath = async (filepath) => {
3838
3846
  const tinaSchema = await this.getSchema();
3839
- const collection = await tinaSchema.getCollectionByFullPath(filepath);
3847
+ const collection = tinaSchema.getCollectionByFullPath(filepath);
3840
3848
  return collection;
3841
3849
  };
3842
3850
  this.get = async (filepath) => {
@@ -3847,7 +3855,7 @@ var Database = class {
3847
3855
  const extension = import_path3.default.extname(filepath);
3848
3856
  const contentObject = await this.store.get(normalizePath(filepath));
3849
3857
  if (!contentObject) {
3850
- throw new import_graphql4.GraphQLError(`Unable to find record ${filepath}`);
3858
+ throw new import_graphql5.GraphQLError(`Unable to find record ${filepath}`);
3851
3859
  }
3852
3860
  const templateName = hasOwnProperty(contentObject, "_template") && typeof contentObject._template === "string" ? contentObject._template : void 0;
3853
3861
  const { collection, template } = tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
@@ -3928,7 +3936,7 @@ var Database = class {
3928
3936
  throw new Error(`Unexpected put for config file ${filepath}`);
3929
3937
  } else {
3930
3938
  const tinaSchema = await this.getSchema();
3931
- const collection = await tinaSchema.getCollectionByFullPath(filepath);
3939
+ const collection = tinaSchema.getCollectionByFullPath(filepath);
3932
3940
  const templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
3933
3941
  let template;
3934
3942
  if (templateInfo.type === "object") {
@@ -4296,17 +4304,20 @@ var _deleteIndexContent = async (database, documentPaths, collection) => {
4296
4304
  };
4297
4305
 
4298
4306
  // src/index.ts
4299
- var buildSchema = async (rootPath, database, flags, skipIndexing) => {
4307
+ var buildSchema = async (rootPath, database, flags) => {
4300
4308
  const tempConfig = import_path4.default.join(rootPath, ".tina", "__generated__", "config");
4301
4309
  const config = await import_fs_extra2.default.readFileSync(import_path4.default.join(tempConfig, "schema.json")).toString();
4302
4310
  await import_fs_extra2.default.rm(tempConfig, { recursive: true });
4303
- if (skipIndexing != null ? skipIndexing : false) {
4304
- await buildFiles({ database, config: JSON.parse(config), flags });
4305
- } else {
4306
- await indexDB({ database, config: JSON.parse(config), flags });
4307
- }
4311
+ const { graphQLSchema, tinaSchema } = await buildDotTinaFiles({
4312
+ database,
4313
+ config: JSON.parse(config),
4314
+ flags
4315
+ });
4316
+ return { graphQLSchema, tinaSchema };
4317
+ };
4318
+ var getASTSchema = async (database) => {
4308
4319
  const gqlAst = await database.getGraphQLSchemaFromBridge();
4309
- return (0, import_graphql5.buildASTSchema)(gqlAst);
4320
+ return (0, import_graphql6.buildASTSchema)(gqlAst);
4310
4321
  };
4311
4322
  // Annotate the CommonJS export names for ESM import in node:
4312
4323
  0 && (module.exports = {
@@ -4317,8 +4328,8 @@ var buildSchema = async (rootPath, database, flags, skipIndexing) => {
4317
4328
  assertShape,
4318
4329
  buildSchema,
4319
4330
  createDatabase,
4331
+ getASTSchema,
4320
4332
  handleFetchErrorError,
4321
- indexDB,
4322
4333
  parseFile,
4323
4334
  resolve,
4324
4335
  sequential,
package/dist/resolve.d.ts CHANGED
@@ -12,13 +12,14 @@ limitations under the License.
12
12
  */
13
13
  import type { Database } from './database';
14
14
  import type { GraphQLConfig } from './types';
15
- export declare const resolve: ({ config, query, variables, database, silenceErrors, verbose, }: {
15
+ export declare const resolve: ({ config, query, variables, database, silenceErrors, verbose, isAudit, }: {
16
16
  config?: GraphQLConfig;
17
17
  query: string;
18
18
  variables: object;
19
19
  database: Database;
20
20
  silenceErrors?: boolean;
21
21
  verbose?: boolean;
22
+ isAudit?: boolean;
22
23
  }) => Promise<import("graphql").ExecutionResult<{
23
24
  [key: string]: any;
24
25
  }, {
@@ -26,6 +26,7 @@ export declare class TinaGraphQLError extends Error implements GraphQLError {
26
26
  export declare type TypeFetchErrorArgs = {
27
27
  stack?: string;
28
28
  file?: string;
29
+ includeAuditMessage?: boolean;
29
30
  originalError: Error;
30
31
  collection?: string;
31
32
  };
@@ -17,6 +17,7 @@ interface ResolverConfig {
17
17
  config?: GraphQLConfig;
18
18
  database: Database;
19
19
  tinaSchema: TinaSchema;
20
+ isAudit: boolean;
20
21
  }
21
22
  export declare const createResolver: (args: ResolverConfig) => Resolver;
22
23
  /**
@@ -28,6 +29,7 @@ export declare class Resolver {
28
29
  config: GraphQLConfig;
29
30
  database: Database;
30
31
  tinaSchema: TinaSchema;
32
+ isAudit: boolean;
31
33
  constructor(init: ResolverConfig);
32
34
  resolveCollection: (args: any, collectionName: string, hasDocuments?: boolean) => Promise<{
33
35
  fields: TinaFieldInner<true>[];
@@ -38,6 +40,27 @@ export declare class Resolver {
38
40
  name: string;
39
41
  path: string;
40
42
  format?: "json" | "md" | "markdown" | "mdx";
43
+ ui?: {
44
+ global?: boolean | {
45
+ icon?: any;
46
+ layout: "fullscreen" | "popup";
47
+ };
48
+ router?: (args: {
49
+ document: {
50
+ _sys: {
51
+ title?: string;
52
+ template: string;
53
+ breadcrumbs: string[];
54
+ path: string;
55
+ basename: string;
56
+ relativePath: string;
57
+ filename: string;
58
+ extension: string;
59
+ };
60
+ };
61
+ collection: TinaCloudCollection<true>;
62
+ }) => string;
63
+ };
41
64
  match?: string;
42
65
  documents: {
43
66
  collection: TinaCloudCollection<true>;
@@ -64,6 +87,27 @@ export declare class Resolver {
64
87
  name: string;
65
88
  path: string;
66
89
  format?: "json" | "md" | "markdown" | "mdx";
90
+ ui?: {
91
+ global?: boolean | {
92
+ icon?: any;
93
+ layout: "fullscreen" | "popup";
94
+ };
95
+ router?: (args: {
96
+ document: {
97
+ _sys: {
98
+ title?: string;
99
+ template: string;
100
+ breadcrumbs: string[];
101
+ path: string;
102
+ basename: string;
103
+ relativePath: string;
104
+ filename: string;
105
+ extension: string;
106
+ };
107
+ };
108
+ collection: TinaCloudCollection<true>;
109
+ }) => string;
110
+ };
67
111
  match?: string;
68
112
  documents: {
69
113
  collection: TinaCloudCollection<true>;
@@ -52,7 +52,7 @@ export declare class TinaSchema {
52
52
  fields: import("../types").TinaFieldInner<true>[];
53
53
  namespace: string[];
54
54
  };
55
- getCollectionByFullPath: (filepath: string) => Promise<TinaCloudCollection<true>>;
55
+ getCollectionByFullPath: (filepath: string) => TinaCloudCollection<true>;
56
56
  getCollectionAndTemplateByFullPath: (filepath: string, templateName?: string) => {
57
57
  collection: TinaCloudCollection<true>;
58
58
  template: Templateable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.63.3",
3
+ "version": "0.63.6",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -19,9 +19,9 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
22
- "@tinacms/datalayer": "0.2.2",
23
- "@tinacms/schema-tools": "0.1.0",
24
- "@tinacms/mdx": "0.61.3",
22
+ "@tinacms/datalayer": "0.2.3",
23
+ "@tinacms/schema-tools": "0.1.1",
24
+ "@tinacms/mdx": "0.61.5",
25
25
  "body-parser": "^1.19.0",
26
26
  "cors": "^2.8.5",
27
27
  "dataloader": "^2.0.0",
@@ -71,8 +71,8 @@
71
71
  "directory": "packages/tina-graphql"
72
72
  },
73
73
  "devDependencies": {
74
- "@tinacms/datalayer": "0.2.2",
75
- "@tinacms/schema-tools": "0.1.0",
74
+ "@tinacms/datalayer": "0.2.3",
75
+ "@tinacms/schema-tools": "0.1.1",
76
76
  "@tinacms/scripts": "0.51.1",
77
77
  "@types/cors": "^2.8.7",
78
78
  "@types/estree": "^0.0.50",