Skip to content

Commit

Permalink
[v0] Add integration test for a complex URL as an endpoint for JSON S…
Browse files Browse the repository at this point in the history
…chema handler
  • Loading branch information
ardatan committed Feb 18, 2025
1 parent f08dd68 commit f989c74
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 2 deletions.
15 changes: 15 additions & 0 deletions examples/json-schema-complex-url/.meshrc.yml
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
4 changes: 4 additions & 0 deletions examples/json-schema-complex-url/assets/getData.json
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"
}
21 changes: 21 additions & 0 deletions examples/json-schema-complex-url/package.json
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"
}
}
6 changes: 6 additions & 0 deletions examples/json-schema-complex-url/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"template": "node",
"container": {
"node": "16"
}
}
13 changes: 13 additions & 0 deletions examples/json-schema-complex-url/src/index.ts
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');
});
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=',

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Basic dXNlcm5hbWU6cGFzc3dvcmQ=" is used as
authorization header
.
url: `/?request=GetData&some_arg=${some_arg}&some_val=0`,
},
},
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5182,6 +5182,19 @@ __metadata:
languageName: unknown
linkType: soft

"@examples/json-schema-complex-url@workspace:examples/json-schema-complex-url":
version: 0.0.0-use.local
resolution: "@examples/json-schema-complex-url@workspace:examples/json-schema-complex-url"
dependencies:
"@graphql-mesh/cli": "npm:0.98.23"
"@graphql-mesh/json-schema": "npm:0.108.20"
"@types/node": "npm:22.13.4"
concurrently: "npm:9.1.2"
graphql: "npm:16.10.0"
tsx: "npm:4.19.2"
languageName: unknown
linkType: soft

"@examples/json-schema-covid@workspace:examples/json-schema-covid":
version: 0.0.0-use.local
resolution: "@examples/json-schema-covid@workspace:examples/json-schema-covid"
Expand Down Expand Up @@ -35861,7 +35874,7 @@ __metadata:
languageName: node
linkType: hard

"tsx@npm:^4.16.5, tsx@npm:^4.19.0":
"tsx@npm:4.19.2, tsx@npm:^4.16.5, tsx@npm:^4.19.0":
version: 4.19.2
resolution: "tsx@npm:4.19.2"
dependencies:
Expand Down

0 comments on commit f989c74

Please sign in to comment.