File tree Expand file tree Collapse file tree
packages/apollo-graphql/src/schema Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717- ` apollo-env `
1818 - <First ` apollo-env ` related entry goes here>
1919- ` apollo-graphql `
20- - <First ` apollo-graphql ` related entry goes here>
20+ - Complex directive arguments don't break ` transformSchema ` (Fixes # 2162 )
2121- ` apollo-language-server `
2222 - <First ` apollo-language-server ` related entry goes here>
2323- ` 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+ debugger ;
20+ const newSchema = transformSchema ( schema , namedType => namedType ) ;
21+
22+ expect ( printSchema ( newSchema ) ) . toEqual ( printSchema ( schema ) ) ;
23+ } ) ;
24+ } ) ;
Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ import {
1919 GraphQLUnionType ,
2020 isInputObjectType ,
2121 GraphQLInputObjectType ,
22- GraphQLInputFieldConfigMap
22+ GraphQLInputFieldConfigMap ,
23+ GraphQLDirective
2324} from "graphql" ;
2425import { mapValues } from "../utilities/mapValues" ;
2526
@@ -53,7 +54,8 @@ export function transformSchema(
5354 types : Object . values ( typeMap ) ,
5455 query : replaceMaybeType ( schemaConfig . query ) ,
5556 mutation : replaceMaybeType ( schemaConfig . mutation ) ,
56- subscription : replaceMaybeType ( schemaConfig . subscription )
57+ subscription : replaceMaybeType ( schemaConfig . subscription ) ,
58+ directives : replaceDirectives ( schemaConfig . directives )
5759 } ) ;
5860
5961 function recreateNamedType ( type : GraphQLNamedType ) : GraphQLNamedType {
@@ -145,4 +147,14 @@ export function transformSchema(
145147 type : replaceType ( arg . type )
146148 } ) ) ;
147149 }
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+ }
148160}
You can’t perform that action at this time.
0 commit comments