aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-macro-relay/bun-macro-relay.tsx
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-30 22:35:34 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-30 22:35:34 -0700
commitf9a906873e92f91104bfa869ed45eb9f5cbd39e1 (patch)
treed4c416aa01c8495e4e2013a9ed9bf8a04f4e5cc7 /packages/bun-macro-relay/bun-macro-relay.tsx
parent4be8aaeab83df751ef0f7ac558121f42d240f810 (diff)
downloadbun-f9a906873e92f91104bfa869ed45eb9f5cbd39e1.tar.gz
bun-f9a906873e92f91104bfa869ed45eb9f5cbd39e1.tar.zst
bun-f9a906873e92f91104bfa869ed45eb9f5cbd39e1.zip
bun-macro-relay works now!
Diffstat (limited to 'packages/bun-macro-relay/bun-macro-relay.tsx')
-rw-r--r--packages/bun-macro-relay/bun-macro-relay.tsx48
1 files changed, 27 insertions, 21 deletions
diff --git a/packages/bun-macro-relay/bun-macro-relay.tsx b/packages/bun-macro-relay/bun-macro-relay.tsx
index 018f8f7f5..88285a0c3 100644
--- a/packages/bun-macro-relay/bun-macro-relay.tsx
+++ b/packages/bun-macro-relay/bun-macro-relay.tsx
@@ -5,17 +5,29 @@ import { parse, print } from "graphql";
// 2. From the parsed GraphQL query, get the AST definition.
// 3. From the AST definition, inject an import to that file inside the artifact directory
// 4. MD5 the printed source text
-// 5. At runtime, if md5 !== import.md5, then warn the user that the query has changed
+// 5. (TODO) At runtime, if md5 !== import.md5, then warn the user that the query has changed
// but the file hasn't been updated so it must be reloaded.
// 6. Replace the TemplateLiteral with the default identifier from the injected import
-let artifactDirectory: string =
- process?.env?.BUN_MACRO_RELAY_ARTIFACT_DIRECTORY ??
- process?.env?.RELAY_ARTIFACT_DIRECTORY ??
- `__generated__`;
+let artifactDirectory: string = `__generated__`;
-artifactDirectory = artifactDirectory.startsWith("/")
- ? artifactDirectory
- : Bun.cwd + artifactDirectory;
+if (process.env.RELAY_ARTIFACT_DIRECTORY) {
+ artifactDirectory = process.env.RELAY_ARTIFACT_DIRECTORY;
+}
+
+if (process.env.BUN_MACRO_RELAY_ARTIFACT_DIRECTORY) {
+ artifactDirectory = process.env.BUN_MACRO_RELAY_ARTIFACT_DIRECTORY;
+}
+
+if (!artifactDirectory.startsWith("/")) {
+ while (artifactDirectory.endsWith("/")) {
+ artifactDirectory = artifactDirectory.substring(
+ 0,
+ artifactDirectory.length - 1
+ );
+ }
+
+ artifactDirectory = Bun.cwd + artifactDirectory;
+}
export function graphql(node) {
let query;
@@ -57,20 +69,14 @@ export function graphql(node) {
const importStmt = (
<import
default={definitionName}
- path={`${artifactDirectory}/${definitionName}`}
+ path={`${artifactDirectory}/${definitionName}.graphql`}
/>
);
- try {
- const ret = (
- <>
- <inject>{importStmt}</inject>
- <id to={importStmt.namespace[definitionName]} pure />
- </>
- );
- return ret;
- } catch (exception) {
- console.error(exception);
- }
- return null;
+ return (
+ <>
+ <inject>{importStmt}</inject>
+ <id to={importStmt.namespace[definitionName]} pure />
+ </>
+ );
}