mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-06-12 17:34:27 +02:00
Support new GraphQL body type in curl export
This commit is contained in:
@@ -51,9 +51,12 @@ export async function pluginHookExport(_ctx: Context, request: Partial<HttpReque
|
|||||||
}
|
}
|
||||||
xs.push(NEWLINE);
|
xs.push(NEWLINE);
|
||||||
}
|
}
|
||||||
|
} else if (typeof request.body?.query === 'string') {
|
||||||
|
const body = { query: request.body.query, variables: request.body.variables ?? undefined };
|
||||||
|
xs.push('--data-raw', `${quote(JSON.stringify(body))}`);
|
||||||
|
xs.push(NEWLINE);
|
||||||
} else if (typeof request.body?.text === 'string') {
|
} else if (typeof request.body?.text === 'string') {
|
||||||
// --data-raw $'...' to do special ANSI C quoting
|
xs.push('--data-raw', `${quote(request.body.text)}`);
|
||||||
xs.push('--data-raw', `$${quote(request.body.text)}`);
|
|
||||||
xs.push(NEWLINE);
|
xs.push(NEWLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,22 @@ describe('exporter-curl', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 () => {
|
test('Exports PUT with multipart form', async () => {
|
||||||
expect(
|
expect(
|
||||||
await pluginHookExport(ctx, {
|
await pluginHookExport(ctx, {
|
||||||
@@ -78,7 +94,7 @@ describe('exporter-curl', () => {
|
|||||||
[
|
[
|
||||||
`curl -X POST 'https://yaak.app'`,
|
`curl -X POST 'https://yaak.app'`,
|
||||||
`--header 'Content-Type: application/json'`,
|
`--header 'Content-Type: application/json'`,
|
||||||
`--data-raw $'{"foo":"bar\\'s"}'`,
|
`--data-raw '{"foo":"bar\\'s"}'`,
|
||||||
].join(` \\\n `),
|
].join(` \\\n `),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -98,7 +114,7 @@ describe('exporter-curl', () => {
|
|||||||
[
|
[
|
||||||
`curl -X POST 'https://yaak.app'`,
|
`curl -X POST 'https://yaak.app'`,
|
||||||
`--header 'Content-Type: application/json'`,
|
`--header 'Content-Type: application/json'`,
|
||||||
`--data-raw $'{"foo":"bar",\n"baz":"qux"}'`,
|
`--data-raw '{"foo":"bar",\n"baz":"qux"}'`,
|
||||||
].join(` \\\n `),
|
].join(` \\\n `),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user