@mo36924/babel-plugin-graphql-tagged-template 5.3.3 → 5.4.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +30 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -12
- package/dist/schema.cjs +7 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.js +5 -0
- package/package.json +10 -2
package/dist/index.cjs
CHANGED
@@ -2,9 +2,12 @@
|
|
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');
|
9
|
+
var utils = require('@graphql-tools/utils');
|
10
|
+
var graphql$1 = require('@mo36924/graphql');
|
8
11
|
var graphql = require('graphql');
|
9
12
|
var packages_babelPluginGraphqlTaggedTemplate_dist_queries = require('./queries.cjs');
|
10
13
|
|
@@ -15,26 +18,41 @@ const queriesPaths = [
|
|
15
18
|
"cjs",
|
16
19
|
"ts"
|
17
20
|
].map((extname)=>node_path.join(queriesDir, `queries.${extname}`));
|
21
|
+
const schemaPaths = [
|
22
|
+
"js",
|
23
|
+
"cjs",
|
24
|
+
"ts"
|
25
|
+
].map((extname)=>node_path.join(queriesDir, `schema.${extname}`));
|
18
26
|
const hash = (data)=>node_crypto.createHash("sha256").update(data).digest("base64url");
|
19
|
-
var index = helperPluginUtils.declare((_api, {
|
27
|
+
var index = helperPluginUtils.declare((_api, { development = node_process.env.NODE_ENV === "development", schema = graphql$1.getSchema().schema, queries = packages_babelPluginGraphqlTaggedTemplate_dist_queries.queries })=>{
|
20
28
|
return {
|
21
29
|
name: "babel-plugin-graphql-tagged-template",
|
22
30
|
visitor: {
|
23
31
|
...development ? {} : {
|
24
32
|
VariableDeclarator (path, { filename = "" }) {
|
25
|
-
if (
|
33
|
+
if (queriesPaths.includes(filename) && path.get("id").isIdentifier({
|
26
34
|
name: "queries"
|
27
|
-
}))
|
28
|
-
|
35
|
+
})) {
|
36
|
+
const sortedQueries = Object.fromEntries(Object.entries(queries).sort(([a], [b])=>a.localeCompare(b)));
|
37
|
+
path.get("init").replaceWith(core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")), [
|
38
|
+
core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("create")), [
|
39
|
+
core.types.nullLiteral()
|
40
|
+
]),
|
41
|
+
core.types.callExpression(core.types.memberExpression(core.types.identifier("JSON"), core.types.identifier("parse")), [
|
42
|
+
core.types.stringLiteral(JSON.stringify(sortedQueries))
|
43
|
+
])
|
44
|
+
]));
|
45
|
+
} else if (schemaPaths.includes(filename) && path.get("id").isIdentifier({
|
46
|
+
name: "schema"
|
47
|
+
})) {
|
48
|
+
const source = utils.printSchemaWithDirectives(schema);
|
49
|
+
const documentNode = graphql.parse(source, {
|
50
|
+
noLocation: true
|
51
|
+
});
|
52
|
+
path.get("init").replaceWith(core.types.callExpression(core.types.memberExpression(core.types.identifier("JSON"), core.types.identifier("parse")), [
|
53
|
+
core.types.stringLiteral(JSON.stringify(documentNode))
|
54
|
+
]));
|
29
55
|
}
|
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
56
|
}
|
39
57
|
},
|
40
58
|
TaggedTemplateExpression (path) {
|
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,8 +1,11 @@
|
|
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';
|
7
|
+
import { printSchemaWithDirectives } from '@graphql-tools/utils';
|
8
|
+
import { getSchema } from '@mo36924/graphql';
|
6
9
|
import { parse, TypeInfo, OperationTypeNode, visit, visitWithTypeInfo, validate, stripIgnoredCharacters } from 'graphql';
|
7
10
|
import { queries } from './queries.js';
|
8
11
|
|
@@ -12,26 +15,41 @@ const queriesPaths = [
|
|
12
15
|
"cjs",
|
13
16
|
"ts"
|
14
17
|
].map((extname)=>join(queriesDir, `queries.${extname}`));
|
18
|
+
const schemaPaths = [
|
19
|
+
"js",
|
20
|
+
"cjs",
|
21
|
+
"ts"
|
22
|
+
].map((extname)=>join(queriesDir, `schema.${extname}`));
|
15
23
|
const hash = (data)=>createHash("sha256").update(data).digest("base64url");
|
16
|
-
var index = declare((_api, {
|
24
|
+
var index = declare((_api, { development = env.NODE_ENV === "development", schema = getSchema().schema, queries: queries$1 = queries })=>{
|
17
25
|
return {
|
18
26
|
name: "babel-plugin-graphql-tagged-template",
|
19
27
|
visitor: {
|
20
28
|
...development ? {} : {
|
21
29
|
VariableDeclarator (path, { filename = "" }) {
|
22
|
-
if (
|
30
|
+
if (queriesPaths.includes(filename) && path.get("id").isIdentifier({
|
23
31
|
name: "queries"
|
24
|
-
}))
|
25
|
-
|
32
|
+
})) {
|
33
|
+
const sortedQueries = Object.fromEntries(Object.entries(queries$1).sort(([a], [b])=>a.localeCompare(b)));
|
34
|
+
path.get("init").replaceWith(types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("assign")), [
|
35
|
+
types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("create")), [
|
36
|
+
types.nullLiteral()
|
37
|
+
]),
|
38
|
+
types.callExpression(types.memberExpression(types.identifier("JSON"), types.identifier("parse")), [
|
39
|
+
types.stringLiteral(JSON.stringify(sortedQueries))
|
40
|
+
])
|
41
|
+
]));
|
42
|
+
} else if (schemaPaths.includes(filename) && path.get("id").isIdentifier({
|
43
|
+
name: "schema"
|
44
|
+
})) {
|
45
|
+
const source = printSchemaWithDirectives(schema);
|
46
|
+
const documentNode = parse(source, {
|
47
|
+
noLocation: true
|
48
|
+
});
|
49
|
+
path.get("init").replaceWith(types.callExpression(types.memberExpression(types.identifier("JSON"), types.identifier("parse")), [
|
50
|
+
types.stringLiteral(JSON.stringify(documentNode))
|
51
|
+
]));
|
26
52
|
}
|
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
53
|
}
|
36
54
|
},
|
37
55
|
TaggedTemplateExpression (path) {
|
package/dist/schema.cjs
ADDED
package/dist/schema.d.ts
ADDED
package/dist/schema.js
ADDED
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.4.4",
|
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.4",
|
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": "
|
64
|
+
"gitHead": "d441e61abb10c23ade3abb7217a9044e15fe767c"
|
57
65
|
}
|