-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v0] Add integration test for a complex URL as an endpoint for JSON S…
…chema handler
- Loading branch information
Showing
8 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
sources: | ||
- name: upstream | ||
handler: | ||
jsonSchema: | ||
endpoint: 'http://username:password@localhost:8515' | ||
operations: | ||
- type: Query | ||
field: getData | ||
path: '?request=GetData&some_arg={args.some_arg}&some_val=0' | ||
method: GET | ||
responseSample: ./assets/getData.json | ||
responseTypeName: GetDataResponse | ||
argTypeMap: | ||
some_arg: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", | ||
"url": "/?request=GetData&some_arg=some_arg_value&some_val=0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@examples/json-schema-complex-url", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"build": "mesh build", | ||
"start": "concurrently \"npm run start:api\" \"npm run start:mesh\"", | ||
"start:api": "tsx src/index.ts", | ||
"start:mesh": "mesh start" | ||
}, | ||
"dependencies": { | ||
"@graphql-mesh/cli": "0.98.23", | ||
"@graphql-mesh/json-schema": "0.108.20", | ||
"graphql": "16.10.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "22.13.4", | ||
"concurrently": "9.1.2", | ||
"tsx": "4.19.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"template": "node", | ||
"container": { | ||
"node": "16" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createServer } from 'node:http'; | ||
|
||
export default createServer((req, res) => { | ||
res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
res.end( | ||
JSON.stringify({ | ||
authorization: req.headers.authorization, | ||
url: req.url, | ||
}), | ||
); | ||
}).listen(8515, () => { | ||
console.log('Server is running on http://localhost:8515'); | ||
}); |
46 changes: 46 additions & 0 deletions
46
examples/json-schema-complex-url/tests/json-schema-complex-url.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { MeshInstance } from '@graphql-mesh/runtime'; | ||
import { getBuiltMesh } from '../.mesh'; | ||
import upstream from '../src'; | ||
|
||
describe('JSON Schema Complex URL', () => { | ||
let mesh: MeshInstance; | ||
beforeAll(async () => { | ||
mesh = await getBuiltMesh(); | ||
}); | ||
afterAll(() => { | ||
mesh.destroy(); | ||
return new Promise<void>((resolve, reject) => { | ||
upstream.close(err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('receives username, password and query params correctly', async () => { | ||
const some_arg = new Date().toISOString(); | ||
const result = await mesh.execute( | ||
/* GraphQL */ ` | ||
query GetData($some_arg: String!) { | ||
getData(some_arg: $some_arg) { | ||
authorization | ||
url | ||
} | ||
} | ||
`, | ||
{ | ||
some_arg, | ||
}, | ||
); | ||
expect(result).toMatchObject({ | ||
data: { | ||
getData: { | ||
authorization: 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', | ||
url: `/?request=GetData&some_arg=${some_arg}&some_val=0`, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
"packageManager": "[email protected]", | ||
"scripts": { | ||
"build": "yarn prebuild && bob build && yarn postbuild", | ||
"build-test-artifacts": "yarn workspace @examples/json-schema-example build && yarn workspace @examples-v1-next/fastify compose && yarn workspace @examples/fastify build && yarn workspace @examples/persisted-operations build && yarn workspace example-response-cache build", | ||
"build-test-artifacts": "yarn workspace @examples/json-schema-example build && yarn workspace @examples-v1-next/fastify compose && yarn workspace @examples/fastify build && yarn workspace @examples/persisted-operations build && yarn workspace example-response-cache build && yarn workspace @examples/json-schema-complex-url build", | ||
"build:website": "yarn build && cd website && yarn build", | ||
"changeset": "changeset", | ||
"changeset-version": "changeset version && yarn postchangeset", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters