@isograph/babel-plugin 0.0.0-main-5db9ddb2 → 0.0.0-main-0f7357fb

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.
Files changed (2) hide show
  1. package/compileTag.js +23 -10
  2. package/package.json +1 -1
package/compileTag.js CHANGED
@@ -13,10 +13,18 @@ const os = require('os');
13
13
  function compileTag(t, path, config) {
14
14
  const callee = path.node.callee;
15
15
  if (t.isIdentifier(callee) && callee.name === 'iso' && path.node.arguments) {
16
- const { keyword, type, field } = getTypeAndField(path);
16
+ const { keyword, parentObjectEntityName, selectableName } =
17
+ getParentObjectEntityNameAndSelectableName(path);
17
18
  if (keyword === 'entrypoint') {
18
19
  // This throws if the tag is invalid
19
- compileImportStatement(t, path, type, field, 'entrypoint', config);
20
+ compileImportStatement(
21
+ t,
22
+ path,
23
+ parentObjectEntityName,
24
+ selectableName,
25
+ 'entrypoint',
26
+ config,
27
+ );
20
28
  } else if (keyword === 'field' || keyword === 'pointer') {
21
29
  if (t.isCallExpression(path.parentPath.node)) {
22
30
  const firstArg = path.parentPath.node.arguments[0];
@@ -41,7 +49,7 @@ function compileTag(t, path, config) {
41
49
  return false;
42
50
  }
43
51
 
44
- const typeAndFieldRegex = new RegExp(
52
+ const parentObjectEntityNameAndSelectableNameRegex = new RegExp(
45
53
  '\\s*(entrypoint|field|pointer)\\s*([^\\.\\s]+)\\.([^\\s\\(]+)',
46
54
  'm',
47
55
  );
@@ -49,7 +57,7 @@ const typeAndFieldRegex = new RegExp(
49
57
  /**
50
58
  * @param {babel.NodePath<babel.types.CallExpression>} path
51
59
  **/
52
- function getTypeAndField(path) {
60
+ function getParentObjectEntityNameAndSelectableName(path) {
53
61
  const firstArg = path.node.arguments[0];
54
62
  if (path.node.arguments.length !== 1 || firstArg == null) {
55
63
  throw new Error(
@@ -72,18 +80,23 @@ function getTypeAndField(path) {
72
80
  }
73
81
 
74
82
  const content = firstQuasi.value.raw;
75
- const typeAndField = typeAndFieldRegex.exec(content);
83
+ const typeAndField =
84
+ parentObjectEntityNameAndSelectableNameRegex.exec(content);
76
85
 
77
86
  const keyword = typeAndField?.[1];
78
- const type = typeAndField?.[2];
79
- const field = typeAndField?.[3];
80
-
81
- if (keyword == null || type == null || field == null) {
87
+ const parentObjectEntityName = typeAndField?.[2];
88
+ const selectableName = typeAndField?.[3];
89
+
90
+ if (
91
+ keyword == null ||
92
+ parentObjectEntityName == null ||
93
+ selectableName == null
94
+ ) {
82
95
  throw new Error(
83
96
  'Malformed iso literal. I hope the iso compiler failed to accept this literal!',
84
97
  );
85
98
  }
86
- return { keyword, type, field };
99
+ return { keyword, parentObjectEntityName, selectableName };
87
100
  }
88
101
 
89
102
  /**
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@isograph/babel-plugin",
3
3
  "description": "A Babel plugin for use with Isograph applications.",
4
4
  "homepage": "https://isograph.dev",
5
- "version": "0.0.0-main-5db9ddb2",
5
+ "version": "0.0.0-main-0f7357fb",
6
6
  "keywords": [
7
7
  "graphql",
8
8
  "isograph",