@mo36924/babel-plugin-graphql-tagged-template 5.1.14 → 5.3.3
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/index.cjs +21 -21
- package/dist/index.d.ts +2 -1
- package/dist/index.js +22 -22
- package/dist/queries.cjs +3 -1
- package/dist/queries.d.ts +3 -2
- package/dist/queries.js +3 -1
- package/package.json +2 -3
package/dist/index.cjs
CHANGED
@@ -5,20 +5,18 @@ 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 basex = require('base-x');
|
9
8
|
var graphql = require('graphql');
|
9
|
+
var packages_babelPluginGraphqlTaggedTemplate_dist_queries = require('./queries.cjs');
|
10
10
|
|
11
11
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
12
|
-
const queriesCache = [];
|
13
12
|
const queriesDir = node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('packages/babel-plugin-graphql-tagged-template/dist/index.cjs', document.baseURI).href))));
|
14
13
|
const queriesPaths = [
|
15
14
|
"js",
|
16
15
|
"cjs",
|
17
16
|
"ts"
|
18
17
|
].map((extname)=>node_path.join(queriesDir, `queries.${extname}`));
|
19
|
-
const
|
20
|
-
|
21
|
-
var index = helperPluginUtils.declare((_, { schema, development, queries = queriesCache })=>{
|
18
|
+
const hash = (data)=>node_crypto.createHash("sha256").update(data).digest("base64url");
|
19
|
+
var index = helperPluginUtils.declare((_api, { schema, development, queries = packages_babelPluginGraphqlTaggedTemplate_dist_queries.queries })=>{
|
22
20
|
return {
|
23
21
|
name: "babel-plugin-graphql-tagged-template",
|
24
22
|
visitor: {
|
@@ -26,14 +24,17 @@ var index = helperPluginUtils.declare((_, { schema, development, queries = queri
|
|
26
24
|
VariableDeclarator (path, { filename = "" }) {
|
27
25
|
if (!(queriesPaths.includes(filename) && path.get("id").isIdentifier({
|
28
26
|
name: "queries"
|
29
|
-
})
|
27
|
+
}))) {
|
30
28
|
return;
|
31
29
|
}
|
32
|
-
path.get("init").replaceWith(core.types.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
])))))
|
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
|
+
]));
|
37
38
|
}
|
38
39
|
},
|
39
40
|
TaggedTemplateExpression (path) {
|
@@ -70,13 +71,14 @@ var index = helperPluginUtils.declare((_, { schema, development, queries = queri
|
|
70
71
|
if (field.kind !== "Field") {
|
71
72
|
throw path.buildCodeFrameError("Only a field is allowed");
|
72
73
|
}
|
73
|
-
const isMutation = !!schema.getMutationType()?.getFields()[field.name.value];
|
74
|
-
const operation = isMutation ? "mutation" : "query";
|
75
|
-
// @ts-expect-error ignore readonly
|
76
|
-
definition.operation = operation;
|
77
74
|
const values = [];
|
78
75
|
const typeInfo = new graphql.TypeInfo(schema);
|
79
|
-
|
76
|
+
const isMutation = !!schema.getMutationType()?.getFields()[field.name.value];
|
77
|
+
const operation = isMutation ? graphql.OperationTypeNode.MUTATION : graphql.OperationTypeNode.QUERY;
|
78
|
+
graphql.visit({
|
79
|
+
...definition,
|
80
|
+
operation
|
81
|
+
}, graphql.visitWithTypeInfo(typeInfo, {
|
80
82
|
Variable () {
|
81
83
|
values.push(typeInfo.getInputType());
|
82
84
|
}
|
@@ -99,12 +101,10 @@ var index = helperPluginUtils.declare((_, { schema, development, queries = queri
|
|
99
101
|
throw path.buildCodeFrameError(errors[0].message);
|
100
102
|
}
|
101
103
|
query = graphql.stripIgnoredCharacters(query);
|
102
|
-
|
103
|
-
|
104
|
-
}
|
105
|
-
const id = development ? query : hash(query);
|
104
|
+
const key = hash(query);
|
105
|
+
queries[key] = documentNode;
|
106
106
|
const properties = [
|
107
|
-
core.types.objectProperty(core.types.identifier("query"), core.types.stringLiteral(
|
107
|
+
core.types.objectProperty(core.types.identifier("query"), core.types.stringLiteral(key))
|
108
108
|
];
|
109
109
|
if (expressions.length) {
|
110
110
|
properties.push(core.types.objectProperty(core.types.identifier("variables"), core.types.objectExpression(expressions.map((expression, i)=>core.types.objectProperty(core.types.identifier(`_${i}`), expression)))));
|
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import * as _babel_core from '@babel/core';
|
2
2
|
import { PluginObj } from '@babel/core';
|
3
3
|
import { GraphQLSchema } from 'graphql';
|
4
|
+
import { Queries } from './queries.js';
|
4
5
|
|
5
6
|
type Options = {
|
6
7
|
schema: GraphQLSchema;
|
7
8
|
development?: boolean;
|
8
|
-
queries?:
|
9
|
+
queries?: Queries;
|
9
10
|
};
|
10
11
|
declare const _default: (api: object, options: Options | null | undefined, dirname: string) => PluginObj<_babel_core.PluginPass>;
|
11
12
|
|
package/dist/index.js
CHANGED
@@ -3,19 +3,17 @@ 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
|
7
|
-
import {
|
6
|
+
import { parse, TypeInfo, OperationTypeNode, visit, visitWithTypeInfo, validate, stripIgnoredCharacters } from 'graphql';
|
7
|
+
import { queries } from './queries.js';
|
8
8
|
|
9
|
-
const queriesCache = [];
|
10
9
|
const queriesDir = dirname(fileURLToPath(import.meta.url));
|
11
10
|
const queriesPaths = [
|
12
11
|
"js",
|
13
12
|
"cjs",
|
14
13
|
"ts"
|
15
14
|
].map((extname)=>join(queriesDir, `queries.${extname}`));
|
16
|
-
const
|
17
|
-
|
18
|
-
var index = declare((_, { schema, development, queries = queriesCache })=>{
|
15
|
+
const hash = (data)=>createHash("sha256").update(data).digest("base64url");
|
16
|
+
var index = declare((_api, { schema, development, queries: queries$1 = queries })=>{
|
19
17
|
return {
|
20
18
|
name: "babel-plugin-graphql-tagged-template",
|
21
19
|
visitor: {
|
@@ -23,14 +21,17 @@ var index = declare((_, { schema, development, queries = queriesCache })=>{
|
|
23
21
|
VariableDeclarator (path, { filename = "" }) {
|
24
22
|
if (!(queriesPaths.includes(filename) && path.get("id").isIdentifier({
|
25
23
|
name: "queries"
|
26
|
-
})
|
24
|
+
}))) {
|
27
25
|
return;
|
28
26
|
}
|
29
|
-
path.get("init").replaceWith(types.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
])))))
|
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
|
+
]));
|
34
35
|
}
|
35
36
|
},
|
36
37
|
TaggedTemplateExpression (path) {
|
@@ -67,13 +68,14 @@ var index = declare((_, { schema, development, queries = queriesCache })=>{
|
|
67
68
|
if (field.kind !== "Field") {
|
68
69
|
throw path.buildCodeFrameError("Only a field is allowed");
|
69
70
|
}
|
70
|
-
const isMutation = !!schema.getMutationType()?.getFields()[field.name.value];
|
71
|
-
const operation = isMutation ? "mutation" : "query";
|
72
|
-
// @ts-expect-error ignore readonly
|
73
|
-
definition.operation = operation;
|
74
71
|
const values = [];
|
75
72
|
const typeInfo = new TypeInfo(schema);
|
76
|
-
|
73
|
+
const isMutation = !!schema.getMutationType()?.getFields()[field.name.value];
|
74
|
+
const operation = isMutation ? OperationTypeNode.MUTATION : OperationTypeNode.QUERY;
|
75
|
+
visit({
|
76
|
+
...definition,
|
77
|
+
operation
|
78
|
+
}, visitWithTypeInfo(typeInfo, {
|
77
79
|
Variable () {
|
78
80
|
values.push(typeInfo.getInputType());
|
79
81
|
}
|
@@ -96,12 +98,10 @@ var index = declare((_, { schema, development, queries = queriesCache })=>{
|
|
96
98
|
throw path.buildCodeFrameError(errors[0].message);
|
97
99
|
}
|
98
100
|
query = stripIgnoredCharacters(query);
|
99
|
-
|
100
|
-
|
101
|
-
}
|
102
|
-
const id = development ? query : hash(query);
|
101
|
+
const key = hash(query);
|
102
|
+
queries$1[key] = documentNode;
|
103
103
|
const properties = [
|
104
|
-
types.objectProperty(types.identifier("query"), types.stringLiteral(
|
104
|
+
types.objectProperty(types.identifier("query"), types.stringLiteral(key))
|
105
105
|
];
|
106
106
|
if (expressions.length) {
|
107
107
|
properties.push(types.objectProperty(types.identifier("variables"), types.objectExpression(expressions.map((expression, i)=>types.objectProperty(types.identifier(`_${i}`), expression)))));
|
package/dist/queries.cjs
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
var _globalThis;
|
4
|
+
// @ts-expect-error queries is set to a value by Babel
|
5
|
+
const queries = (_globalThis = globalThis).__GRAPHQL_QUERIES__ ?? (_globalThis.__GRAPHQL_QUERIES__ = Object.create(null));
|
4
6
|
|
5
7
|
exports.queries = queries;
|
package/dist/queries.d.ts
CHANGED
package/dist/queries.js
CHANGED
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.
|
4
|
+
"version": "5.3.3",
|
5
5
|
"description": "babel-plugin-graphql-tagged-template",
|
6
6
|
"author": "mo36924",
|
7
7
|
"license": "MIT",
|
@@ -51,8 +51,7 @@
|
|
51
51
|
"@babel/helper-plugin-utils": "^7.25.9",
|
52
52
|
"@types/babel__core": "^7.20.5",
|
53
53
|
"@types/babel__helper-plugin-utils": "^7.10.3",
|
54
|
-
"base-x": "^5.0.0",
|
55
54
|
"graphql": "^16.9.0"
|
56
55
|
},
|
57
|
-
"gitHead": "
|
56
|
+
"gitHead": "2398045d669322b77121c2ef7522538fe790979e"
|
58
57
|
}
|