From be6513796f6ed6762b8e8c7202587b4b49ea5198 Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Fri, 8 Nov 2024 11:26:41 -0500 Subject: [PATCH] Fix dumping payload with outfile --- .../__tests__/__snapshots__/syncTest.ts.snap | 33 +++++++++++++++++++ javascript_client/src/__tests__/syncTest.ts | 22 +++++++++++++ javascript_client/src/sync/index.ts | 1 + 3 files changed, 56 insertions(+) diff --git a/javascript_client/src/__tests__/__snapshots__/syncTest.ts.snap b/javascript_client/src/__tests__/__snapshots__/syncTest.ts.snap index f85f7ca208..baefca5d21 100644 --- a/javascript_client/src/__tests__/__snapshots__/syncTest.ts.snap +++ b/javascript_client/src/__tests__/__snapshots__/syncTest.ts.snap @@ -728,6 +728,39 @@ fragment Todo_user on User { ] `; +exports[`sync operations Sync output Can dump payload and outfile at the same time 1`] = ` +"{ + "operations": [ + { + "name": "GetStuff", + "body": "fragment Frag1 on Query {\\n moreStuff\\n}\\n\\nquery GetStuff {\\n ...Frag1\\n}", + "alias": "4568c28d403794e011363caf815ec827" + }, + { + "name": "GetStuff2", + "body": "fragment Frag1 on Query {\\n moreStuff\\n}\\n\\nfragment Frag2 on Query {\\n ...Frag3\\n}\\n\\nfragment Frag3 on Query {\\n evenMoreStuff\\n}\\n\\nquery GetStuff2 {\\n stuff\\n ...Frag1\\n ...Frag2\\n}", + "alias": "faf462be033e16dd2a56130d56a9192f" + }, + { + "name": "GetStuff3", + "body": "fragment Frag2 on Query {\\n ...Frag3\\n}\\n\\nfragment Frag3 on Query {\\n evenMoreStuff\\n}\\n\\nfragment Frag4 on Query {\\n evenMoreStuff {\\n stuffInside\\n }\\n}\\n\\nquery GetStuff3 {\\n stuff {\\n withStuffInside\\n }\\n ...Frag2\\n ...Frag4\\n}", + "alias": "aab385a1685772ad520fc70d468030fa" + }, + { + "name": "GetStuffIsolated", + "body": "query GetStuffIsolated {\\n ...FragIsolated\\n things {\\n existHere\\n }\\n}\\n\\nfragment FragIsolated on Query {\\n evenMoreStuff {\\n stuffInside\\n }\\n}", + "alias": "b2cb0b317d071f9f38905fba21d73258" + }, + { + "name": "GetStuffIsolated2", + "body": "query GetStuffIsolated2 {\\n things {\\n existHere\\n }\\n}", + "alias": "6cdae165fd6dc5dc5900e5a2bba90cc2" + } + ] +} +" +`; + exports[`sync operations custom file processing options Adds .graphql to the glob if needed 1`] = ` [ { diff --git a/javascript_client/src/__tests__/syncTest.ts b/javascript_client/src/__tests__/syncTest.ts index f9b07719f8..e749760553 100644 --- a/javascript_client/src/__tests__/syncTest.ts +++ b/javascript_client/src/__tests__/syncTest.ts @@ -296,6 +296,28 @@ describe("sync operations", () => { }) }) + it("Can dump payload and outfile at the same time", () => { + var options = { + client: "test-2", + path: "./src/__tests__/project", + quiet: true, + outfile: "customOutfile.js", + dumpPayload: "customDumpPayload.js" + } + + return sync(options).then(function() { + var generatedCode = fs.readFileSync("./customOutfile.js", "utf8") + expect(generatedCode).toMatch('"GetStuff": "4568c28d403794e011363caf815ec827"') + expect(generatedCode).toMatch('module.exports = OperationStoreClient') + expect(generatedCode).toMatch('var _client = "test-2"') + + var generatedPayload = fs.readFileSync("./customDumpPayload.js", "utf8") + expect(generatedPayload).toMatchSnapshot() + fs.unlinkSync("./customOutfile.js") + fs.unlinkSync("./customDumpPayload.js") + }) + }) + it("Skips outfile generation when using --persist-output artifact", () => { var options = { client: "test-2", diff --git a/javascript_client/src/sync/index.ts b/javascript_client/src/sync/index.ts index 8286ac71e4..818c56f5d6 100644 --- a/javascript_client/src/sync/index.ts +++ b/javascript_client/src/sync/index.ts @@ -221,6 +221,7 @@ function sync(options: SyncOptions) { }) } else if (dumpingPayload) { sendFunc(payload, { dumpPayload: options.dumpPayload }) + resolve(payload) return } else { // This is a local-only run to generate an artifact