mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-06-12 09:24:29 +02:00
Fix GraphQL variables
This commit is contained in:
@@ -52,7 +52,7 @@ export async function pluginHookExport(_ctx: Context, request: Partial<HttpReque
|
|||||||
xs.push(NEWLINE);
|
xs.push(NEWLINE);
|
||||||
}
|
}
|
||||||
} else if (typeof request.body?.query === 'string') {
|
} else if (typeof request.body?.query === 'string') {
|
||||||
const body = { query: request.body.query, variables: request.body.variables ?? undefined };
|
const body = { query: request.body.query || '', variables: maybeParseJSON(request.body.variables, {}) };
|
||||||
xs.push('--data-raw', `${quote(JSON.stringify(body))}`);
|
xs.push('--data-raw', `${quote(JSON.stringify(body))}`);
|
||||||
xs.push(NEWLINE);
|
xs.push(NEWLINE);
|
||||||
} else if (typeof request.body?.text === 'string') {
|
} else if (typeof request.body?.text === 'string') {
|
||||||
@@ -92,3 +92,11 @@ function quote(arg: string): string {
|
|||||||
function onlyEnabled(v: { name?: string; enabled?: boolean }): boolean {
|
function onlyEnabled(v: { name?: string; enabled?: boolean }): boolean {
|
||||||
return v.enabled !== false && !!v.name;
|
return v.enabled !== false && !!v.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function maybeParseJSON(v: any, fallback: any): string {
|
||||||
|
try {
|
||||||
|
return JSON.parse(v);
|
||||||
|
} catch (err) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ describe('exporter-curl', () => {
|
|||||||
bodyType: 'graphql',
|
bodyType: 'graphql',
|
||||||
body: {
|
body: {
|
||||||
query : '{foo,bar}',
|
query : '{foo,bar}',
|
||||||
variables: {a: 'aaa', b: 'bbb'},
|
variables: '{"a": "aaa", "b": "bbb"}',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).toEqual(
|
).toEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user