Skip to content

Commit 2809bae

Browse files
authored
graphql: override validate function for compatibility with class-validator (#396)
1 parent 4741786 commit 2809bae

File tree

7 files changed

+124
-69
lines changed

7 files changed

+124
-69
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@subsquid/graphql-server",
5+
"comment": "override validate function to make it compatible with the latest class-validator package",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@subsquid/graphql-server"
10+
}

common/config/rush/pnpm-lock.yaml

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graphql/graphql-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"peerDependencies": {
5050
"@subsquid/big-decimal": "^1.0.0",
51-
"class-validator": "^0.14.0",
51+
"class-validator": "^0.14.2",
5252
"type-graphql": "^1.2.0-rc.1",
5353
"typeorm": "^0.3.17"
5454
},

graphql/graphql-server/src/resolvers.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {GraphQLSchema} from 'graphql'
22
import {buildSchema, ContainerType, ResolverData} from 'type-graphql'
3+
import {validateSync} from 'class-validator'
34
import type {EntityManager} from 'typeorm'
45
import {BigDecimalScalar, BigInteger, Bytes, DateTime} from './scalars'
56
import {TypeormOpenreaderContext} from './typeorm'
@@ -23,9 +24,14 @@ export async function loadCustomResolvers(mod: string): Promise<GraphQLSchema> {
2324
resolvers: [mod],
2425
scalarsMap,
2526
container: resolverData => new CustomResolversContainer(resolverData),
26-
validate: {
27-
forbidUnknownValues: false
28-
}
27+
validate: ((argValue) => {
28+
const errors = validateSync(argValue!, {
29+
forbidUnknownValues: false
30+
});
31+
if (errors.length) {
32+
throw errors[0];
33+
}
34+
})
2935
})
3036
}
3137

graphql/graphql-server/src/test/resolvers-extension/lib/server-extension/resolvers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,11 @@ export class PingPong {
6767
return msg
6868
}
6969
}
70+
71+
@Resolver()
72+
export class ArgResolver {
73+
@Query(() => Boolean, { nullable: false })
74+
stringArray(@Arg('ids', () => [String]) ids: string[]): boolean {
75+
return true
76+
}
77+
}

0 commit comments

Comments
 (0)