Skip to content

Commit 9a6ae85

Browse files
@graphql-hive/importer and point to exact syntax error while parsing config (#462)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5b69bdd commit 9a6ae85

30 files changed

+587
-34
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@graphql-hive/gateway': patch
3+
---
4+
5+
dependencies updates:
6+
7+
- Added dependency [`@graphql-hive/importer@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-hive/importer/v/workspace:^) (to `dependencies`)
8+
- Removed dependency [`@graphql-mesh/include@^0.2.3` ↗︎](https://www.npmjs.com/package/@graphql-mesh/include/v/0.2.3) (from `dependencies`)

.changeset/lemon-zebras-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/gateway': patch
3+
---
4+
5+
Use `@graphql-hive/importer` for importing configs and transpiling TypeScript files

.changeset/plenty-timers-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/gateway': minor
3+
---
4+
5+
Point to exact location of syntax error when parsing malformed config files

.changeset/strong-ghosts-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/importer': major
3+
---
4+
5+
Improving Hive's importing capabilities allowing it to parse TypeScript files

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ __generated__
99
.wrangler/
1010
*.Dockerfile
1111
/examples/
12+
/packages/importer/tests/fixtures/syntax-error.ts
13+
/e2e/config-syntax-error/gateway.config.ts
14+
/e2e/config-syntax-error/custom-resolvers.ts
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { createTenv } from '@internal/e2e';
2+
import { isCI } from '@internal/testing';
3+
import { expect, it } from 'vitest';
4+
5+
const { gateway, service, gatewayRunner } = createTenv(__dirname);
6+
7+
it.skipIf(
8+
// for whatever reason docker in CI sometimes (sometimes is the keyword, more than less)
9+
// doesnt provide all the logs and throws errors with weird messages and I dont know where from or why
10+
// see https://github.com/graphql-hive/gateway/actions/runs/12830196184/job/35777821364
11+
isCI() && gatewayRunner === 'docker',
12+
)(
13+
'should point to exact location of syntax error when parsing a malformed config',
14+
async () => {
15+
await expect(
16+
gateway({
17+
supergraph: {
18+
with: 'mesh',
19+
services: [await service('hello')],
20+
},
21+
runner: {
22+
docker: {
23+
volumes: [
24+
{
25+
host: 'custom-resolvers.ts',
26+
container: '/gateway/custom-resolvers.ts',
27+
},
28+
],
29+
},
30+
},
31+
}),
32+
).rejects.toThrowError(
33+
gatewayRunner === 'bun' || gatewayRunner === 'bun-docker'
34+
? /error: Expected "{" but found "hello"(.|\n)*\/custom-resolvers.ts:8:11/
35+
: /SyntaxError \[Error\]: Error transforming .*(\/|\\)custom-resolvers.ts: Unexpected token, expected "{" \(8:11\)/,
36+
);
37+
},
38+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @ts-nocheck -- syntax error intentionally
2+
3+
import { GatewayContext } from '@graphql-hive/gateway';
4+
import { IResolvers } from '@graphql-tools/utils';
5+
6+
export const customResolvers: IResolvers<unknown, GatewayContext> = {
7+
Query: {
8+
bye() hello {
9+
return 'world';
10+
},
11+
},
12+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from '@graphql-hive/gateway';
2+
import { customResolvers } from './custom-resolvers';
3+
4+
export const gatewayConfig = defineConfig({
5+
additionalResolvers: [customResolvers],
6+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {
2+
defineConfig,
3+
loadGraphQLHTTPSubgraph,
4+
} from '@graphql-mesh/compose-cli';
5+
import { Opts } from '@internal/testing';
6+
7+
const opts = Opts(process.argv);
8+
9+
export const composeConfig = defineConfig({
10+
subgraphs: [
11+
{
12+
sourceHandler: loadGraphQLHTTPSubgraph('hello', {
13+
endpoint: `http://localhost:${opts.getServicePort('hello')}/graphql`,
14+
}),
15+
},
16+
],
17+
additionalTypeDefs: /* GraphQL */ `
18+
extend type Query {
19+
bye: String!
20+
}
21+
`,
22+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@e2e/config-syntax-error",
3+
"private": true,
4+
"dependencies": {
5+
"@graphql-mesh/compose-cli": "^1.2.13",
6+
"@graphql-tools/utils": "^10.7.2",
7+
"graphql": "^16.9.0",
8+
"tslib": "^2.8.1"
9+
}
10+
}

0 commit comments

Comments
 (0)