@@ -11,11 +11,17 @@ export function transformSchema(
11
11
additionalModules : ( GraphQLModule | Module ) [ ] = [ ] ,
12
12
{ generateOpaqueTypes } : { generateOpaqueTypes ?: boolean } = { } ,
13
13
) {
14
+ const postTransformers : GraphQLModule [ "postTransform" ] [ ] = [ ] ;
14
15
const modules = [ CoreSync ( ) , ...additionalModules ] ;
15
16
const directiveMappers : Record < string , FieldDirectiveMapper > = { } ;
16
17
const typeDefs : DocumentNode [ ] = modules . flatMap ( ( m ) => {
17
- const { module : gqlModule , mappers = { } } = "id" in m ? { module : m } : m ;
18
+ const {
19
+ module : gqlModule ,
20
+ mappers = { } ,
21
+ postTransform = undefined ,
22
+ } = "id" in m ? { module : m } : m ;
18
23
const documents = gqlModule . typeDefs ;
24
+ postTransformers . push ( postTransform ) ;
19
25
documents . forEach ( ( document ) => {
20
26
document . definitions . forEach ( ( definition ) => {
21
27
if ( definition . kind !== Kind . DIRECTIVE_DEFINITION ) return ;
@@ -36,10 +42,15 @@ export function transformSchema(
36
42
generateOpaqueTypes,
37
43
} ) ;
38
44
39
- const errors = validateSchema ( schema ) ;
45
+ const postSchema = postTransformers . reduce (
46
+ ( s , transform ) => transform ?.( s ) ?? s ,
47
+ schema ,
48
+ ) ;
49
+
50
+ const errors = validateSchema ( postSchema ) ;
40
51
41
52
if ( errors . length > 0 ) {
42
53
throw new Error ( errors . map ( ( e ) => e . message ) . join ( "\n" ) ) ;
43
54
}
44
- return schema ;
55
+ return postSchema ;
45
56
}
0 commit comments