@@ -17,7 +17,7 @@ import {
1717
1818import { cloneSubschemaConfig , SubschemaConfig , MergedTypeConfig , MergedFieldConfig } from '@graphql-tools/delegate' ;
1919import {
20- getDirectives ,
20+ getDirective ,
2121 getImplementingTypes ,
2222 MapperKind ,
2323 mapSchema ,
@@ -73,45 +73,48 @@ export function stitchingDirectivesTransformer(
7373
7474 mapSchema ( schema , {
7575 [ MapperKind . OBJECT_TYPE ] : type => {
76- const directives = getDirectives ( schema , type , pathToDirectivesInExtensions ) ;
77-
78- if ( keyDirectiveName != null && directives [ keyDirectiveName ] != null ) {
79- const keyDirective = directives [ keyDirectiveName ] ;
80- const selectionSet = parseSelectionSet ( keyDirective . selectionSet , { noLocation : true } ) ;
76+ const keyDirective = getDirective ( schema , type , keyDirectiveName , pathToDirectivesInExtensions ) ?. [ 0 ] ;
77+ if ( keyDirective != null ) {
78+ const selectionSet = parseSelectionSet ( keyDirective [ 'selectionSet' ] , { noLocation : true } ) ;
8179 selectionSetsByType [ type . name ] = selectionSet ;
8280 }
8381
84- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] ) {
82+ const canonicalDirective = getDirective (
83+ schema ,
84+ type ,
85+ canonicalDirectiveName ,
86+ pathToDirectivesInExtensions
87+ ) ?. [ 0 ] ;
88+ if ( canonicalDirective != null ) {
8589 setCanonicalDefinition ( type . name ) ;
8690 }
87-
8891 return undefined ;
8992 } ,
9093 [ MapperKind . OBJECT_FIELD ] : ( fieldConfig , fieldName , typeName ) => {
91- const directives = getDirectives ( schema , fieldConfig , pathToDirectivesInExtensions ) ;
92-
93- if ( computedDirectiveName != null && directives [ computedDirectiveName ] != null ) {
94- const computedDirective = directives [ computedDirectiveName ] ;
95- const selectionSet = parseSelectionSet ( computedDirective . selectionSet , { noLocation : true } ) ;
94+ const computedDirective = getDirective (
95+ schema ,
96+ fieldConfig ,
97+ computedDirectiveName ,
98+ pathToDirectivesInExtensions
99+ ) ?. [ 0 ] ;
100+ if ( computedDirective != null ) {
101+ const selectionSet = parseSelectionSet ( computedDirective [ 'selectionSet' ] , { noLocation : true } ) ;
96102 if ( ! computedFieldSelectionSets [ typeName ] ) {
97103 computedFieldSelectionSets [ typeName ] = Object . create ( null ) ;
98104 }
99105 computedFieldSelectionSets [ typeName ] [ fieldName ] = selectionSet ;
100106 }
101107
102- if (
103- mergeDirectiveName != null &&
104- directives [ mergeDirectiveName ] != null &&
105- directives [ mergeDirectiveName ] . keyField
106- ) {
107- const mergeDirectiveKeyField = directives [ mergeDirectiveName ] . keyField ;
108+ const mergeDirective = getDirective ( schema , fieldConfig , mergeDirectiveName , pathToDirectivesInExtensions ) ?. [ 0 ] ;
109+ if ( mergeDirective ?. [ 'keyField' ] != null ) {
110+ const mergeDirectiveKeyField = mergeDirective [ 'keyField' ] ;
108111 const selectionSet = parseSelectionSet ( `{ ${ mergeDirectiveKeyField } }` , { noLocation : true } ) ;
109112
110- const typeNames : Array < string > = directives [ mergeDirectiveName ] . types ;
113+ const typeNames : Array < string > = mergeDirective [ ' types' ] ;
111114
112115 const returnType = getNamedType ( fieldConfig . type ) ;
113116
114- forEachConcreteType ( schema , returnType , directives [ mergeDirectiveName ] ?. types , typeName => {
117+ forEachConcreteType ( schema , returnType , typeNames , typeName => {
115118 if ( typeNames == null || typeNames . includes ( typeName ) ) {
116119 const existingSelectionSet = selectionSetsByType [ typeName ] ;
117120 selectionSetsByType [ typeName ] = existingSelectionSet
@@ -121,70 +124,111 @@ export function stitchingDirectivesTransformer(
121124 } ) ;
122125 }
123126
124- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] != null ) {
127+ const canonicalDirective = getDirective (
128+ schema ,
129+ fieldConfig ,
130+ canonicalDirectiveName ,
131+ pathToDirectivesInExtensions
132+ ) ?. [ 0 ] ;
133+ if ( canonicalDirective != null ) {
125134 setCanonicalDefinition ( typeName , fieldName ) ;
126135 }
127136
128137 return undefined ;
129138 } ,
130139 [ MapperKind . INTERFACE_TYPE ] : type => {
131- const directives = getDirectives ( schema , type , pathToDirectivesInExtensions ) ;
132-
133- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] != null ) {
140+ const canonicalDirective = getDirective (
141+ schema ,
142+ type ,
143+ canonicalDirectiveName ,
144+ pathToDirectivesInExtensions
145+ ) ?. [ 0 ] ;
146+
147+ if ( canonicalDirective ) {
134148 setCanonicalDefinition ( type . name ) ;
135149 }
136150
137151 return undefined ;
138152 } ,
139153 [ MapperKind . INTERFACE_FIELD ] : ( fieldConfig , fieldName , typeName ) => {
140- const directives = getDirectives ( schema , fieldConfig , pathToDirectivesInExtensions ) ;
141-
142- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] ) {
154+ const canonicalDirective = getDirective (
155+ schema ,
156+ fieldConfig ,
157+ canonicalDirectiveName ,
158+ pathToDirectivesInExtensions
159+ ) ?. [ 0 ] ;
160+
161+ if ( canonicalDirective ) {
143162 setCanonicalDefinition ( typeName , fieldName ) ;
144163 }
145164
146165 return undefined ;
147166 } ,
148167 [ MapperKind . INPUT_OBJECT_TYPE ] : type => {
149- const directives = getDirectives ( schema , type , pathToDirectivesInExtensions ) ;
150-
151- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] != null ) {
168+ const canonicalDirective = getDirective (
169+ schema ,
170+ type ,
171+ canonicalDirectiveName ,
172+ pathToDirectivesInExtensions
173+ ) ?. [ 0 ] ;
174+
175+ if ( canonicalDirective ) {
152176 setCanonicalDefinition ( type . name ) ;
153177 }
154178
155179 return undefined ;
156180 } ,
157181 [ MapperKind . INPUT_OBJECT_FIELD ] : ( inputFieldConfig , fieldName , typeName ) => {
158- const directives = getDirectives ( schema , inputFieldConfig , pathToDirectivesInExtensions ) ;
159-
160- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] != null ) {
182+ const canonicalDirective = getDirective (
183+ schema ,
184+ inputFieldConfig ,
185+ canonicalDirectiveName ,
186+ pathToDirectivesInExtensions
187+ ) ?. [ 0 ] ;
188+
189+ if ( canonicalDirective != null ) {
161190 setCanonicalDefinition ( typeName , fieldName ) ;
162191 }
163192
164193 return undefined ;
165194 } ,
166195 [ MapperKind . UNION_TYPE ] : type => {
167- const directives = getDirectives ( schema , type , pathToDirectivesInExtensions ) ;
168-
169- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] != null ) {
196+ const canonicalDirective = getDirective (
197+ schema ,
198+ type ,
199+ canonicalDirectiveName ,
200+ pathToDirectivesInExtensions
201+ ) ?. [ 0 ] ;
202+
203+ if ( canonicalDirective != null ) {
170204 setCanonicalDefinition ( type . name ) ;
171205 }
172206
173207 return undefined ;
174208 } ,
175209 [ MapperKind . ENUM_TYPE ] : type => {
176- const directives = getDirectives ( schema , type , pathToDirectivesInExtensions ) ;
177-
178- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] != null ) {
210+ const canonicalDirective = getDirective (
211+ schema ,
212+ type ,
213+ canonicalDirectiveName ,
214+ pathToDirectivesInExtensions
215+ ) ?. [ 0 ] ;
216+
217+ if ( canonicalDirective != null ) {
179218 setCanonicalDefinition ( type . name ) ;
180219 }
181220
182221 return undefined ;
183222 } ,
184223 [ MapperKind . SCALAR_TYPE ] : type => {
185- const directives = getDirectives ( schema , type , pathToDirectivesInExtensions ) ;
186-
187- if ( canonicalDirectiveName != null && directives [ canonicalDirectiveName ] != null ) {
224+ const canonicalDirective = getDirective (
225+ schema ,
226+ type ,
227+ canonicalDirectiveName ,
228+ pathToDirectivesInExtensions
229+ ) ?. [ 0 ] ;
230+
231+ if ( canonicalDirective != null ) {
188232 setCanonicalDefinition ( type . name ) ;
189233 }
190234
@@ -248,23 +292,21 @@ export function stitchingDirectivesTransformer(
248292
249293 mapSchema ( schema , {
250294 [ MapperKind . OBJECT_FIELD ] : ( fieldConfig , fieldName ) => {
251- const directives = getDirectives ( schema , fieldConfig , pathToDirectivesInExtensions ) ;
252-
253- if ( mergeDirectiveName != null && directives [ mergeDirectiveName ] != null ) {
254- const directiveArgumentMap = directives [ mergeDirectiveName ] ;
295+ const mergeDirective = getDirective ( schema , fieldConfig , mergeDirectiveName , pathToDirectivesInExtensions ) ?. [ 0 ] ;
255296
297+ if ( mergeDirective != null ) {
256298 const returnType = getNullableType ( fieldConfig . type ) ;
257299 const returnsList = isListType ( returnType ) ;
258300 const namedType = getNamedType ( returnType ) ;
259301
260- let mergeArgsExpr : string = directiveArgumentMap . argsExpr ;
302+ let mergeArgsExpr : string = mergeDirective [ ' argsExpr' ] ;
261303
262304 if ( mergeArgsExpr == null ) {
263- const key : Array < string > = directiveArgumentMap . key ;
264- const keyField : string = directiveArgumentMap . keyField ;
305+ const key : Array < string > = mergeDirective [ ' key' ] ;
306+ const keyField : string = mergeDirective [ ' keyField' ] ;
265307 const keyExpr = key != null ? buildKeyExpr ( key ) : keyField != null ? `$key.${ keyField } ` : '$key' ;
266308
267- const keyArg : string = directiveArgumentMap . keyArg ;
309+ const keyArg : string = mergeDirective [ ' keyArg' ] ;
268310 const argNames = keyArg == null ? [ Object . keys ( fieldConfig . args ?? { } ) [ 0 ] ] : keyArg . split ( '.' ) ;
269311
270312 const lastArgName = argNames . pop ( ) ;
@@ -275,7 +317,7 @@ export function stitchingDirectivesTransformer(
275317 }
276318 }
277319
278- const typeNames : Array < string > = directiveArgumentMap . types ;
320+ const typeNames : Array < string > = mergeDirective [ ' types' ] ;
279321
280322 forEachConcreteTypeName ( namedType , schema , typeNames , typeName => {
281323 const parsedMergeArgsExpr = parseMergeArgsExpr (
@@ -285,7 +327,7 @@ export function stitchingDirectivesTransformer(
285327 : mergeSelectionSets ( ...allSelectionSetsByType [ typeName ] )
286328 ) ;
287329
288- const additionalArgs = directiveArgumentMap . additionalArgs ;
330+ const additionalArgs = mergeDirective [ ' additionalArgs' ] ;
289331 if ( additionalArgs != null ) {
290332 parsedMergeArgsExpr . args = mergeDeep (
291333 parsedMergeArgsExpr . args ,
0 commit comments