@tinacms/cli 1.2.0 → 1.2.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.
@@ -1,6 +1,3 @@
1
- /**
2
-
3
- */
4
1
  import type { Bridge } from '@tinacms/datalayer';
5
2
  import type { Database } from '@tinacms/graphql';
6
3
  import type { TinaCloudSchema } from '@tinacms/schema-tools';
@@ -17,3 +14,19 @@ export declare const checkClientInfo: (ctx: {
17
14
  }, next: any, _options: {
18
15
  verbose?: boolean;
19
16
  }) => Promise<any>;
17
+ export declare const fetchRemoteGraphqlSchema: ({ url, token, }: {
18
+ url: string;
19
+ token?: string;
20
+ }) => Promise<any>;
21
+ export declare const checkGraphqlSchema: (ctx: {
22
+ builder: ConfigBuilder;
23
+ rootPath: string;
24
+ database: Database;
25
+ bridge: Bridge;
26
+ usingTs: boolean;
27
+ schema?: TinaCloudSchema<false>;
28
+ apiUrl: string;
29
+ isSelfHostedDatabase: boolean;
30
+ }, next: any, _options: {
31
+ verbose?: boolean;
32
+ }) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- /**
2
-
3
- */
4
1
  export { defineSchema } from './cmds/compile';
5
2
  export type { TinaCloudSchema, TinaSchema, TinaCloudCollection, TinaCollection, TinaField, TinaTemplate, } from '@tinacms/graphql';
6
3
  export declare function init(args: any): Promise<void>;
package/dist/index.js CHANGED
@@ -304,7 +304,7 @@ var commander = __toModule(require("commander"));
304
304
 
305
305
  // package.json
306
306
  var name = "@tinacms/cli";
307
- var version = "1.2.0";
307
+ var version = "1.2.2";
308
308
 
309
309
  // src/cmds/audit/audit.ts
310
310
  var import_graphql = __toModule(require("@tinacms/graphql"));
@@ -2992,6 +2992,8 @@ var attachDatabase = async (ctx, next, _options) => {
2992
2992
 
2993
2993
  // src/cmds/statusChecks/checkClientInformation.ts
2994
2994
  var import_progress2 = __toModule(require("progress"));
2995
+ var import_graphql12 = __toModule(require("graphql"));
2996
+ var import_core2 = __toModule(require("@graphql-inspector/core"));
2995
2997
  var import_schema_tools2 = __toModule(require("@tinacms/schema-tools"));
2996
2998
  async function request(args) {
2997
2999
  const headers = new Headers();
@@ -3064,6 +3066,56 @@ var checkClientInfo = async (ctx, next, _options) => {
3064
3066
  }
3065
3067
  next();
3066
3068
  };
3069
+ var fetchRemoteGraphqlSchema = async ({
3070
+ url,
3071
+ token
3072
+ }) => {
3073
+ const headers = new Headers();
3074
+ if (token) {
3075
+ headers.append("X-API-KEY", token);
3076
+ }
3077
+ const body = JSON.stringify({ query: (0, import_graphql12.getIntrospectionQuery)(), variables: {} });
3078
+ headers.append("Content-Type", "application/json");
3079
+ const res = await fetch(url, {
3080
+ method: "POST",
3081
+ headers,
3082
+ body
3083
+ });
3084
+ const data = await res.json();
3085
+ return data == null ? void 0 : data.data;
3086
+ };
3087
+ var checkGraphqlSchema = async (ctx, next, _options) => {
3088
+ var _a;
3089
+ const bar = new import_progress2.default("Checking local GraphQL Schema matches server. :prog", 1);
3090
+ const config2 = (_a = ctx.schema) == null ? void 0 : _a.config;
3091
+ const token = config2.token;
3092
+ const url = ctx.apiUrl;
3093
+ const remoteSchema = await fetchRemoteGraphqlSchema({
3094
+ url,
3095
+ token
3096
+ });
3097
+ const remoteGqlSchema = (0, import_graphql12.buildClientSchema)(remoteSchema);
3098
+ const localSchemaDocument = await ctx.database.getGraphQLSchemaFromBridge();
3099
+ const localGraphqlSchema = (0, import_graphql12.buildSchema)((0, import_graphql12.print)(localSchemaDocument));
3100
+ const diffResult = await (0, import_core2.diff)(localGraphqlSchema, remoteGqlSchema);
3101
+ if (diffResult.length === 0) {
3102
+ bar.tick({
3103
+ prog: "\u2705"
3104
+ });
3105
+ } else {
3106
+ bar.tick({
3107
+ prog: "\u274C"
3108
+ });
3109
+ let errorMessage = `The local GraphQL schema doesn't match the remote GraphQL schema. Please push up your changes to Github to update your remote GraphQL schema.`;
3110
+ if (config2 == null ? void 0 : config2.branch) {
3111
+ errorMessage += `
3112
+
3113
+ Addition info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
3114
+ }
3115
+ throw new Error(errorMessage);
3116
+ }
3117
+ next();
3118
+ };
3067
3119
 
3068
3120
  // src/cmds/baseCmds.ts
3069
3121
  var CMD_START_SERVER = "server:start";
@@ -3212,6 +3264,7 @@ var baseCmds = [
3212
3264
  buildSetupCmdBuild,
3213
3265
  buildCmdBuild,
3214
3266
  checkClientInfo,
3267
+ checkGraphqlSchema,
3215
3268
  waitForDB,
3216
3269
  indexIntoSelfHostedDatabase
3217
3270
  ], options)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -50,13 +50,14 @@
50
50
  "@graphql-codegen/typescript-generic-sdk": "^2.1.4",
51
51
  "@graphql-codegen/typescript-operations": "^2.1.4",
52
52
  "@graphql-codegen/visitor-plugin-common": "^2.4.0",
53
+ "@graphql-inspector/core": "^4.0.0",
53
54
  "@graphql-tools/graphql-file-loader": "^7.2.0",
54
55
  "@graphql-tools/load": "^7.3.2",
55
- "@tinacms/app": "1.1.0",
56
- "@tinacms/datalayer": "1.1.1",
57
- "@tinacms/graphql": "1.3.0",
56
+ "@tinacms/app": "1.1.1",
57
+ "@tinacms/datalayer": "1.1.3",
58
+ "@tinacms/graphql": "1.3.2",
58
59
  "@tinacms/metrics": "1.0.2",
59
- "@tinacms/schema-tools": "1.3.1",
60
+ "@tinacms/schema-tools": "1.3.2",
60
61
  "ajv": "^6.12.3",
61
62
  "altair-express-middleware": "4.0.6",
62
63
  "auto-bind": "^4.0.0",
@@ -78,8 +79,8 @@
78
79
  "lodash": "^4.17.19",
79
80
  "lodash.get": "^4.4.2",
80
81
  "log4js": "^6.4.0",
81
- "memory-level": "^1.0.0",
82
82
  "many-level": "^2.0.0",
83
+ "memory-level": "^1.0.0",
83
84
  "minimatch": "^5.1.2",
84
85
  "multer": "1.4.5-lts.1",
85
86
  "normalize-path": "^3.0.0",