@mo36924/babel-plugin-graphql-tagged-template 5.4.3 → 5.4.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +8 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -8
- package/dist/schema.cjs +2 -2
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
@@ -2,12 +2,15 @@
|
|
2
2
|
|
3
3
|
var node_crypto = require('node:crypto');
|
4
4
|
var node_path = require('node:path');
|
5
|
+
var node_process = require('node:process');
|
5
6
|
var node_url = require('node:url');
|
6
7
|
var core = require('@babel/core');
|
7
8
|
var helperPluginUtils = require('@babel/helper-plugin-utils');
|
8
9
|
var utils = require('@graphql-tools/utils');
|
9
10
|
var graphql = require('graphql');
|
10
11
|
var packages_babelPluginGraphqlTaggedTemplate_dist_queries = require('./queries.cjs');
|
12
|
+
var packages_babelPluginGraphqlTaggedTemplate_dist_schema = require('./schema.cjs');
|
13
|
+
require('@mo36924/graphql');
|
11
14
|
|
12
15
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
13
16
|
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))));
|
@@ -22,7 +25,7 @@ const schemaPaths = [
|
|
22
25
|
"ts"
|
23
26
|
].map((extname)=>node_path.join(queriesDir, `schema.${extname}`));
|
24
27
|
const hash = (data)=>node_crypto.createHash("sha256").update(data).digest("base64url");
|
25
|
-
var index = helperPluginUtils.declare((_api, {
|
28
|
+
var index = helperPluginUtils.declare((_api, { development = node_process.env.NODE_ENV === "development", schema = packages_babelPluginGraphqlTaggedTemplate_dist_schema.schema, queries = packages_babelPluginGraphqlTaggedTemplate_dist_queries.queries })=>{
|
26
29
|
return {
|
27
30
|
name: "babel-plugin-graphql-tagged-template",
|
28
31
|
visitor: {
|
@@ -31,13 +34,14 @@ var index = helperPluginUtils.declare((_api, { schema, development, queries = pa
|
|
31
34
|
if (queriesPaths.includes(filename) && path.get("id").isIdentifier({
|
32
35
|
name: "queries"
|
33
36
|
})) {
|
37
|
+
const sortedQueries = Object.fromEntries(Object.entries(queries).sort(([a], [b])=>a.localeCompare(b)));
|
34
38
|
path.get("init").replaceWith(core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")), [
|
35
39
|
core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("create")), [
|
36
40
|
core.types.nullLiteral()
|
37
41
|
]),
|
38
|
-
core.types.
|
39
|
-
|
40
|
-
|
42
|
+
core.types.callExpression(core.types.memberExpression(core.types.identifier("JSON"), core.types.identifier("parse")), [
|
43
|
+
core.types.stringLiteral(JSON.stringify(sortedQueries))
|
44
|
+
])
|
41
45
|
]));
|
42
46
|
} else if (schemaPaths.includes(filename) && path.get("id").isIdentifier({
|
43
47
|
name: "schema"
|
package/dist/index.d.ts
CHANGED
@@ -4,8 +4,8 @@ import { GraphQLSchema } from 'graphql';
|
|
4
4
|
import { Queries } from './queries.js';
|
5
5
|
|
6
6
|
type Options = {
|
7
|
-
schema: GraphQLSchema;
|
8
7
|
development?: boolean;
|
8
|
+
schema?: GraphQLSchema;
|
9
9
|
queries?: Queries;
|
10
10
|
};
|
11
11
|
declare const _default: (api: object, options: Options | null | undefined, dirname: string) => PluginObj<_babel_core.PluginPass>;
|
package/dist/index.js
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
import { createHash } from 'node:crypto';
|
2
2
|
import { dirname, join } from 'node:path';
|
3
|
+
import { env } from 'node:process';
|
3
4
|
import { fileURLToPath } from 'node:url';
|
4
5
|
import { types } from '@babel/core';
|
5
6
|
import { declare } from '@babel/helper-plugin-utils';
|
6
7
|
import { printSchemaWithDirectives } from '@graphql-tools/utils';
|
7
8
|
import { parse, TypeInfo, OperationTypeNode, visit, visitWithTypeInfo, validate, stripIgnoredCharacters } from 'graphql';
|
8
9
|
import { queries } from './queries.js';
|
10
|
+
import { schema } from './schema.js';
|
11
|
+
import '@mo36924/graphql';
|
9
12
|
|
10
13
|
const queriesDir = dirname(fileURLToPath(import.meta.url));
|
11
14
|
const queriesPaths = [
|
@@ -19,7 +22,7 @@ const schemaPaths = [
|
|
19
22
|
"ts"
|
20
23
|
].map((extname)=>join(queriesDir, `schema.${extname}`));
|
21
24
|
const hash = (data)=>createHash("sha256").update(data).digest("base64url");
|
22
|
-
var index = declare((_api, {
|
25
|
+
var index = declare((_api, { development = env.NODE_ENV === "development", schema: schema$1 = schema, queries: queries$1 = queries })=>{
|
23
26
|
return {
|
24
27
|
name: "babel-plugin-graphql-tagged-template",
|
25
28
|
visitor: {
|
@@ -28,18 +31,19 @@ var index = declare((_api, { schema, development, queries: queries$1 = queries }
|
|
28
31
|
if (queriesPaths.includes(filename) && path.get("id").isIdentifier({
|
29
32
|
name: "queries"
|
30
33
|
})) {
|
34
|
+
const sortedQueries = Object.fromEntries(Object.entries(queries$1).sort(([a], [b])=>a.localeCompare(b)));
|
31
35
|
path.get("init").replaceWith(types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("assign")), [
|
32
36
|
types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("create")), [
|
33
37
|
types.nullLiteral()
|
34
38
|
]),
|
35
|
-
types.
|
36
|
-
|
37
|
-
|
39
|
+
types.callExpression(types.memberExpression(types.identifier("JSON"), types.identifier("parse")), [
|
40
|
+
types.stringLiteral(JSON.stringify(sortedQueries))
|
41
|
+
])
|
38
42
|
]));
|
39
43
|
} else if (schemaPaths.includes(filename) && path.get("id").isIdentifier({
|
40
44
|
name: "schema"
|
41
45
|
})) {
|
42
|
-
const source = printSchemaWithDirectives(schema);
|
46
|
+
const source = printSchemaWithDirectives(schema$1);
|
43
47
|
const documentNode = parse(source, {
|
44
48
|
noLocation: true
|
45
49
|
});
|
@@ -84,8 +88,8 @@ var index = declare((_api, { schema, development, queries: queries$1 = queries }
|
|
84
88
|
throw path.buildCodeFrameError("Only a field is allowed");
|
85
89
|
}
|
86
90
|
const values = [];
|
87
|
-
const typeInfo = new TypeInfo(schema);
|
88
|
-
const isMutation = !!schema.getMutationType()?.getFields()[field.name.value];
|
91
|
+
const typeInfo = new TypeInfo(schema$1);
|
92
|
+
const isMutation = !!schema$1.getMutationType()?.getFields()[field.name.value];
|
89
93
|
const operation = isMutation ? OperationTypeNode.MUTATION : OperationTypeNode.QUERY;
|
90
94
|
visit({
|
91
95
|
...definition,
|
@@ -108,7 +112,7 @@ var index = declare((_api, { schema, development, queries: queries$1 = queries }
|
|
108
112
|
} catch (err) {
|
109
113
|
throw path.buildCodeFrameError(String(err));
|
110
114
|
}
|
111
|
-
const errors = validate(schema, documentNode);
|
115
|
+
const errors = validate(schema$1, documentNode);
|
112
116
|
if (errors.length) {
|
113
117
|
throw path.buildCodeFrameError(errors[0].message);
|
114
118
|
}
|
package/dist/schema.cjs
CHANGED
package/dist/schema.d.ts
CHANGED
package/dist/schema.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.
|
4
|
+
"version": "5.4.6",
|
5
5
|
"description": "babel-plugin-graphql-tagged-template",
|
6
6
|
"author": "mo36924",
|
7
7
|
"license": "MIT",
|
@@ -56,10 +56,10 @@
|
|
56
56
|
"@babel/core": "^7.26.0",
|
57
57
|
"@babel/helper-plugin-utils": "^7.25.9",
|
58
58
|
"@graphql-tools/utils": "^10.5.6",
|
59
|
-
"@mo36924/graphql": "^5.4.
|
59
|
+
"@mo36924/graphql": "^5.4.4",
|
60
60
|
"@types/babel__core": "^7.20.5",
|
61
61
|
"@types/babel__helper-plugin-utils": "^7.10.3",
|
62
62
|
"graphql": "^16.9.0"
|
63
63
|
},
|
64
|
-
"gitHead": "
|
64
|
+
"gitHead": "0fc11c9a45c9304be259b12af873958cbf13bb9d"
|
65
65
|
}
|