@tinacms/graphql 0.63.4 → 0.63.7

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,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
- export { indexDB } from './build';
13
+ import { buildDotTinaFiles } from './build';
14
14
  export { resolve } from './resolve';
15
15
  export * from './resolver/error';
16
16
  export { createDatabase } from './database';
@@ -21,8 +21,14 @@ export type { Store } from '@tinacms/datalayer';
21
21
  export type { Bridge } from './database/bridge';
22
22
  export { sequential, assertShape } from './util';
23
23
  export { stringifyFile, parseFile } from './database/util';
24
+ export { createSchema } from './schema';
25
+ export { buildDotTinaFiles };
24
26
  export declare type DummyType = unknown;
25
- export declare const buildSchema: (rootPath: string, database: Database, flags?: string[], skipIndexing?: boolean) => Promise<import("graphql").GraphQLSchema>;
27
+ export declare const buildSchema: (rootPath: string, database: Database, flags?: string[]) => Promise<{
28
+ graphQLSchema: import("graphql").DocumentNode;
29
+ tinaSchema: import("./schema").TinaSchema;
30
+ }>;
31
+ export declare const getASTSchema: (database: Database) => Promise<import("graphql").GraphQLSchema>;
26
32
  import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from './types';
27
33
  export declare type TinaCloudSchema = TinaCloudSchemaBase<false>;
28
34
  export declare type TinaSchema = TinaCloudSchema;
package/dist/index.js CHANGED
@@ -58,10 +58,12 @@ __export(exports, {
58
58
  TinaParseDocumentError: () => TinaParseDocumentError,
59
59
  TinaQueryError: () => TinaQueryError,
60
60
  assertShape: () => assertShape,
61
+ buildDotTinaFiles: () => buildDotTinaFiles,
61
62
  buildSchema: () => buildSchema,
62
63
  createDatabase: () => createDatabase,
64
+ createSchema: () => createSchema,
65
+ getASTSchema: () => getASTSchema,
63
66
  handleFetchErrorError: () => handleFetchErrorError,
64
- indexDB: () => indexDB,
65
67
  parseFile: () => parseFile,
66
68
  resolve: () => resolve,
67
69
  sequential: () => sequential,
@@ -69,7 +71,7 @@ __export(exports, {
69
71
  });
70
72
  var import_fs_extra2 = __toModule(require("fs-extra"));
71
73
  var import_path4 = __toModule(require("path"));
72
- var import_graphql5 = __toModule(require("graphql"));
74
+ var import_graphql6 = __toModule(require("graphql"));
73
75
 
74
76
  // src/build.ts
75
77
  var import_lodash3 = __toModule(require("lodash"));
@@ -2437,7 +2439,7 @@ var validateField = async (field) => {
2437
2439
 
2438
2440
  // package.json
2439
2441
  var name = "@tinacms/graphql";
2440
- var version = "0.63.4";
2442
+ var version = "0.63.7";
2441
2443
  var main = "dist/index.js";
2442
2444
  var typings = "dist/index.d.ts";
2443
2445
  var files = [
@@ -2578,17 +2580,18 @@ var TinaFetchError = class extends Error {
2578
2580
  };
2579
2581
  var TinaQueryError = class extends TinaFetchError {
2580
2582
  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);
2583
+ super(`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2582
2584
  }
2583
2585
  };
2584
2586
  var TinaParseDocumentError = class extends TinaFetchError {
2585
2587
  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);
2588
+ super(`Error Parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2587
2589
  }
2588
2590
  toString() {
2589
2591
  return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
2590
2592
  }
2591
2593
  };
2594
+ var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
2592
2595
  var handleFetchErrorError = (e, verbose) => {
2593
2596
  if (e instanceof Error) {
2594
2597
  if (e instanceof TinaFetchError) {
@@ -2667,9 +2670,9 @@ var TinaSchema = class {
2667
2670
  }
2668
2671
  return globalTemplate;
2669
2672
  };
2670
- this.getCollectionByFullPath = async (filepath) => {
2673
+ this.getCollectionByFullPath = (filepath) => {
2671
2674
  const collection = this.getCollections().find((collection2) => {
2672
- return filepath.replace("\\", "/").startsWith(collection2.path);
2675
+ return filepath.replace("\\", "/").startsWith(collection2.path.replace(/\/?$/, "/"));
2673
2676
  });
2674
2677
  if (!collection) {
2675
2678
  throw new Error(`Unable to find collection for file at ${filepath}`);
@@ -2678,12 +2681,7 @@ var TinaSchema = class {
2678
2681
  };
2679
2682
  this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
2680
2683
  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
- }
2684
+ const collection = this.getCollectionByFullPath(filepath);
2687
2685
  const templates = this.getTemplatesForCollectable(collection);
2688
2686
  if (templates.type === "union") {
2689
2687
  if (templateName) {
@@ -2775,11 +2773,7 @@ var TinaSchema = class {
2775
2773
 
2776
2774
  // src/build.ts
2777
2775
  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 ({
2776
+ var buildDotTinaFiles = async ({
2783
2777
  database,
2784
2778
  config,
2785
2779
  flags = [],
@@ -2904,7 +2898,7 @@ var _buildSchema = async (builder, tinaSchema) => {
2904
2898
  };
2905
2899
 
2906
2900
  // src/resolve.ts
2907
- var import_graphql3 = __toModule(require("graphql"));
2901
+ var import_graphql4 = __toModule(require("graphql"));
2908
2902
 
2909
2903
  // src/resolver/index.ts
2910
2904
  var import_path2 = __toModule(require("path"));
@@ -3059,6 +3053,7 @@ var hasTinaMediaConfig = (schema) => {
3059
3053
  };
3060
3054
 
3061
3055
  // src/resolver/index.ts
3056
+ var import_graphql3 = __toModule(require("graphql"));
3062
3057
  var createResolver = (args) => {
3063
3058
  return new Resolver(args);
3064
3059
  };
@@ -3102,6 +3097,7 @@ var Resolver = class {
3102
3097
  throw new TinaParseDocumentError({
3103
3098
  originalError: e,
3104
3099
  collection: collection.name,
3100
+ includeAuditMessage: !this.isAudit,
3105
3101
  file: relativePath,
3106
3102
  stack: e.stack
3107
3103
  });
@@ -3435,6 +3431,7 @@ var Resolver = class {
3435
3431
  };
3436
3432
  this.resolveFieldData = async (_a, rawData, accumulator) => {
3437
3433
  var _b = _a, { namespace } = _b, field = __objRest(_b, ["namespace"]);
3434
+ var _a2;
3438
3435
  if (!rawData) {
3439
3436
  return void 0;
3440
3437
  }
@@ -3459,6 +3456,12 @@ var Resolver = class {
3459
3456
  break;
3460
3457
  case "rich-text":
3461
3458
  const tree = (0, import_mdx.parseMDX)(value, field, (value2) => resolveMediaRelativeToCloud(value2, this.config, this.tinaSchema.schema));
3459
+ if (((_a2 = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _a2.type) === "invalid_markdown") {
3460
+ if (this.isAudit) {
3461
+ const invalidNode = tree == null ? void 0 : tree.children[0];
3462
+ throw new import_graphql3.GraphQLError(`${invalidNode == null ? void 0 : invalidNode.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`);
3463
+ }
3464
+ }
3462
3465
  accumulator[field.name] = tree;
3463
3466
  break;
3464
3467
  case "object":
@@ -3525,6 +3528,7 @@ var Resolver = class {
3525
3528
  this.config = init.config;
3526
3529
  this.database = init.database;
3527
3530
  this.tinaSchema = init.tinaSchema;
3531
+ this.isAudit = init.isAudit;
3528
3532
  }
3529
3533
  async resolveFilterConditions(filter, fields, collectionName) {
3530
3534
  const conditions = [];
@@ -3564,20 +3568,26 @@ var resolve = async ({
3564
3568
  variables,
3565
3569
  database,
3566
3570
  silenceErrors,
3567
- verbose
3571
+ verbose,
3572
+ isAudit
3568
3573
  }) => {
3569
3574
  var _a;
3570
3575
  try {
3571
3576
  const verboseValue = verbose != null ? verbose : true;
3572
3577
  const graphQLSchemaAst = await database.getGraphQLSchema();
3573
- const graphQLSchema = (0, import_graphql3.buildASTSchema)(graphQLSchemaAst);
3578
+ const graphQLSchema = (0, import_graphql4.buildASTSchema)(graphQLSchemaAst);
3574
3579
  const tinaConfig = await database.getTinaSchema();
3575
3580
  const tinaSchema = await createSchema({
3576
3581
  schema: tinaConfig,
3577
3582
  flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
3578
3583
  });
3579
- const resolver = await createResolver({ config, database, tinaSchema });
3580
- const res = await (0, import_graphql3.graphql)({
3584
+ const resolver = await createResolver({
3585
+ config,
3586
+ database,
3587
+ tinaSchema,
3588
+ isAudit: isAudit || false
3589
+ });
3590
+ const res = await (0, import_graphql4.graphql)({
3581
3591
  schema: graphQLSchema,
3582
3592
  source: query,
3583
3593
  variableValues: variables,
@@ -3587,7 +3597,7 @@ var resolve = async ({
3587
3597
  typeResolver: async (source, _args, info) => {
3588
3598
  if (source.__typename)
3589
3599
  return source.__typename;
3590
- const namedType = (0, import_graphql3.getNamedType)(info.returnType).toString();
3600
+ const namedType = (0, import_graphql4.getNamedType)(info.returnType).toString();
3591
3601
  const lookup = await database.getLookup(namedType);
3592
3602
  if (lookup.resolveType === "unionData") {
3593
3603
  return lookup.typeMap[source._template];
@@ -3598,7 +3608,7 @@ var resolve = async ({
3598
3608
  fieldResolver: async (source = {}, _args = {}, _context, info) => {
3599
3609
  try {
3600
3610
  const args = JSON.parse(JSON.stringify(_args));
3601
- const returnType = (0, import_graphql3.getNamedType)(info.returnType).toString();
3611
+ const returnType = (0, import_graphql4.getNamedType)(info.returnType).toString();
3602
3612
  const lookup = await database.getLookup(returnType);
3603
3613
  const isMutation = info.parentType.toString() === "Mutation";
3604
3614
  const value = source[info.fieldName];
@@ -3625,12 +3635,12 @@ var resolve = async ({
3625
3635
  }
3626
3636
  if (info.fieldName === "getOptimizedQuery") {
3627
3637
  try {
3628
- const [optimizedQuery] = (0, import_relay_operation_optimizer.optimizeDocuments)(info.schema, [(0, import_graphql3.parse)(args.queryString)], {
3638
+ const [optimizedQuery] = (0, import_relay_operation_optimizer.optimizeDocuments)(info.schema, [(0, import_graphql4.parse)(args.queryString)], {
3629
3639
  assumeValid: true,
3630
3640
  includeFragments: false,
3631
3641
  noLocation: true
3632
3642
  });
3633
- return (0, import_graphql3.print)(optimizedQuery);
3643
+ return (0, import_graphql4.print)(optimizedQuery);
3634
3644
  } catch (e) {
3635
3645
  throw new Error(`Invalid query provided, Error message: ${e.message}`);
3636
3646
  }
@@ -3749,7 +3759,7 @@ var resolve = async ({
3749
3759
  if (!silenceErrors) {
3750
3760
  console.error(e);
3751
3761
  }
3752
- if (e instanceof import_graphql3.GraphQLError) {
3762
+ if (e instanceof import_graphql4.GraphQLError) {
3753
3763
  return {
3754
3764
  errors: [e]
3755
3765
  };
@@ -3761,7 +3771,7 @@ var resolve = async ({
3761
3771
 
3762
3772
  // src/database/index.ts
3763
3773
  var import_path3 = __toModule(require("path"));
3764
- var import_graphql4 = __toModule(require("graphql"));
3774
+ var import_graphql5 = __toModule(require("graphql"));
3765
3775
 
3766
3776
  // src/database/util.ts
3767
3777
  var import_gray_matter = __toModule(require("gray-matter"));
@@ -3836,7 +3846,7 @@ var Database = class {
3836
3846
  this.config = config;
3837
3847
  this.collectionForPath = async (filepath) => {
3838
3848
  const tinaSchema = await this.getSchema();
3839
- const collection = await tinaSchema.getCollectionByFullPath(filepath);
3849
+ const collection = tinaSchema.getCollectionByFullPath(filepath);
3840
3850
  return collection;
3841
3851
  };
3842
3852
  this.get = async (filepath) => {
@@ -3847,7 +3857,7 @@ var Database = class {
3847
3857
  const extension = import_path3.default.extname(filepath);
3848
3858
  const contentObject = await this.store.get(normalizePath(filepath));
3849
3859
  if (!contentObject) {
3850
- throw new import_graphql4.GraphQLError(`Unable to find record ${filepath}`);
3860
+ throw new import_graphql5.GraphQLError(`Unable to find record ${filepath}`);
3851
3861
  }
3852
3862
  const templateName = hasOwnProperty(contentObject, "_template") && typeof contentObject._template === "string" ? contentObject._template : void 0;
3853
3863
  const { collection, template } = tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
@@ -3928,7 +3938,7 @@ var Database = class {
3928
3938
  throw new Error(`Unexpected put for config file ${filepath}`);
3929
3939
  } else {
3930
3940
  const tinaSchema = await this.getSchema();
3931
- const collection = await tinaSchema.getCollectionByFullPath(filepath);
3941
+ const collection = tinaSchema.getCollectionByFullPath(filepath);
3932
3942
  const templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
3933
3943
  let template;
3934
3944
  if (templateInfo.type === "object") {
@@ -4296,17 +4306,20 @@ var _deleteIndexContent = async (database, documentPaths, collection) => {
4296
4306
  };
4297
4307
 
4298
4308
  // src/index.ts
4299
- var buildSchema = async (rootPath, database, flags, skipIndexing) => {
4309
+ var buildSchema = async (rootPath, database, flags) => {
4300
4310
  const tempConfig = import_path4.default.join(rootPath, ".tina", "__generated__", "config");
4301
4311
  const config = await import_fs_extra2.default.readFileSync(import_path4.default.join(tempConfig, "schema.json")).toString();
4302
4312
  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
- }
4313
+ const { graphQLSchema, tinaSchema } = await buildDotTinaFiles({
4314
+ database,
4315
+ config: JSON.parse(config),
4316
+ flags
4317
+ });
4318
+ return { graphQLSchema, tinaSchema };
4319
+ };
4320
+ var getASTSchema = async (database) => {
4308
4321
  const gqlAst = await database.getGraphQLSchemaFromBridge();
4309
- return (0, import_graphql5.buildASTSchema)(gqlAst);
4322
+ return (0, import_graphql6.buildASTSchema)(gqlAst);
4310
4323
  };
4311
4324
  // Annotate the CommonJS export names for ESM import in node:
4312
4325
  0 && (module.exports = {
@@ -4315,10 +4328,12 @@ var buildSchema = async (rootPath, database, flags, skipIndexing) => {
4315
4328
  TinaParseDocumentError,
4316
4329
  TinaQueryError,
4317
4330
  assertShape,
4331
+ buildDotTinaFiles,
4318
4332
  buildSchema,
4319
4333
  createDatabase,
4334
+ createSchema,
4335
+ getASTSchema,
4320
4336
  handleFetchErrorError,
4321
- indexDB,
4322
4337
  parseFile,
4323
4338
  resolve,
4324
4339
  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.4",
3
+ "version": "0.63.7",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -20,8 +20,8 @@
20
20
  "dependencies": {
21
21
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
22
22
  "@tinacms/datalayer": "0.2.3",
23
- "@tinacms/schema-tools": "0.1.0",
24
- "@tinacms/mdx": "0.61.3",
23
+ "@tinacms/schema-tools": "0.1.2",
24
+ "@tinacms/mdx": "0.61.6",
25
25
  "body-parser": "^1.19.0",
26
26
  "cors": "^2.8.5",
27
27
  "dataloader": "^2.0.0",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "devDependencies": {
74
74
  "@tinacms/datalayer": "0.2.3",
75
- "@tinacms/schema-tools": "0.1.0",
75
+ "@tinacms/schema-tools": "0.1.2",
76
76
  "@tinacms/scripts": "0.51.1",
77
77
  "@types/cors": "^2.8.7",
78
78
  "@types/estree": "^0.0.50",