@@ -108,82 +108,94 @@ internal object SchemaHelper {
108108 }
109109
110110 internal fun List<GQLDefinition>.reworkIntrospectionQuery (features : Set <GraphQLFeature >) =
111- mapIf<_ , GQLOperationDefinition >({ it.name == " IntrospectionQuery" }) {
112- it.copy(
113- selections = it.selections
114- // Add __schema { description }
115- .mapIf(SchemaDescription in features) { schemaField ->
116- schemaField as GQLField
117- schemaField.copy(
118- selections = schemaField.selections + createField(" description" )
119- )
120- }
121- // Add __schema { directives { isRepeatable } }
122- .mapIf(RepeatableDirectives in features) { schemaField ->
123- schemaField as GQLField
124- schemaField.copy(
125- selections = schemaField.selections.mapIf<_ , GQLField >({ it.name == " directives" }) { directivesField ->
126- directivesField.copy(selections = directivesField.selections + createField(" isRepeatable" ))
127- }
128- )
129- }
130- // Replace __schema { directives { args { ... } } } by __schema { directives { args(includeDeprecated: true) { ... } } }
131- .mapIf(DeprecatedInputValues in features) { schemaField ->
132- schemaField as GQLField
133- schemaField.copy(
134- selections = schemaField.selections.mapIf<_ , GQLField >({ it.name == " directives" }) { directivesField ->
135- directivesField.copy(
136- selections = directivesField.selections.mapIf<_ , GQLField >({ it.name == " args" }) { argsField ->
137- argsField.copy(arguments = listOf (GQLArgument (name = " includeDeprecated" , value = GQLBooleanValue (value = true ))))
138- }
139- )
140- }
141- )
142- }
143- )
144- }
111+ mapIf<_ , GQLOperationDefinition >({ it.name == " IntrospectionQuery" }) {
112+ it.copy(
113+ selections = it.selections
114+ // Add __schema { description }
115+ .mapIf(SchemaDescription in features) { schemaField ->
116+ schemaField as GQLField
117+ schemaField.copy(
118+ selections = schemaField.selections + createField(" description" )
119+ )
120+ }
121+ // Add __schema { directives { isRepeatable } }
122+ .mapIf(RepeatableDirectives in features) { schemaField ->
123+ schemaField as GQLField
124+ schemaField.copy(
125+ selections = schemaField.selections.mapIf<_ , GQLField >({ it.name == " directives" }) { directivesField ->
126+ directivesField.copy(selections = directivesField.selections + createField(" isRepeatable" ))
127+ }
128+ )
129+ }
130+ // Add __schema { directives(includeDeprecated: true) { isDeprecated deprecationReason } }
131+ .mapIf(DeprecatedDirectives in features) { schemaField ->
132+ schemaField as GQLField
133+ schemaField.copy(
134+ selections = schemaField.selections.mapIf<_ , GQLField >({ it.name == " directives" }) { directivesField ->
135+ directivesField.copy(
136+ arguments = listOf (GQLArgument (name = " includeDeprecated" , value = GQLBooleanValue (value = true ))),
137+ selections = directivesField.selections + createField(" isDeprecated" ) + createField(" deprecationReason" )
138+ )
139+ }
140+ )
141+ }
142+ // Replace __schema { directives { args { ... } } } by __schema { directives { args(includeDeprecated: true) { ... } } }
143+ .mapIf(DeprecatedInputValues in features) { schemaField ->
144+ schemaField as GQLField
145+ schemaField.copy(
146+ selections = schemaField.selections.mapIf<_ , GQLField >({ it.name == " directives" }) { directivesField ->
147+ directivesField.copy(
148+ selections = directivesField.selections.mapIf<_ , GQLField >({ it.name == " args" }) { argsField ->
149+ argsField.copy(arguments = listOf (GQLArgument (name = " includeDeprecated" , value = GQLBooleanValue (value = true ))))
150+ }
151+ )
152+ }
153+ )
154+ }
155+ )
156+ }
145157
146158 internal fun List<GQLDefinition>.reworkFullTypeFragment (features : Set <GraphQLFeature >) =
147- mapIf<_ , GQLFragmentDefinition >({ it.name == " FullType" }) {
148- it.copy(
149- selections = it.selections
150- // Add specifiedByUrl
151- .letIf(SpecifiedBy in features) { fields ->
152- fields + createField(" specifiedByURL" )
153- }
154- // Add isOneOf
155- .letIf(OneOf in features) { fields ->
156- fields + createField(" isOneOf" )
157- }
158- // Replace inputFields { ... } by inputFields(includeDeprecated: true) { ... }
159- .mapIf<_ , GQLField >({ DeprecatedInputValues in features && it.name == " inputFields" }) { inputFieldsField ->
160- inputFieldsField.copy(arguments = listOf (GQLArgument (name = " includeDeprecated" , value = GQLBooleanValue (value = true ))))
161- }
162- // Replace fields { args { ... } } by fields { args(includeDeprecated: true) { ... } }
163- .mapIf<_ , GQLField >({ DeprecatedInputValues in features && it.name == " fields" }) { fieldsField ->
164- fieldsField.copy(
165- selections = fieldsField.selections.mapIf<_ , GQLField >({ it.name == " args" }) { argsField ->
166- argsField.copy(arguments = listOf (GQLArgument (name = " includeDeprecated" , value = GQLBooleanValue (value = true ))))
167- }
168- )
169- }
170- )
171- }
159+ mapIf<_ , GQLFragmentDefinition >({ it.name == " FullType" }) {
160+ it.copy(
161+ selections = it.selections
162+ // Add specifiedByUrl
163+ .letIf(SpecifiedBy in features) { fields ->
164+ fields + createField(" specifiedByURL" )
165+ }
166+ // Add isOneOf
167+ .letIf(OneOf in features) { fields ->
168+ fields + createField(" isOneOf" )
169+ }
170+ // Replace inputFields { ... } by inputFields(includeDeprecated: true) { ... }
171+ .mapIf<_ , GQLField >({ DeprecatedInputValues in features && it.name == " inputFields" }) { inputFieldsField ->
172+ inputFieldsField.copy(arguments = listOf (GQLArgument (name = " includeDeprecated" , value = GQLBooleanValue (value = true ))))
173+ }
174+ // Replace fields { args { ... } } by fields { args(includeDeprecated: true) { ... } }
175+ .mapIf<_ , GQLField >({ DeprecatedInputValues in features && it.name == " fields" }) { fieldsField ->
176+ fieldsField.copy(
177+ selections = fieldsField.selections.mapIf<_ , GQLField >({ it.name == " args" }) { argsField ->
178+ argsField.copy(arguments = listOf (GQLArgument (name = " includeDeprecated" , value = GQLBooleanValue (value = true ))))
179+ }
180+ )
181+ }
182+ )
183+ }
172184
173185 internal fun List<GQLDefinition>.reworkInputValueFragment (features : Set <GraphQLFeature >) =
174- mapIf<_ , GQLFragmentDefinition >({ it.name == " InputValue" }) {
175- it.copy(
176- selections = it.selections
177- // Add isDeprecated
178- .letIf(DeprecatedInputValues in features) { fields ->
179- fields + createField(" isDeprecated" )
180- }
181- // Add deprecationReason
182- .letIf(DeprecatedInputValues in features) { fields ->
183- fields + createField(" deprecationReason" )
184- }
185- )
186- }
186+ mapIf<_ , GQLFragmentDefinition >({ it.name == " InputValue" }) {
187+ it.copy(
188+ selections = it.selections
189+ // Add isDeprecated
190+ .letIf(DeprecatedInputValues in features) { fields ->
191+ fields + createField(" isDeprecated" )
192+ }
193+ // Add deprecationReason
194+ .letIf(DeprecatedInputValues in features) { fields ->
195+ fields + createField(" deprecationReason" )
196+ }
197+ )
198+ }
187199
188200 private inline fun <T > T.letIf (condition : Boolean , block : (T ) -> T ): T = if (condition) block(this ) else this
189201
@@ -194,7 +206,8 @@ internal object SchemaHelper {
194206 block : (E ) -> E ,
195207 ): List <T > = map { if (it is E && condition(it)) block(it) else it }
196208
197- private fun createField (name : String ) = GQLField (alias = null , name = name, arguments = emptyList(), directives = emptyList(), selections = emptyList())
209+ private fun createField (name : String ) =
210+ GQLField (alias = null , name = name, arguments = emptyList(), directives = emptyList(), selections = emptyList())
198211
199212 private fun OkHttpClient.Builder.applyInsecureTrustManager () = apply {
200213 val insecureTrustManager = InsecureTrustManager ()
0 commit comments