From d91e60f7e08916d13e003c1785be2bf327204368 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Tue, 22 Oct 2024 07:26:16 -0700 Subject: [PATCH] Support new GraphQL body type in curl export --- plugins/exporter-curl/src/index.ts | 7 +++++-- plugins/exporter-curl/tests/index.test.ts | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/exporter-curl/src/index.ts b/plugins/exporter-curl/src/index.ts index 97814c82..5fdbdaf7 100644 --- a/plugins/exporter-curl/src/index.ts +++ b/plugins/exporter-curl/src/index.ts @@ -51,9 +51,12 @@ export async function pluginHookExport(_ctx: Context, request: Partial { ); }); + test('Exports POST with GraphQL data', async () => { + expect( + await pluginHookExport(ctx, { + url: 'https://yaak.app', + method: 'POST', + bodyType: 'graphql', + body: { + query : '{foo,bar}', + variables: {a: 'aaa', b: 'bbb'}, + }, + }), + ).toEqual( + [`curl -X POST 'https://yaak.app'`, `--data-raw '{"query":"{foo,bar}","variables":{"a":"aaa","b":"bbb"}}'`].join(` \\\n `), + ); + }); + test('Exports PUT with multipart form', async () => { expect( await pluginHookExport(ctx, { @@ -78,7 +94,7 @@ describe('exporter-curl', () => { [ `curl -X POST 'https://yaak.app'`, `--header 'Content-Type: application/json'`, - `--data-raw $'{"foo":"bar\\'s"}'`, + `--data-raw '{"foo":"bar\\'s"}'`, ].join(` \\\n `), ); }); @@ -98,7 +114,7 @@ describe('exporter-curl', () => { [ `curl -X POST 'https://yaak.app'`, `--header 'Content-Type: application/json'`, - `--data-raw $'{"foo":"bar",\n"baz":"qux"}'`, + `--data-raw '{"foo":"bar",\n"baz":"qux"}'`, ].join(` \\\n `), ); });