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 (#8393)
  • Loading branch information
ardatan authored Feb 19, 2025
1 parent cc9af0b commit 82a538b
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 3 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=',
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
54 changes: 52 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5220,6 +5220,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 @@ -8177,7 +8190,7 @@ __metadata:
languageName: node
linkType: hard

"@graphql-tools/executor@npm:^1.3.10, @graphql-tools/executor@npm:^1.3.2, @graphql-tools/executor@npm:^1.3.6":
"@graphql-tools/executor@npm:^1.3.10, @graphql-tools/executor@npm:^1.3.2, @graphql-tools/executor@npm:^1.3.6, @graphql-tools/executor@npm:^1.3.7":
version: 1.3.14
resolution: "@graphql-tools/executor@npm:1.3.14"
dependencies:
Expand Down Expand Up @@ -22741,7 +22754,7 @@ __metadata:
languageName: node
linkType: hard

"graphql-yoga@npm:5.12.0, graphql-yoga@npm:^5.10.10, graphql-yoga@npm:^5.10.11, graphql-yoga@npm:^5.10.6, graphql-yoga@npm:^5.7.0":
"graphql-yoga@npm:5.12.0, graphql-yoga@npm:^5.10.10, graphql-yoga@npm:^5.10.11, graphql-yoga@npm:^5.7.0":
version: 5.12.0
resolution: "graphql-yoga@npm:5.12.0"
dependencies:
Expand All @@ -22762,6 +22775,27 @@ __metadata:
languageName: node
linkType: hard

"graphql-yoga@npm:^5.10.6":
version: 5.10.11
resolution: "graphql-yoga@npm:5.10.11"
dependencies:
"@envelop/core": "npm:^5.0.2"
"@graphql-tools/executor": "npm:^1.3.7"
"@graphql-tools/schema": "npm:^10.0.11"
"@graphql-tools/utils": "npm:^10.6.2"
"@graphql-yoga/logger": "npm:^2.0.1"
"@graphql-yoga/subscription": "npm:^5.0.3"
"@whatwg-node/fetch": "npm:^0.10.1"
"@whatwg-node/server": "npm:^0.9.64"
dset: "npm:^3.1.4"
lru-cache: "npm:^10.0.0"
tslib: "npm:^2.8.1"
peerDependencies:
graphql: ^15.2.0 || ^16.0.0
checksum: 10c0/74b3ad3ff77656c680b36044c2655e8e95624fa51f4cb189c7d7d23a17ce14538fd13a552eea78fd1eddd3cc2e1c2f98bb529ad66a83a2869d9306f648f15368
languageName: node
linkType: hard

"graphql@npm:16.10.0":
version: 16.10.0
resolution: "graphql@npm:16.10.0"
Expand Down Expand Up @@ -35912,6 +35946,22 @@ __metadata:
languageName: node
linkType: hard

"tsx@npm:4.19.2":
version: 4.19.2
resolution: "tsx@npm:4.19.2"
dependencies:
esbuild: "npm:~0.23.0"
fsevents: "npm:~2.3.3"
get-tsconfig: "npm:^4.7.5"
dependenciesMeta:
fsevents:
optional: true
bin:
tsx: dist/cli.mjs
checksum: 10c0/63164b889b1d170403e4d8753a6755dec371f220f5ce29a8e88f1f4d6085a784a12d8dc2ee669116611f2c72757ac9beaa3eea5c452796f541bdd2dc11753721
languageName: node
linkType: hard

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

0 comments on commit 82a538b

Please sign in to comment.