Skip to content

Commit cb0cd4c

Browse files
committed
tests
1 parent 1920d35 commit cb0cd4c

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

packages/openapi-to-graphql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"build": "tsc --project ../../tsconfig.build.json",
6363
"guru-load": "node test/evaluation/load_apis_guru.js",
6464
"guru-test": "DEBUG=preprocessing,translation node test/evaluation/eval_apis_guru.js",
65-
"test": "jest --runInBand --detectOpenHandles -t 'Optionally use queryString'"
65+
"test": "jest --runInBand --detectOpenHandles"
6666
},
6767
"husky": {
6868
"hooks": {

packages/openapi-to-graphql/test/example_api6.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,41 @@ test('Handle no response schema', () => {
396396
})
397397
})
398398
})
399+
400+
/**
401+
* GET /arrayInQueryParameters with and without the useQueryString requestOption
402+
*
403+
* The default behaviour is to add indexed parameters, i.e. a[0]=x&a[1]=y.
404+
* The querystring behaviour (which can be made configurable in the future) is a=x&a=y
405+
*/
406+
test('Optionally use queryString', () => {
407+
const query = `{
408+
arrayInQueryParameters(ids: ["a", "b"])
409+
}`
410+
411+
// Use default settings
412+
const promise = graphql(createdSchema, query).then((result) => {
413+
expect(result.data).toEqual({
414+
arrayInQueryParameters: encodeURI('ids[0]=a&ids[1]=b')
415+
})
416+
})
417+
418+
// Set useQueryString to true
419+
const options: Options<any, any, any> = {
420+
requestOptions: {
421+
useQueryString: true
422+
}
423+
}
424+
425+
const promise2 = openAPIToGraphQL
426+
.createGraphQLSchema(oas, options)
427+
.then(({ schema, report }) => {
428+
return graphql(schema, query).then((result) => {
429+
expect(result.data).toEqual({
430+
arrayInQueryParameters: encodeURI('ids=a&ids=b')
431+
})
432+
})
433+
})
434+
435+
return Promise.all([promise, promise2])
436+
})

packages/openapi-to-graphql/test/example_api6_server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ function startServer(PORT) {
5757
}
5858
)
5959

60+
app.get(
61+
'/api/arrayInQueryParameters',
62+
(req, res) => {
63+
res.send(req.originalUrl.split('?')[1])
64+
}
65+
)
66+
6067
function stringifyRussianDolls(russianDoll) {
6168
if (!typeof russianDoll.name === 'string') {
6269
return ''

packages/openapi-to-graphql/test/fixtures/example_oas6.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,36 @@
416416
}
417417
}
418418
}
419+
},
420+
"/arrayInQueryParameters": {
421+
"get": {
422+
"description": "Takes an array as GET query parameter",
423+
"responses": {
424+
"200": {
425+
"description": "Success",
426+
"content": {
427+
"text/html": {
428+
"schema": {
429+
"type": "string"
430+
}
431+
}
432+
}
433+
}
434+
},
435+
"parameters": [
436+
{
437+
"name": "ids",
438+
"in": "query",
439+
"required": false,
440+
"schema": {
441+
"type": "array",
442+
"items": {
443+
"type": "string"
444+
}
445+
}
446+
}
447+
]
448+
}
419449
}
420450
},
421451
"components": {

0 commit comments

Comments
 (0)