@mo36924/babel-plugin-graphql-tagged-template 1.5.21 → 1.5.22

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.cjs CHANGED
@@ -7,6 +7,17 @@ const graphql = require('graphql');
7
7
 
8
8
  let _schema;
9
9
  const index = ({ types: t }, options) => {
10
+ const clientTag = "@mo36924/graphql-client-tag";
11
+ const hooksTag = "@mo36924/graphql-hooks-tag";
12
+ const client = options.client ?? "fetch";
13
+ let parseQuery = false;
14
+ let clientModule = "@mo36924/graphql-fetch-client";
15
+ let hooksModule = "@mo36924/graphql-fetch-hooks";
16
+ if (client === "postgres") {
17
+ parseQuery = true;
18
+ clientModule = "@mo36924/graphql-postgres-client";
19
+ hooksModule = "@mo36924/graphql-postgres-hooks";
20
+ }
10
21
  let schema = options.schema
11
22
  ? typeof options.schema === "object"
12
23
  ? options.schema
@@ -19,7 +30,31 @@ const index = ({ types: t }, options) => {
19
30
  return {
20
31
  name: "graphql-tagged-template",
21
32
  visitor: {
22
- TaggedTemplateExpression(path, state) {
33
+ ImportDeclaration(path) {
34
+ if (path.node.source.value === clientTag) {
35
+ path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(clientModule)));
36
+ }
37
+ else if (path.node.source.value === hooksTag) {
38
+ path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(hooksModule)));
39
+ }
40
+ },
41
+ ExportAllDeclaration(path) {
42
+ if (path.node.source.value === clientTag) {
43
+ path.replaceWith(t.exportAllDeclaration(t.stringLiteral(clientModule)));
44
+ }
45
+ else if (path.node.source.value === hooksTag) {
46
+ path.replaceWith(t.exportAllDeclaration(t.stringLiteral(hooksModule)));
47
+ }
48
+ },
49
+ ExportNamedDeclaration(path) {
50
+ if (path.node.source && path.node.source.value === clientTag) {
51
+ path.replaceWith(t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(clientModule)));
52
+ }
53
+ else if (path.node.source && path.node.source.value === hooksTag) {
54
+ path.replaceWith(t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(hooksModule)));
55
+ }
56
+ },
57
+ TaggedTemplateExpression(path) {
23
58
  const { tag, quasi: { quasis, expressions }, } = path.node;
24
59
  if (!t.isIdentifier(tag)) {
25
60
  return;
@@ -79,21 +114,21 @@ const index = ({ types: t }, options) => {
79
114
  if (errors.length) {
80
115
  throw path.buildCodeFrameError(errors[0].message);
81
116
  }
82
- const args = [];
83
- if (options.parse) {
117
+ const properties = [];
118
+ if (parseQuery) {
84
119
  const id = path.scope.generateUid("gql");
85
120
  path.scope.getProgramParent().push({ kind: "let", id: t.identifier(id) });
86
- args.push(t.assignmentExpression("||=", t.identifier(id), t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [
121
+ properties.push(t.objectProperty(t.identifier("document"), t.assignmentExpression("||=", t.identifier(id), t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [
87
122
  t.stringLiteral(JSON.stringify(documentNode)),
88
- ])));
123
+ ]))));
89
124
  }
90
125
  else {
91
- args.push(t.stringLiteral(graphql.stripIgnoredCharacters(query)));
126
+ properties.push(t.objectProperty(t.identifier("query"), t.stringLiteral(graphql.stripIgnoredCharacters(query))));
92
127
  }
93
128
  if (expressions.length) {
94
- args.push(t.arrayExpression(expressions));
129
+ properties.push(t.objectProperty(t.identifier("variables"), t.objectExpression(expressions.map((expression, i) => t.objectProperty(t.identifier("_" + i), expression)))));
95
130
  }
96
- path.replaceWith(t.callExpression(t.identifier(name), args));
131
+ path.replaceWith(t.callExpression(t.identifier(name), [t.objectExpression(properties)]));
97
132
  },
98
133
  },
99
134
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import babel, { PluginObj, types as t } from \"@babel/core\";\nimport { buildASTSchema } from \"@mo36924/graphql-build\";\nimport { config } from \"@mo36924/graphql-config\";\nimport { buildModel } from \"@mo36924/graphql-model\";\nimport {\n DocumentNode,\n GraphQLInputType,\n GraphQLSchema,\n TypeInfo,\n buildSchema,\n parse,\n stripIgnoredCharacters,\n validate,\n visit,\n visitWithTypeInfo,\n} from \"graphql\";\n\nexport type Options = {\n model?: string | DocumentNode;\n schema?: string | GraphQLSchema;\n parse?: boolean;\n};\n\nlet _schema: GraphQLSchema;\n\nexport default ({ types: t }: typeof babel, options: Options): PluginObj => {\n let schema = options.schema\n ? typeof options.schema === \"object\"\n ? options.schema\n : buildSchema(options.schema)\n : options.model\n ? typeof options.model === \"object\"\n ? buildASTSchema(options.model)\n : buildModel(options.model).schema\n : (_schema ||= config().schema);\n\n return {\n name: \"graphql-tagged-template\",\n visitor: {\n TaggedTemplateExpression(path, state) {\n const {\n tag,\n quasi: { quasis, expressions },\n } = path.node;\n\n if (!t.isIdentifier(tag)) {\n return;\n }\n\n const name = tag.name;\n let operation = \"\";\n\n switch (name) {\n case \"gql\":\n case \"query\":\n case \"useQuery\":\n break;\n case \"mutation\":\n case \"useMutation\":\n operation = \"mutation\";\n break;\n case \"subscription\":\n case \"useSubscription\":\n operation = \"subscription\";\n break;\n default:\n return;\n }\n\n let query = operation + (quasis[0].value.cooked ?? quasis[0].value.raw);\n\n for (let i = 0; i < expressions.length; i++) {\n query += `$_${i}${quasis[i + 1].value.cooked ?? quasis[i + 1].value.raw}`;\n }\n\n let documentNode: DocumentNode;\n\n try {\n documentNode = parse(query);\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const values: GraphQLInputType[] = [];\n const typeInfo = new TypeInfo(schema);\n\n visit(\n documentNode,\n visitWithTypeInfo(typeInfo, {\n Variable() {\n values.push(typeInfo.getInputType()!);\n },\n }),\n );\n\n if (values.length) {\n const variables = `(${values.map((value, i) => `$_${i}:${value}`).join()})`;\n\n if (operation) {\n query = operation + variables + query.slice(operation.length);\n } else if (name !== \"gql\") {\n query = \"query\" + variables + query;\n }\n }\n\n try {\n documentNode = parse(query, { noLocation: true });\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const errors = validate(schema, documentNode);\n\n if (errors.length) {\n throw path.buildCodeFrameError(errors[0].message);\n }\n\n const args: t.Expression[] = [];\n\n if (options.parse) {\n const id = path.scope.generateUid(\"gql\");\n path.scope.getProgramParent().push({ kind: \"let\", id: t.identifier(id) });\n\n args.push(\n t.assignmentExpression(\n \"||=\",\n t.identifier(id),\n t.callExpression(t.memberExpression(t.identifier(\"JSON\"), t.identifier(\"parse\")), [\n t.stringLiteral(JSON.stringify(documentNode)),\n ]),\n ),\n );\n } else {\n args.push(t.stringLiteral(stripIgnoredCharacters(query)));\n }\n\n if (expressions.length) {\n args.push(t.arrayExpression(expressions as t.Expression[]));\n }\n\n path.replaceWith(t.callExpression(t.identifier(name), args));\n },\n },\n };\n};\n"],"names":["buildSchema","buildASTSchema","buildModel","config","parse","TypeInfo","visit","visitWithTypeInfo","validate","stripIgnoredCharacters"],"mappings":";;;;;;;AAuBA,IAAI,OAAsB,CAAC;AAE3B,cAAe,CAAC,EAAE,KAAK,EAAE,CAAC,EAAgB,EAAE,OAAgB,KAAe;AACzE,IAAA,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM;AACzB,UAAE,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;cAChC,OAAO,CAAC,MAAM;AAChB,cAAEA,mBAAW,CAAC,OAAO,CAAC,MAAM,CAAC;UAC7B,OAAO,CAAC,KAAK;AACf,cAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;AACjC,kBAAEC,2BAAc,CAAC,OAAO,CAAC,KAAK,CAAC;kBAC7BC,uBAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM;eACjC,OAAO,KAAKC,oBAAM,EAAE,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO;AACL,QAAA,IAAI,EAAE,yBAAyB;AAC/B,QAAA,OAAO,EAAE;YACP,wBAAwB,CAAC,IAAI,EAAE,KAAK,EAAA;AAClC,gBAAA,MAAM,EACJ,GAAG,EACH,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,GAC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sources":["../src/index.ts"],"sourcesContent":["import babel, { PluginObj, types as t } from \"@babel/core\";\nimport { buildASTSchema } from \"@mo36924/graphql-build\";\nimport { config } from \"@mo36924/graphql-config\";\nimport { buildModel } from \"@mo36924/graphql-model\";\nimport {\n DocumentNode,\n GraphQLInputType,\n GraphQLSchema,\n TypeInfo,\n buildSchema,\n parse,\n stripIgnoredCharacters,\n validate,\n visit,\n visitWithTypeInfo,\n} from \"graphql\";\n\nexport type Options = {\n client?: \"fetch\" | \"postgres\";\n model?: string | DocumentNode;\n schema?: string | GraphQLSchema;\n};\n\nlet _schema: GraphQLSchema;\n\nexport default ({ types: t }: typeof babel, options: Options): PluginObj => {\n const clientTag = \"@mo36924/graphql-client-tag\";\n const hooksTag = \"@mo36924/graphql-hooks-tag\";\n const client = options.client ?? \"fetch\";\n let parseQuery: boolean = false;\n let clientModule = \"@mo36924/graphql-fetch-client\";\n let hooksModule = \"@mo36924/graphql-fetch-hooks\";\n\n if (client === \"postgres\") {\n parseQuery = true;\n clientModule = \"@mo36924/graphql-postgres-client\";\n hooksModule = \"@mo36924/graphql-postgres-hooks\";\n }\n\n let schema = options.schema\n ? typeof options.schema === \"object\"\n ? options.schema\n : buildSchema(options.schema)\n : options.model\n ? typeof options.model === \"object\"\n ? buildASTSchema(options.model)\n : buildModel(options.model).schema\n : (_schema ||= config().schema);\n\n return {\n name: \"graphql-tagged-template\",\n visitor: {\n ImportDeclaration(path) {\n if (path.node.source.value === clientTag) {\n path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(clientModule)));\n } else if (path.node.source.value === hooksTag) {\n path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(hooksModule)));\n }\n },\n ExportAllDeclaration(path) {\n if (path.node.source.value === clientTag) {\n path.replaceWith(t.exportAllDeclaration(t.stringLiteral(clientModule)));\n } else if (path.node.source.value === hooksTag) {\n path.replaceWith(t.exportAllDeclaration(t.stringLiteral(hooksModule)));\n }\n },\n ExportNamedDeclaration(path) {\n if (path.node.source && path.node.source.value === clientTag) {\n path.replaceWith(\n t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(clientModule)),\n );\n } else if (path.node.source && path.node.source.value === hooksTag) {\n path.replaceWith(\n t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(hooksModule)),\n );\n }\n },\n TaggedTemplateExpression(path) {\n const {\n tag,\n quasi: { quasis, expressions },\n } = path.node;\n\n if (!t.isIdentifier(tag)) {\n return;\n }\n\n const name = tag.name;\n let operation = \"\";\n\n switch (name) {\n case \"gql\":\n case \"query\":\n case \"useQuery\":\n break;\n case \"mutation\":\n case \"useMutation\":\n operation = \"mutation\";\n break;\n case \"subscription\":\n case \"useSubscription\":\n operation = \"subscription\";\n break;\n default:\n return;\n }\n\n let query = operation + (quasis[0].value.cooked ?? quasis[0].value.raw);\n\n for (let i = 0; i < expressions.length; i++) {\n query += `$_${i}${quasis[i + 1].value.cooked ?? quasis[i + 1].value.raw}`;\n }\n\n let documentNode: DocumentNode;\n\n try {\n documentNode = parse(query);\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const values: GraphQLInputType[] = [];\n const typeInfo = new TypeInfo(schema);\n\n visit(\n documentNode,\n visitWithTypeInfo(typeInfo, {\n Variable() {\n values.push(typeInfo.getInputType()!);\n },\n }),\n );\n\n if (values.length) {\n const variables = `(${values.map((value, i) => `$_${i}:${value}`).join()})`;\n\n if (operation) {\n query = operation + variables + query.slice(operation.length);\n } else if (name !== \"gql\") {\n query = \"query\" + variables + query;\n }\n }\n\n try {\n documentNode = parse(query, { noLocation: true });\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const errors = validate(schema, documentNode);\n\n if (errors.length) {\n throw path.buildCodeFrameError(errors[0].message);\n }\n\n const properties: t.ObjectProperty[] = [];\n\n if (parseQuery) {\n const id = path.scope.generateUid(\"gql\");\n path.scope.getProgramParent().push({ kind: \"let\", id: t.identifier(id) });\n\n properties.push(\n t.objectProperty(\n t.identifier(\"document\"),\n t.assignmentExpression(\n \"||=\",\n t.identifier(id),\n t.callExpression(t.memberExpression(t.identifier(\"JSON\"), t.identifier(\"parse\")), [\n t.stringLiteral(JSON.stringify(documentNode)),\n ]),\n ),\n ),\n );\n } else {\n properties.push(t.objectProperty(t.identifier(\"query\"), t.stringLiteral(stripIgnoredCharacters(query))));\n }\n\n if (expressions.length) {\n properties.push(\n t.objectProperty(\n t.identifier(\"variables\"),\n t.objectExpression(\n expressions.map((expression, i) => t.objectProperty(t.identifier(\"_\" + i), expression as t.Expression)),\n ),\n ),\n );\n }\n\n path.replaceWith(t.callExpression(t.identifier(name), [t.objectExpression(properties)]));\n },\n },\n };\n};\n"],"names":["buildSchema","buildASTSchema","buildModel","config","parse","TypeInfo","visit","visitWithTypeInfo","validate","stripIgnoredCharacters"],"mappings":";;;;;;;AAuBA,IAAI,OAAsB,CAAC;AAE3B,cAAe,CAAC,EAAE,KAAK,EAAE,CAAC,EAAgB,EAAE,OAAgB,KAAe;IACzE,MAAM,SAAS,GAAG,6BAA6B,CAAC;IAChD,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAC9C,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;IACzC,IAAI,UAAU,GAAY,KAAK,CAAC;IAChC,IAAI,YAAY,GAAG,+BAA+B,CAAC;IACnD,IAAI,WAAW,GAAG,8BAA8B,CAAC;IAEjD,IAAI,MAAM,KAAK,UAAU,EAAE;QACzB,UAAU,GAAG,IAAI,CAAC;QAClB,YAAY,GAAG,kCAAkC,CAAC;QAClD,WAAW,GAAG,iCAAiC,CAAC;AACjD,KAAA;AAED,IAAA,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM;AACzB,UAAE,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;cAChC,OAAO,CAAC,MAAM;AAChB,cAAEA,mBAAW,CAAC,OAAO,CAAC,MAAM,CAAC;UAC7B,OAAO,CAAC,KAAK;AACf,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GraphQLSchema } from 'graphql';
3
3
 
4
4
  declare type Options = {
5
+ client?: "fetch" | "postgres";
5
6
  model?: string | DocumentNode;
6
7
  schema?: string | GraphQLSchema;
7
- parse?: boolean;
8
8
  };
9
9
  declare const _default: ({ types: t }: typeof babel, options: Options) => PluginObj;
10
10
 
package/dist/index.js CHANGED
@@ -5,6 +5,17 @@ import { buildSchema, parse, TypeInfo, visit, visitWithTypeInfo, validate, strip
5
5
 
6
6
  let _schema;
7
7
  const index = ({ types: t }, options) => {
8
+ const clientTag = "@mo36924/graphql-client-tag";
9
+ const hooksTag = "@mo36924/graphql-hooks-tag";
10
+ const client = options.client ?? "fetch";
11
+ let parseQuery = false;
12
+ let clientModule = "@mo36924/graphql-fetch-client";
13
+ let hooksModule = "@mo36924/graphql-fetch-hooks";
14
+ if (client === "postgres") {
15
+ parseQuery = true;
16
+ clientModule = "@mo36924/graphql-postgres-client";
17
+ hooksModule = "@mo36924/graphql-postgres-hooks";
18
+ }
8
19
  let schema = options.schema
9
20
  ? typeof options.schema === "object"
10
21
  ? options.schema
@@ -17,7 +28,31 @@ const index = ({ types: t }, options) => {
17
28
  return {
18
29
  name: "graphql-tagged-template",
19
30
  visitor: {
20
- TaggedTemplateExpression(path, state) {
31
+ ImportDeclaration(path) {
32
+ if (path.node.source.value === clientTag) {
33
+ path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(clientModule)));
34
+ }
35
+ else if (path.node.source.value === hooksTag) {
36
+ path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(hooksModule)));
37
+ }
38
+ },
39
+ ExportAllDeclaration(path) {
40
+ if (path.node.source.value === clientTag) {
41
+ path.replaceWith(t.exportAllDeclaration(t.stringLiteral(clientModule)));
42
+ }
43
+ else if (path.node.source.value === hooksTag) {
44
+ path.replaceWith(t.exportAllDeclaration(t.stringLiteral(hooksModule)));
45
+ }
46
+ },
47
+ ExportNamedDeclaration(path) {
48
+ if (path.node.source && path.node.source.value === clientTag) {
49
+ path.replaceWith(t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(clientModule)));
50
+ }
51
+ else if (path.node.source && path.node.source.value === hooksTag) {
52
+ path.replaceWith(t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(hooksModule)));
53
+ }
54
+ },
55
+ TaggedTemplateExpression(path) {
21
56
  const { tag, quasi: { quasis, expressions }, } = path.node;
22
57
  if (!t.isIdentifier(tag)) {
23
58
  return;
@@ -77,21 +112,21 @@ const index = ({ types: t }, options) => {
77
112
  if (errors.length) {
78
113
  throw path.buildCodeFrameError(errors[0].message);
79
114
  }
80
- const args = [];
81
- if (options.parse) {
115
+ const properties = [];
116
+ if (parseQuery) {
82
117
  const id = path.scope.generateUid("gql");
83
118
  path.scope.getProgramParent().push({ kind: "let", id: t.identifier(id) });
84
- args.push(t.assignmentExpression("||=", t.identifier(id), t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [
119
+ properties.push(t.objectProperty(t.identifier("document"), t.assignmentExpression("||=", t.identifier(id), t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [
85
120
  t.stringLiteral(JSON.stringify(documentNode)),
86
- ])));
121
+ ]))));
87
122
  }
88
123
  else {
89
- args.push(t.stringLiteral(stripIgnoredCharacters(query)));
124
+ properties.push(t.objectProperty(t.identifier("query"), t.stringLiteral(stripIgnoredCharacters(query))));
90
125
  }
91
126
  if (expressions.length) {
92
- args.push(t.arrayExpression(expressions));
127
+ properties.push(t.objectProperty(t.identifier("variables"), t.objectExpression(expressions.map((expression, i) => t.objectProperty(t.identifier("_" + i), expression)))));
93
128
  }
94
- path.replaceWith(t.callExpression(t.identifier(name), args));
129
+ path.replaceWith(t.callExpression(t.identifier(name), [t.objectExpression(properties)]));
95
130
  },
96
131
  },
97
132
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import babel, { PluginObj, types as t } from \"@babel/core\";\nimport { buildASTSchema } from \"@mo36924/graphql-build\";\nimport { config } from \"@mo36924/graphql-config\";\nimport { buildModel } from \"@mo36924/graphql-model\";\nimport {\n DocumentNode,\n GraphQLInputType,\n GraphQLSchema,\n TypeInfo,\n buildSchema,\n parse,\n stripIgnoredCharacters,\n validate,\n visit,\n visitWithTypeInfo,\n} from \"graphql\";\n\nexport type Options = {\n model?: string | DocumentNode;\n schema?: string | GraphQLSchema;\n parse?: boolean;\n};\n\nlet _schema: GraphQLSchema;\n\nexport default ({ types: t }: typeof babel, options: Options): PluginObj => {\n let schema = options.schema\n ? typeof options.schema === \"object\"\n ? options.schema\n : buildSchema(options.schema)\n : options.model\n ? typeof options.model === \"object\"\n ? buildASTSchema(options.model)\n : buildModel(options.model).schema\n : (_schema ||= config().schema);\n\n return {\n name: \"graphql-tagged-template\",\n visitor: {\n TaggedTemplateExpression(path, state) {\n const {\n tag,\n quasi: { quasis, expressions },\n } = path.node;\n\n if (!t.isIdentifier(tag)) {\n return;\n }\n\n const name = tag.name;\n let operation = \"\";\n\n switch (name) {\n case \"gql\":\n case \"query\":\n case \"useQuery\":\n break;\n case \"mutation\":\n case \"useMutation\":\n operation = \"mutation\";\n break;\n case \"subscription\":\n case \"useSubscription\":\n operation = \"subscription\";\n break;\n default:\n return;\n }\n\n let query = operation + (quasis[0].value.cooked ?? quasis[0].value.raw);\n\n for (let i = 0; i < expressions.length; i++) {\n query += `$_${i}${quasis[i + 1].value.cooked ?? quasis[i + 1].value.raw}`;\n }\n\n let documentNode: DocumentNode;\n\n try {\n documentNode = parse(query);\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const values: GraphQLInputType[] = [];\n const typeInfo = new TypeInfo(schema);\n\n visit(\n documentNode,\n visitWithTypeInfo(typeInfo, {\n Variable() {\n values.push(typeInfo.getInputType()!);\n },\n }),\n );\n\n if (values.length) {\n const variables = `(${values.map((value, i) => `$_${i}:${value}`).join()})`;\n\n if (operation) {\n query = operation + variables + query.slice(operation.length);\n } else if (name !== \"gql\") {\n query = \"query\" + variables + query;\n }\n }\n\n try {\n documentNode = parse(query, { noLocation: true });\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const errors = validate(schema, documentNode);\n\n if (errors.length) {\n throw path.buildCodeFrameError(errors[0].message);\n }\n\n const args: t.Expression[] = [];\n\n if (options.parse) {\n const id = path.scope.generateUid(\"gql\");\n path.scope.getProgramParent().push({ kind: \"let\", id: t.identifier(id) });\n\n args.push(\n t.assignmentExpression(\n \"||=\",\n t.identifier(id),\n t.callExpression(t.memberExpression(t.identifier(\"JSON\"), t.identifier(\"parse\")), [\n t.stringLiteral(JSON.stringify(documentNode)),\n ]),\n ),\n );\n } else {\n args.push(t.stringLiteral(stripIgnoredCharacters(query)));\n }\n\n if (expressions.length) {\n args.push(t.arrayExpression(expressions as t.Expression[]));\n }\n\n path.replaceWith(t.callExpression(t.identifier(name), args));\n },\n },\n };\n};\n"],"names":[],"mappings":";;;;;AAuBA,IAAI,OAAsB,CAAC;AAE3B,cAAe,CAAC,EAAE,KAAK,EAAE,CAAC,EAAgB,EAAE,OAAgB,KAAe;AACzE,IAAA,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM;AACzB,UAAE,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;cAChC,OAAO,CAAC,MAAM;AAChB,cAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;UAC7B,OAAO,CAAC,KAAK;AACf,cAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;AACjC,kBAAE,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC;kBAC7B,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM;eACjC,OAAO,KAAK,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO;AACL,QAAA,IAAI,EAAE,yBAAyB;AAC/B,QAAA,OAAO,EAAE;YACP,wBAAwB,CAAC,IAAI,EAAE,KAAK,EAAA;AAClC,gBAAA,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SAAA;KACF,CAAC;AACJ,CAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import babel, { PluginObj, types as t } from \"@babel/core\";\nimport { buildASTSchema } from \"@mo36924/graphql-build\";\nimport { config } from \"@mo36924/graphql-config\";\nimport { buildModel } from \"@mo36924/graphql-model\";\nimport {\n DocumentNode,\n GraphQLInputType,\n GraphQLSchema,\n TypeInfo,\n buildSchema,\n parse,\n stripIgnoredCharacters,\n validate,\n visit,\n visitWithTypeInfo,\n} from \"graphql\";\n\nexport type Options = {\n client?: \"fetch\" | \"postgres\";\n model?: string | DocumentNode;\n schema?: string | GraphQLSchema;\n};\n\nlet _schema: GraphQLSchema;\n\nexport default ({ types: t }: typeof babel, options: Options): PluginObj => {\n const clientTag = \"@mo36924/graphql-client-tag\";\n const hooksTag = \"@mo36924/graphql-hooks-tag\";\n const client = options.client ?? \"fetch\";\n let parseQuery: boolean = false;\n let clientModule = \"@mo36924/graphql-fetch-client\";\n let hooksModule = \"@mo36924/graphql-fetch-hooks\";\n\n if (client === \"postgres\") {\n parseQuery = true;\n clientModule = \"@mo36924/graphql-postgres-client\";\n hooksModule = \"@mo36924/graphql-postgres-hooks\";\n }\n\n let schema = options.schema\n ? typeof options.schema === \"object\"\n ? options.schema\n : buildSchema(options.schema)\n : options.model\n ? typeof options.model === \"object\"\n ? buildASTSchema(options.model)\n : buildModel(options.model).schema\n : (_schema ||= config().schema);\n\n return {\n name: \"graphql-tagged-template\",\n visitor: {\n ImportDeclaration(path) {\n if (path.node.source.value === clientTag) {\n path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(clientModule)));\n } else if (path.node.source.value === hooksTag) {\n path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(hooksModule)));\n }\n },\n ExportAllDeclaration(path) {\n if (path.node.source.value === clientTag) {\n path.replaceWith(t.exportAllDeclaration(t.stringLiteral(clientModule)));\n } else if (path.node.source.value === hooksTag) {\n path.replaceWith(t.exportAllDeclaration(t.stringLiteral(hooksModule)));\n }\n },\n ExportNamedDeclaration(path) {\n if (path.node.source && path.node.source.value === clientTag) {\n path.replaceWith(\n t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(clientModule)),\n );\n } else if (path.node.source && path.node.source.value === hooksTag) {\n path.replaceWith(\n t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(hooksModule)),\n );\n }\n },\n TaggedTemplateExpression(path) {\n const {\n tag,\n quasi: { quasis, expressions },\n } = path.node;\n\n if (!t.isIdentifier(tag)) {\n return;\n }\n\n const name = tag.name;\n let operation = \"\";\n\n switch (name) {\n case \"gql\":\n case \"query\":\n case \"useQuery\":\n break;\n case \"mutation\":\n case \"useMutation\":\n operation = \"mutation\";\n break;\n case \"subscription\":\n case \"useSubscription\":\n operation = \"subscription\";\n break;\n default:\n return;\n }\n\n let query = operation + (quasis[0].value.cooked ?? quasis[0].value.raw);\n\n for (let i = 0; i < expressions.length; i++) {\n query += `$_${i}${quasis[i + 1].value.cooked ?? quasis[i + 1].value.raw}`;\n }\n\n let documentNode: DocumentNode;\n\n try {\n documentNode = parse(query);\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const values: GraphQLInputType[] = [];\n const typeInfo = new TypeInfo(schema);\n\n visit(\n documentNode,\n visitWithTypeInfo(typeInfo, {\n Variable() {\n values.push(typeInfo.getInputType()!);\n },\n }),\n );\n\n if (values.length) {\n const variables = `(${values.map((value, i) => `$_${i}:${value}`).join()})`;\n\n if (operation) {\n query = operation + variables + query.slice(operation.length);\n } else if (name !== \"gql\") {\n query = \"query\" + variables + query;\n }\n }\n\n try {\n documentNode = parse(query, { noLocation: true });\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const errors = validate(schema, documentNode);\n\n if (errors.length) {\n throw path.buildCodeFrameError(errors[0].message);\n }\n\n const properties: t.ObjectProperty[] = [];\n\n if (parseQuery) {\n const id = path.scope.generateUid(\"gql\");\n path.scope.getProgramParent().push({ kind: \"let\", id: t.identifier(id) });\n\n properties.push(\n t.objectProperty(\n t.identifier(\"document\"),\n t.assignmentExpression(\n \"||=\",\n t.identifier(id),\n t.callExpression(t.memberExpression(t.identifier(\"JSON\"), t.identifier(\"parse\")), [\n t.stringLiteral(JSON.stringify(documentNode)),\n ]),\n ),\n ),\n );\n } else {\n properties.push(t.objectProperty(t.identifier(\"query\"), t.stringLiteral(stripIgnoredCharacters(query))));\n }\n\n if (expressions.length) {\n properties.push(\n t.objectProperty(\n t.identifier(\"variables\"),\n t.objectExpression(\n expressions.map((expression, i) => t.objectProperty(t.identifier(\"_\" + i), expression as t.Expression)),\n ),\n ),\n );\n }\n\n path.replaceWith(t.callExpression(t.identifier(name), [t.objectExpression(properties)]));\n },\n },\n };\n};\n"],"names":[],"mappings":";;;;;AAuBA,IAAI,OAAsB,CAAC;AAE3B,cAAe,CAAC,EAAE,KAAK,EAAE,CAAC,EAAgB,EAAE,OAAgB,KAAe;IACzE,MAAM,SAAS,GAAG,6BAA6B,CAAC;IAChD,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAC9C,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;IACzC,IAAI,UAAU,GAAY,KAAK,CAAC;IAChC,IAAI,YAAY,GAAG,+BAA+B,CAAC;IACnD,IAAI,WAAW,GAAG,8BAA8B,CAAC;IAEjD,IAAI,MAAM,KAAK,UAAU,EAAE;QACzB,UAAU,GAAG,IAAI,CAAC;QAClB,YAAY,GAAG,kCAAkC,CAAC;QAClD,WAAW,GAAG,iCAAiC,CAAC;AACjD,KAAA;AAED,IAAA,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM;AACzB,UAAE,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;cAChC,OAAO,CAAC,MAAM;AAChB,cAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;UAC7B,OAAO,CAAC,KAAK;AACf,cAAE,OAAO,OAAO,C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({ types: t }, options) => {
8
+ const clientTag = "@mo36924/graphql-client-tag";
9
+ const hooksTag = "@mo36924/graphql-hooks-tag";
10
+ const client = options.client ?? "fetch";
11
+ let parseQuery = false;
12
+ let clientModule = "@mo36924/graphql-fetch-client";
13
+ let hooksModule = "@mo36924/graphql-fetch-hooks";
14
+ if (client === "postgres") {
15
+ parseQuery = true;
16
+ clientModule = "@mo36924/graphql-postgres-client";
17
+ hooksModule = "@mo36924/graphql-postgres-hooks";
18
+ }
8
19
  let schema = options.schema
9
20
  ? typeof options.schema === "object"
10
21
  ? options.schema
@@ -17,7 +28,31 @@ const index = ({ types: t }, options) => {
17
28
  return {
18
29
  name: "graphql-tagged-template",
19
30
  visitor: {
20
- TaggedTemplateExpression(path, state) {
31
+ ImportDeclaration(path) {
32
+ if (path.node.source.value === clientTag) {
33
+ path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(clientModule)));
34
+ }
35
+ else if (path.node.source.value === hooksTag) {
36
+ path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(hooksModule)));
37
+ }
38
+ },
39
+ ExportAllDeclaration(path) {
40
+ if (path.node.source.value === clientTag) {
41
+ path.replaceWith(t.exportAllDeclaration(t.stringLiteral(clientModule)));
42
+ }
43
+ else if (path.node.source.value === hooksTag) {
44
+ path.replaceWith(t.exportAllDeclaration(t.stringLiteral(hooksModule)));
45
+ }
46
+ },
47
+ ExportNamedDeclaration(path) {
48
+ if (path.node.source && path.node.source.value === clientTag) {
49
+ path.replaceWith(t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(clientModule)));
50
+ }
51
+ else if (path.node.source && path.node.source.value === hooksTag) {
52
+ path.replaceWith(t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(hooksModule)));
53
+ }
54
+ },
55
+ TaggedTemplateExpression(path) {
21
56
  const { tag, quasi: { quasis, expressions }, } = path.node;
22
57
  if (!t.isIdentifier(tag)) {
23
58
  return;
@@ -77,21 +112,21 @@ const index = ({ types: t }, options) => {
77
112
  if (errors.length) {
78
113
  throw path.buildCodeFrameError(errors[0].message);
79
114
  }
80
- const args = [];
81
- if (options.parse) {
115
+ const properties = [];
116
+ if (parseQuery) {
82
117
  const id = path.scope.generateUid("gql");
83
118
  path.scope.getProgramParent().push({ kind: "let", id: t.identifier(id) });
84
- args.push(t.assignmentExpression("||=", t.identifier(id), t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [
119
+ properties.push(t.objectProperty(t.identifier("document"), t.assignmentExpression("||=", t.identifier(id), t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [
85
120
  t.stringLiteral(JSON.stringify(documentNode)),
86
- ])));
121
+ ]))));
87
122
  }
88
123
  else {
89
- args.push(t.stringLiteral(stripIgnoredCharacters(query)));
124
+ properties.push(t.objectProperty(t.identifier("query"), t.stringLiteral(stripIgnoredCharacters(query))));
90
125
  }
91
126
  if (expressions.length) {
92
- args.push(t.arrayExpression(expressions));
127
+ properties.push(t.objectProperty(t.identifier("variables"), t.objectExpression(expressions.map((expression, i) => t.objectProperty(t.identifier("_" + i), expression)))));
93
128
  }
94
- path.replaceWith(t.callExpression(t.identifier(name), args));
129
+ path.replaceWith(t.callExpression(t.identifier(name), [t.objectExpression(properties)]));
95
130
  },
96
131
  },
97
132
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import babel, { PluginObj, types as t } from \"@babel/core\";\nimport { buildASTSchema } from \"@mo36924/graphql-build\";\nimport { config } from \"@mo36924/graphql-config\";\nimport { buildModel } from \"@mo36924/graphql-model\";\nimport {\n DocumentNode,\n GraphQLInputType,\n GraphQLSchema,\n TypeInfo,\n buildSchema,\n parse,\n stripIgnoredCharacters,\n validate,\n visit,\n visitWithTypeInfo,\n} from \"graphql\";\n\nexport type Options = {\n model?: string | DocumentNode;\n schema?: string | GraphQLSchema;\n parse?: boolean;\n};\n\nlet _schema: GraphQLSchema;\n\nexport default ({ types: t }: typeof babel, options: Options): PluginObj => {\n let schema = options.schema\n ? typeof options.schema === \"object\"\n ? options.schema\n : buildSchema(options.schema)\n : options.model\n ? typeof options.model === \"object\"\n ? buildASTSchema(options.model)\n : buildModel(options.model).schema\n : (_schema ||= config().schema);\n\n return {\n name: \"graphql-tagged-template\",\n visitor: {\n TaggedTemplateExpression(path, state) {\n const {\n tag,\n quasi: { quasis, expressions },\n } = path.node;\n\n if (!t.isIdentifier(tag)) {\n return;\n }\n\n const name = tag.name;\n let operation = \"\";\n\n switch (name) {\n case \"gql\":\n case \"query\":\n case \"useQuery\":\n break;\n case \"mutation\":\n case \"useMutation\":\n operation = \"mutation\";\n break;\n case \"subscription\":\n case \"useSubscription\":\n operation = \"subscription\";\n break;\n default:\n return;\n }\n\n let query = operation + (quasis[0].value.cooked ?? quasis[0].value.raw);\n\n for (let i = 0; i < expressions.length; i++) {\n query += `$_${i}${quasis[i + 1].value.cooked ?? quasis[i + 1].value.raw}`;\n }\n\n let documentNode: DocumentNode;\n\n try {\n documentNode = parse(query);\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const values: GraphQLInputType[] = [];\n const typeInfo = new TypeInfo(schema);\n\n visit(\n documentNode,\n visitWithTypeInfo(typeInfo, {\n Variable() {\n values.push(typeInfo.getInputType()!);\n },\n }),\n );\n\n if (values.length) {\n const variables = `(${values.map((value, i) => `$_${i}:${value}`).join()})`;\n\n if (operation) {\n query = operation + variables + query.slice(operation.length);\n } else if (name !== \"gql\") {\n query = \"query\" + variables + query;\n }\n }\n\n try {\n documentNode = parse(query, { noLocation: true });\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const errors = validate(schema, documentNode);\n\n if (errors.length) {\n throw path.buildCodeFrameError(errors[0].message);\n }\n\n const args: t.Expression[] = [];\n\n if (options.parse) {\n const id = path.scope.generateUid(\"gql\");\n path.scope.getProgramParent().push({ kind: \"let\", id: t.identifier(id) });\n\n args.push(\n t.assignmentExpression(\n \"||=\",\n t.identifier(id),\n t.callExpression(t.memberExpression(t.identifier(\"JSON\"), t.identifier(\"parse\")), [\n t.stringLiteral(JSON.stringify(documentNode)),\n ]),\n ),\n );\n } else {\n args.push(t.stringLiteral(stripIgnoredCharacters(query)));\n }\n\n if (expressions.length) {\n args.push(t.arrayExpression(expressions as t.Expression[]));\n }\n\n path.replaceWith(t.callExpression(t.identifier(name), args));\n },\n },\n };\n};\n"],"names":[],"mappings":";;;;;AAuBA,IAAI,OAAsB,CAAC;AAE3B,cAAe,CAAC,EAAE,KAAK,EAAE,CAAC,EAAgB,EAAE,OAAgB,KAAe;AACzE,IAAA,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM;AACzB,UAAE,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;cAChC,OAAO,CAAC,MAAM;AAChB,cAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;UAC7B,OAAO,CAAC,KAAK;AACf,cAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;AACjC,kBAAE,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC;kBAC7B,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM;eACjC,OAAO,KAAK,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO;AACL,QAAA,IAAI,EAAE,yBAAyB;AAC/B,QAAA,OAAO,EAAE;YACP,wBAAwB,CAAC,IAAI,EAAE,KAAK,EAAA;AAClC,gBAAA,MAAM,EACJ,GAAG,EACH,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,GAC/B,GAAG,IAAI,CAAC,IAAI,CAAC;AAEd,gBAAA,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE;oBACxB,OAAO;AACR,iBAAA;AAED,gBAAA,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;gBACtB,IAAI,SAAS,GAAG,EAAE,CAAC;AAEnB,gBAAA,QAAQ,IAAI;AACV,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AK,CAAC,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAE1E,oBAAA,IAAI,CAAC,IAAI,CACP,CAAC,CAAC,oBAAoB,CACpB,KAAK,EACL,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,EAChB,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE;wBAChF,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;qBAC9C,CAAC,CACH,CACF,CAAC;AACH,iBAAA;AAAM,qBAAA;AACL,oBAAA,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3D,iBAAA;gBAED,IAAI,WAAW,CAAC,MAAM,EAAE;oBACtB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,WAA6B,CAAC,CAAC,CAAC;AAC7D,iBAAA;AAED,gBAAA,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;aAC9D;AACF,SAAA;KACF,CAAC;AACJ,CAAC;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import babel, { PluginObj, types as t } from \"@babel/core\";\nimport { buildASTSchema } from \"@mo36924/graphql-build\";\nimport { config } from \"@mo36924/graphql-config\";\nimport { buildModel } from \"@mo36924/graphql-model\";\nimport {\n DocumentNode,\n GraphQLInputType,\n GraphQLSchema,\n TypeInfo,\n buildSchema,\n parse,\n stripIgnoredCharacters,\n validate,\n visit,\n visitWithTypeInfo,\n} from \"graphql\";\n\nexport type Options = {\n client?: \"fetch\" | \"postgres\";\n model?: string | DocumentNode;\n schema?: string | GraphQLSchema;\n};\n\nlet _schema: GraphQLSchema;\n\nexport default ({ types: t }: typeof babel, options: Options): PluginObj => {\n const clientTag = \"@mo36924/graphql-client-tag\";\n const hooksTag = \"@mo36924/graphql-hooks-tag\";\n const client = options.client ?? \"fetch\";\n let parseQuery: boolean = false;\n let clientModule = \"@mo36924/graphql-fetch-client\";\n let hooksModule = \"@mo36924/graphql-fetch-hooks\";\n\n if (client === \"postgres\") {\n parseQuery = true;\n clientModule = \"@mo36924/graphql-postgres-client\";\n hooksModule = \"@mo36924/graphql-postgres-hooks\";\n }\n\n let schema = options.schema\n ? typeof options.schema === \"object\"\n ? options.schema\n : buildSchema(options.schema)\n : options.model\n ? typeof options.model === \"object\"\n ? buildASTSchema(options.model)\n : buildModel(options.model).schema\n : (_schema ||= config().schema);\n\n return {\n name: \"graphql-tagged-template\",\n visitor: {\n ImportDeclaration(path) {\n if (path.node.source.value === clientTag) {\n path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(clientModule)));\n } else if (path.node.source.value === hooksTag) {\n path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral(hooksModule)));\n }\n },\n ExportAllDeclaration(path) {\n if (path.node.source.value === clientTag) {\n path.replaceWith(t.exportAllDeclaration(t.stringLiteral(clientModule)));\n } else if (path.node.source.value === hooksTag) {\n path.replaceWith(t.exportAllDeclaration(t.stringLiteral(hooksModule)));\n }\n },\n ExportNamedDeclaration(path) {\n if (path.node.source && path.node.source.value === clientTag) {\n path.replaceWith(\n t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(clientModule)),\n );\n } else if (path.node.source && path.node.source.value === hooksTag) {\n path.replaceWith(\n t.exportNamedDeclaration(path.node.declaration, path.node.specifiers, t.stringLiteral(hooksModule)),\n );\n }\n },\n TaggedTemplateExpression(path) {\n const {\n tag,\n quasi: { quasis, expressions },\n } = path.node;\n\n if (!t.isIdentifier(tag)) {\n return;\n }\n\n const name = tag.name;\n let operation = \"\";\n\n switch (name) {\n case \"gql\":\n case \"query\":\n case \"useQuery\":\n break;\n case \"mutation\":\n case \"useMutation\":\n operation = \"mutation\";\n break;\n case \"subscription\":\n case \"useSubscription\":\n operation = \"subscription\";\n break;\n default:\n return;\n }\n\n let query = operation + (quasis[0].value.cooked ?? quasis[0].value.raw);\n\n for (let i = 0; i < expressions.length; i++) {\n query += `$_${i}${quasis[i + 1].value.cooked ?? quasis[i + 1].value.raw}`;\n }\n\n let documentNode: DocumentNode;\n\n try {\n documentNode = parse(query);\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const values: GraphQLInputType[] = [];\n const typeInfo = new TypeInfo(schema);\n\n visit(\n documentNode,\n visitWithTypeInfo(typeInfo, {\n Variable() {\n values.push(typeInfo.getInputType()!);\n },\n }),\n );\n\n if (values.length) {\n const variables = `(${values.map((value, i) => `$_${i}:${value}`).join()})`;\n\n if (operation) {\n query = operation + variables + query.slice(operation.length);\n } else if (name !== \"gql\") {\n query = \"query\" + variables + query;\n }\n }\n\n try {\n documentNode = parse(query, { noLocation: true });\n } catch (err) {\n throw path.buildCodeFrameError(String(err));\n }\n\n const errors = validate(schema, documentNode);\n\n if (errors.length) {\n throw path.buildCodeFrameError(errors[0].message);\n }\n\n const properties: t.ObjectProperty[] = [];\n\n if (parseQuery) {\n const id = path.scope.generateUid(\"gql\");\n path.scope.getProgramParent().push({ kind: \"let\", id: t.identifier(id) });\n\n properties.push(\n t.objectProperty(\n t.identifier(\"document\"),\n t.assignmentExpression(\n \"||=\",\n t.identifier(id),\n t.callExpression(t.memberExpression(t.identifier(\"JSON\"), t.identifier(\"parse\")), [\n t.stringLiteral(JSON.stringify(documentNode)),\n ]),\n ),\n ),\n );\n } else {\n properties.push(t.objectProperty(t.identifier(\"query\"), t.stringLiteral(stripIgnoredCharacters(query))));\n }\n\n if (expressions.length) {\n properties.push(\n t.objectProperty(\n t.identifier(\"variables\"),\n t.objectExpression(\n expressions.map((expression, i) => t.objectProperty(t.identifier(\"_\" + i), expression as t.Expression)),\n ),\n ),\n );\n }\n\n path.replaceWith(t.callExpression(t.identifier(name), [t.objectExpression(properties)]));\n },\n },\n };\n};\n"],"names":[],"mappings":";;;;;AAuBA,IAAI,OAAsB,CAAC;AAE3B,cAAe,CAAC,EAAE,KAAK,EAAE,CAAC,EAAgB,EAAE,OAAgB,KAAe;IACzE,MAAM,SAAS,GAAG,6BAA6B,CAAC;IAChD,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAC9C,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;IACzC,IAAI,UAAU,GAAY,KAAK,CAAC;IAChC,IAAI,YAAY,GAAG,+BAA+B,CAAC;IACnD,IAAI,WAAW,GAAG,8BAA8B,CAAC;IAEjD,IAAI,MAAM,KAAK,UAAU,EAAE;QACzB,UAAU,GAAG,IAAI,CAAC;QAClB,YAAY,GAAG,kCAAkC,CAAC;QAClD,WAAW,GAAG,iCAAiC,CAAC;AACjD,KAAA;AAED,IAAA,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM;AACzB,UAAE,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;cAChC,OAAO,CAAC,MAAM;AAChB,cAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;UAC7B,OAAO,CAAC,KAAK;AACf,cAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;AACjC,kBAAE,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC;kBAC7B,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM;eACjC,OAAO,KAAK,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO;AACL,QAAA,IAAI,EAAE,yBAAyB;AAC/B,QAAA,OAAO,EAAE;AACP,YAAA,iBAAiB,CAAC,IAAI,EAAA;gBACpB,IAAI,IAAI,CAAC,I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BAC9C,CAAC,CACH,CACF,CACF,CAAC;AACH,iBAAA;AAAM,qBAAA;oBACL,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1G,iBAAA;gBAED,IAAI,WAAW,CAAC,MAAM,EAAE;oBACtB,UAAU,CAAC,IAAI,CACb,CAAC,CAAC,cAAc,CACd,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,EACzB,CAAC,CAAC,gBAAgB,CAChB,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,UAA0B,CAAC,CAAC,CACxG,CACF,CACF,CAAC;AACH,iBAAA;gBAED,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;aAC1F;AACF,SAAA;KACF,CAAC;AACJ,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mo36924/babel-plugin-graphql-tagged-template",
3
- "version": "1.5.21",
3
+ "version": "1.5.22",
4
4
  "description": "babel-plugin-graphql-tagged-template",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/mo36924/graphql#readme",
@@ -31,13 +31,13 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@babel/core": "^7.17.8",
34
- "@mo36924/graphql-build": "^1.5.21",
35
- "@mo36924/graphql-config": "^1.5.21",
36
- "@mo36924/graphql-model": "^1.5.21",
34
+ "@mo36924/graphql-build": "^1.5.22",
35
+ "@mo36924/graphql-config": "^1.5.22",
36
+ "@mo36924/graphql-model": "^1.5.22",
37
37
  "graphql": "^16.3.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "943062323c8119e2b226abdfbe8a9145870f6042"
42
+ "gitHead": "345391cf7ea2061c78f671824846d5dc0de1df7b"
43
43
  }