@mo36924/babel-plugin-graphql-tagged-template 5.3.3 → 5.4.3

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ var node_path = require('node:path');
5
5
  var node_url = require('node:url');
6
6
  var core = require('@babel/core');
7
7
  var helperPluginUtils = require('@babel/helper-plugin-utils');
8
+ var utils = require('@graphql-tools/utils');
8
9
  var graphql = require('graphql');
9
10
  var packages_babelPluginGraphqlTaggedTemplate_dist_queries = require('./queries.cjs');
10
11
 
@@ -15,6 +16,11 @@ const queriesPaths = [
15
16
  "cjs",
16
17
  "ts"
17
18
  ].map((extname)=>node_path.join(queriesDir, `queries.${extname}`));
19
+ const schemaPaths = [
20
+ "js",
21
+ "cjs",
22
+ "ts"
23
+ ].map((extname)=>node_path.join(queriesDir, `schema.${extname}`));
18
24
  const hash = (data)=>node_crypto.createHash("sha256").update(data).digest("base64url");
19
25
  var index = helperPluginUtils.declare((_api, { schema, development, queries = packages_babelPluginGraphqlTaggedTemplate_dist_queries.queries })=>{
20
26
  return {
@@ -22,19 +28,28 @@ var index = helperPluginUtils.declare((_api, { schema, development, queries = pa
22
28
  visitor: {
23
29
  ...development ? {} : {
24
30
  VariableDeclarator (path, { filename = "" }) {
25
- if (!(queriesPaths.includes(filename) && path.get("id").isIdentifier({
31
+ if (queriesPaths.includes(filename) && path.get("id").isIdentifier({
26
32
  name: "queries"
27
- }))) {
28
- return;
33
+ })) {
34
+ path.get("init").replaceWith(core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")), [
35
+ core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("create")), [
36
+ core.types.nullLiteral()
37
+ ]),
38
+ core.types.objectExpression(Object.entries(queries).sort(([a], [b])=>a.localeCompare(b)).map(([key, documentNode])=>core.types.objectProperty(core.types.stringLiteral(key), core.types.callExpression(core.types.memberExpression(core.types.identifier("JSON"), core.types.identifier("parse")), [
39
+ core.types.stringLiteral(JSON.stringify(documentNode))
40
+ ]))))
41
+ ]));
42
+ } else if (schemaPaths.includes(filename) && path.get("id").isIdentifier({
43
+ name: "schema"
44
+ })) {
45
+ const source = utils.printSchemaWithDirectives(schema);
46
+ const documentNode = graphql.parse(source, {
47
+ noLocation: true
48
+ });
49
+ path.get("init").replaceWith(core.types.callExpression(core.types.memberExpression(core.types.identifier("JSON"), core.types.identifier("parse")), [
50
+ core.types.stringLiteral(JSON.stringify(documentNode))
51
+ ]));
29
52
  }
30
- path.get("init").replaceWith(core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")), [
31
- core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("create")), [
32
- core.types.nullLiteral()
33
- ]),
34
- core.types.objectExpression(Object.entries(queries).sort(([a], [b])=>a.localeCompare(b)).map(([key, documentNode])=>core.types.objectProperty(core.types.stringLiteral(key), core.types.callExpression(core.types.memberExpression(core.types.identifier("JSON"), core.types.identifier("parse")), [
35
- core.types.stringLiteral(JSON.stringify(documentNode))
36
- ]))))
37
- ]));
38
53
  }
39
54
  },
40
55
  TaggedTemplateExpression (path) {
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { dirname, join } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { types } from '@babel/core';
5
5
  import { declare } from '@babel/helper-plugin-utils';
6
+ import { printSchemaWithDirectives } from '@graphql-tools/utils';
6
7
  import { parse, TypeInfo, OperationTypeNode, visit, visitWithTypeInfo, validate, stripIgnoredCharacters } from 'graphql';
7
8
  import { queries } from './queries.js';
8
9
 
@@ -12,6 +13,11 @@ const queriesPaths = [
12
13
  "cjs",
13
14
  "ts"
14
15
  ].map((extname)=>join(queriesDir, `queries.${extname}`));
16
+ const schemaPaths = [
17
+ "js",
18
+ "cjs",
19
+ "ts"
20
+ ].map((extname)=>join(queriesDir, `schema.${extname}`));
15
21
  const hash = (data)=>createHash("sha256").update(data).digest("base64url");
16
22
  var index = declare((_api, { schema, development, queries: queries$1 = queries })=>{
17
23
  return {
@@ -19,19 +25,28 @@ var index = declare((_api, { schema, development, queries: queries$1 = queries }
19
25
  visitor: {
20
26
  ...development ? {} : {
21
27
  VariableDeclarator (path, { filename = "" }) {
22
- if (!(queriesPaths.includes(filename) && path.get("id").isIdentifier({
28
+ if (queriesPaths.includes(filename) && path.get("id").isIdentifier({
23
29
  name: "queries"
24
- }))) {
25
- return;
30
+ })) {
31
+ path.get("init").replaceWith(types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("assign")), [
32
+ types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("create")), [
33
+ types.nullLiteral()
34
+ ]),
35
+ types.objectExpression(Object.entries(queries$1).sort(([a], [b])=>a.localeCompare(b)).map(([key, documentNode])=>types.objectProperty(types.stringLiteral(key), types.callExpression(types.memberExpression(types.identifier("JSON"), types.identifier("parse")), [
36
+ types.stringLiteral(JSON.stringify(documentNode))
37
+ ]))))
38
+ ]));
39
+ } else if (schemaPaths.includes(filename) && path.get("id").isIdentifier({
40
+ name: "schema"
41
+ })) {
42
+ const source = printSchemaWithDirectives(schema);
43
+ const documentNode = parse(source, {
44
+ noLocation: true
45
+ });
46
+ path.get("init").replaceWith(types.callExpression(types.memberExpression(types.identifier("JSON"), types.identifier("parse")), [
47
+ types.stringLiteral(JSON.stringify(documentNode))
48
+ ]));
26
49
  }
27
- path.get("init").replaceWith(types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("assign")), [
28
- types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("create")), [
29
- types.nullLiteral()
30
- ]),
31
- types.objectExpression(Object.entries(queries$1).sort(([a], [b])=>a.localeCompare(b)).map(([key, documentNode])=>types.objectProperty(types.stringLiteral(key), types.callExpression(types.memberExpression(types.identifier("JSON"), types.identifier("parse")), [
32
- types.stringLiteral(JSON.stringify(documentNode))
33
- ]))))
34
- ]));
35
50
  }
36
51
  },
37
52
  TaggedTemplateExpression (path) {
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var config = require('@mo36924/graphql/config');
4
+
5
+ const schema = config.getSchema().schema;
6
+
7
+ exports.schema = schema;
@@ -0,0 +1,5 @@
1
+ import * as graphql from 'graphql';
2
+
3
+ declare const schema: graphql.GraphQLSchema | undefined;
4
+
5
+ export { schema };
package/dist/schema.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getSchema } from '@mo36924/graphql/config';
2
+
3
+ const schema = getSchema().schema;
4
+
5
+ export { schema };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mo36924/babel-plugin-graphql-tagged-template",
3
3
  "type": "module",
4
- "version": "5.3.3",
4
+ "version": "5.4.3",
5
5
  "description": "babel-plugin-graphql-tagged-template",
6
6
  "author": "mo36924",
7
7
  "license": "MIT",
@@ -27,6 +27,12 @@
27
27
  "import": "./dist/queries.js",
28
28
  "require": "./dist/queries.cjs",
29
29
  "default": "./dist/queries.js"
30
+ },
31
+ "./schema": {
32
+ "types": "./dist/schema.d.ts",
33
+ "import": "./dist/schema.js",
34
+ "require": "./dist/schema.cjs",
35
+ "default": "./dist/schema.js"
30
36
  }
31
37
  },
32
38
  "main": "./dist/index.js",
@@ -49,9 +55,11 @@
49
55
  "dependencies": {
50
56
  "@babel/core": "^7.26.0",
51
57
  "@babel/helper-plugin-utils": "^7.25.9",
58
+ "@graphql-tools/utils": "^10.5.6",
59
+ "@mo36924/graphql": "^5.4.2",
52
60
  "@types/babel__core": "^7.20.5",
53
61
  "@types/babel__helper-plugin-utils": "^7.10.3",
54
62
  "graphql": "^16.9.0"
55
63
  },
56
- "gitHead": "2398045d669322b77121c2ef7522538fe790979e"
64
+ "gitHead": "e313716c27a4a0550a2e2b06506fbef0558bd0af"
57
65
  }