Skip to content

Commit 480b6af

Browse files
committed
add typescript tests
1 parent 113e314 commit 480b6af

12 files changed

Lines changed: 1319 additions & 776 deletions

File tree

.github/workflows/typecheck.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: TypeScript Type Check
2+
3+
on:
4+
push: {}
5+
pull_request: {}
6+
7+
jobs:
8+
typecheck:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
node-version: [20.x, 22.x, 24.x]
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Typecheck
29+
run: npm run typecheck
30+
31+
- name: Test TS
32+
run: npm run test:ts

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
## Typescript types
2828
- Improved Typescript d.ts file
29-
- Exported helper interfaces `ApolloServiceSettings`, `ApolloServiceMethods`, `ApolloServiceLocalVars` to support Moleculer 0.15 Service generics
29+
- Exported helper interfaces `ApolloServiceSettings`, `ApolloServiceMethods`, `ApolloServiceLocalVars` to support Moleculer 0.15 Service generics.
3030
- Augmented Moleculer `ActionSchema` with graphql property.
31+
- Typescript CI tests.
3132

3233
--------------------------------------------------
3334
<a name="0.3.8"></a>

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,25 +254,31 @@ with the results in the same order as they were provided.
254254
To activate DataLoader for a resolver, simply add `dataLoader: true` to the resolver's property object in the `resolvers` property of the service's `graphql` property:
255255

256256
```js
257-
settings: {
258-
graphql: {
259-
resolvers: {
260-
Post: {
261-
author: {
262-
action: "users.resolve",
263-
dataLoader: true,
264-
rootParams: {
265-
author: "id",
257+
module.exports = {
258+
settings: {
259+
graphql: {
260+
resolvers: {
261+
Post: {
262+
author: {
263+
action: "users.resolve",
264+
dataLoader: true,
265+
rootParams: {
266+
author: "id",
267+
},
266268
},
267-
},
268-
voters: {
269-
action: "users.resolve",
270-
dataLoader: true,
271-
rootParams: {
272-
voters: "id",
269+
voters: {
270+
action: "users.resolve",
271+
dataLoader: true,
272+
rootParams: {
273+
voters: "id",
274+
},
273275
},
274-
},
275-
...
276+
// ...
277+
}
278+
}
279+
}
280+
}
281+
};
276282
```
277283
Since DataLoader only expects a single value to be loaded at a time, only one `rootParams` key/value pairing will be utilized, but `params` and GraphQL child arguments work properly.
278284

@@ -305,6 +311,8 @@ It is unlikely that setting any of the options which accept a function will work
305311
- [Full With Dataloader](examples/full/index.js)
306312
- set `DATALOADER` environment variable to `"true"`
307313
- `npm run dev full`
314+
- [Typescript](test/typescript/index.ts)
315+
- `npm run test:ts`
308316

309317
## Test
310318
```

examples/full/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ broker.createService({
6363
mappingPolicy: "restrict"
6464
},
6565

66-
// https://www.apollographql.com/docs/apollo-server/v2/api/apollo-server.html
66+
// https://www.apollographql.com/docs/apollo-server/api/apollo-server#options
6767
serverOptions: {
6868
tracing: false,
6969

examples/simple/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ broker.createService({
3434

3535
checkActionVisibility: true,
3636

37-
// https://www.apollographql.com/docs/apollo-server/v2/api/apollo-server.html
37+
// https://www.apollographql.com/docs/apollo-server/api/apollo-server#options
3838
serverOptions: {}
3939
})
4040
],
4141

4242
events: {
43-
"graphql.schema.updated"({ schema }) {
44-
this.logger.info("Generated GraphQL schema:\n\n" + schema);
43+
"graphql.schema.updated"(ctx) {
44+
this.logger.info("Generated GraphQL schema:\n\n" + ctx.params.schema);
4545
}
4646
}
4747
});

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ declare module "moleculer-apollo-server" {
7878
}
7979

8080
export interface ApolloMixinOptions {
81-
serverOptions?: BaseApolloServerOptions<BaseContext> & {
81+
serverOptions?: Partial<BaseApolloServerOptions<BaseContext>> & {
8282
subscriptions?: boolean | WsServerOptions;
8383
};
8484
routeOptions?: ApiRouteSchema;

0 commit comments

Comments
 (0)