File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed
packages/apollo-graphql/src/schema Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 17
17
- ` apollo-env `
18
18
- <First ` apollo-env ` related entry goes here>
19
19
- ` apollo-graphql `
20
- - <First ` apollo-graphql ` related entry goes here>
20
+ - Complex directive arguments don't break ` transformSchema ` (Fixes # 2162 )
21
21
- ` apollo-language-server `
22
22
- <First ` apollo-language-server ` related entry goes here>
23
23
- ` apollo-tools `
Original file line number Diff line number Diff line change
1
+ import { buildSchema , printSchema } from "graphql" ;
2
+ import { transformSchema } from "../transformSchema" ;
3
+
4
+ describe ( "transformSchema" , ( ) => {
5
+ test ( "no-op transform leaves types untouched" , ( ) => {
6
+ const schema = buildSchema ( `#graphql
7
+ type Query {
8
+ foo: String @test(baz: { bar: "hello" })
9
+ }
10
+
11
+ input DirectiveArg {
12
+ bar: String
13
+ }
14
+
15
+ # https://github.com/apollographql/apollo-tooling/issues/2162
16
+ directive @test(baz: DirectiveArg) on FIELD_DEFINITION
17
+ ` ) ;
18
+
19
+ const newSchema = transformSchema ( schema , namedType => namedType ) ;
20
+
21
+ expect ( printSchema ( newSchema ) ) . toEqual ( printSchema ( schema ) ) ;
22
+ } ) ;
23
+ } ) ;
Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ import {
19
19
GraphQLUnionType ,
20
20
isInputObjectType ,
21
21
GraphQLInputObjectType ,
22
- GraphQLInputFieldConfigMap
22
+ GraphQLInputFieldConfigMap ,
23
+ GraphQLDirective
23
24
} from "graphql" ;
24
25
import { mapValues } from "../utilities/mapValues" ;
25
26
@@ -53,7 +54,8 @@ export function transformSchema(
53
54
types : Object . values ( typeMap ) ,
54
55
query : replaceMaybeType ( schemaConfig . query ) ,
55
56
mutation : replaceMaybeType ( schemaConfig . mutation ) ,
56
- subscription : replaceMaybeType ( schemaConfig . subscription )
57
+ subscription : replaceMaybeType ( schemaConfig . subscription ) ,
58
+ directives : replaceDirectives ( schemaConfig . directives )
57
59
} ) ;
58
60
59
61
function recreateNamedType ( type : GraphQLNamedType ) : GraphQLNamedType {
@@ -145,4 +147,14 @@ export function transformSchema(
145
147
type : replaceType ( arg . type )
146
148
} ) ) ;
147
149
}
150
+
151
+ function replaceDirectives ( directives : GraphQLDirective [ ] ) {
152
+ return directives . map ( directive => {
153
+ const config = directive . toConfig ( ) ;
154
+ return new GraphQLDirective ( {
155
+ ...config ,
156
+ args : replaceArgs ( config . args )
157
+ } ) ;
158
+ } ) ;
159
+ }
148
160
}
You can’t perform that action at this time.
0 commit comments