mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-11 10:46:25 +03:00
fix kriti template generation for array type
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10865 GitOrigin-RevId: ae4b0646dce567e15b03050bc424e17e51f10737
This commit is contained in:
parent
8dae5ae742
commit
81049db4d8
@ -90,7 +90,7 @@ describe('generateAction', () => {
|
||||
),
|
||||
headers: [],
|
||||
queryParams:
|
||||
'{{ concat ([concat({{ range _, x := $body.input?.tags }} "tags={{x}}&" {{ end }}), "limit={{$body.input?.limit}}&"]) }}',
|
||||
'{{ concat ([{{ if empty($body.input?.tags) }} [] {{ else }} concat({{ range _, x := $body.input?.tags }} "tags={{x}}&" {{ end }}) {{ end }}, "limit={{$body.input?.limit}}&"]) }}',
|
||||
});
|
||||
});
|
||||
|
||||
@ -111,13 +111,14 @@ describe('generateQueryParams', () => {
|
||||
it('should generate query params with one non-array param and one array param', async () => {
|
||||
const queryParams = await generateQueryParams([status, tags]);
|
||||
expect(queryParams).toBe(
|
||||
'{{ concat (["status={{$body.input?.status}}&", concat({{ range _, x := $body.input?.tags }} "tags={{x}}&" {{ end }})]) }}'
|
||||
'{{ concat (["status={{$body.input?.status}}&", {{ if empty($body.input?.tags) }} [] {{ else }} concat({{ range _, x := $body.input?.tags }} "tags={{x}}&" {{ end }}) {{ end }}]) }}'
|
||||
);
|
||||
});
|
||||
it('should generate query params with one non-array param and one array param (reversed)', async () => {
|
||||
const queryParams = await generateQueryParams([tags, status]);
|
||||
console.log(queryParams);
|
||||
expect(queryParams).toBe(
|
||||
'{{ concat ([concat({{ range _, x := $body.input?.tags }} "tags={{x}}&" {{ end }}), "status={{$body.input?.status}}&"]) }}'
|
||||
'{{ concat ([{{ if empty($body.input?.tags) }} [] {{ else }} concat({{ range _, x := $body.input?.tags }} "tags={{x}}&" {{ end }}) {{ end }}, "status={{$body.input?.status}}&"]) }}'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -74,7 +74,7 @@ export const generateQueryParams = (parameters: OperationParameters) => {
|
||||
if (isThereArray) {
|
||||
const stringParams = parameters.map(param => {
|
||||
if (isSchemaObject(param?.schema) && param.schema.type === 'array') {
|
||||
return `concat({{ range _, x := $body.input?.${param.name} }} "${param.name}={{x}}&" {{ end }})`;
|
||||
return `{{ if empty($body.input?.${param.name}) }} [] {{ else }} concat({{ range _, x := $body.input?.${param.name} }} "${param.name}={{x}}&" {{ end }}) {{ end }}`;
|
||||
}
|
||||
return `"${param.name}={{$body.input?.${param.name}}}&"`;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user