Skip to content

Commit 84f0f92

Browse files
authored
Fix 2nd step introspection (#5451)
1 parent cd59ca7 commit 84f0f92

File tree

6 files changed

+25
-47
lines changed

6 files changed

+25
-47
lines changed

libraries/apollo-tooling/src/main/kotlin/com/apollographql/apollo3/tooling/SchemaHelper.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.apollographql.apollo3.api.http.HttpBody
66
import com.apollographql.apollo3.api.http.HttpHeader
77
import com.apollographql.apollo3.api.http.HttpMethod
88
import com.apollographql.apollo3.api.http.HttpRequest
9+
import com.apollographql.apollo3.api.json.buildJsonString
10+
import com.apollographql.apollo3.api.json.writeObject
911
import com.apollographql.apollo3.ast.GQLArgument
1012
import com.apollographql.apollo3.ast.GQLBooleanValue
1113
import com.apollographql.apollo3.ast.GQLDefinition
@@ -99,7 +101,13 @@ internal object SchemaHelper {
99101
headers: Map<String, String>,
100102
insecure: Boolean,
101103
): String {
102-
return fetch(ByteStringHttpBody("application/json", introspectionQuery), endpoint, headers, insecure)
104+
val jsonBody = buildJsonString {
105+
writeObject {
106+
name("operationName").value("IntrospectionQuery")
107+
name("query").value(introspectionQuery)
108+
}
109+
}
110+
return fetch(ByteStringHttpBody("application/json", jsonBody), endpoint, headers, insecure)
103111
}
104112

105113
internal fun List<GQLDefinition>.reworkIntrospectionQuery(features: Set<GraphQLFeature>) =
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"operationName":"IntrospectionQuery","query":"query IntrospectionQuery {\n __schema {\n queryType {\n name\n }\n mutationType {\n name\n }\n subscriptionType {\n name\n }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args(includeDeprecated: true) {\n ...InputValue\n }\n isRepeatable\n }\n description\n }\n}\n\nfragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args(includeDeprecated: true) {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields(includeDeprecated: true) {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n specifiedByURL\n}\n\nfragment InputValue on __InputValue {\n name\n description\n type {\n ...TypeRef\n }\n defaultValue\n isDeprecated\n deprecationReason\n}\n\nfragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n}\n"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"operationName":"IntrospectionQuery","query":"query IntrospectionQuery {\n __schema {\n queryType {\n name\n }\n mutationType {\n name\n }\n subscriptionType {\n name\n }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args {\n ...InputValue\n }\n }\n }\n}\n\nfragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n}\n\nfragment InputValue on __InputValue {\n name\n description\n type {\n ...TypeRef\n }\n defaultValue\n}\n\nfragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n}\n"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"operationName":"IntrospectionQuery","query":"query IntrospectionQuery {\n __schema {\n queryType {\n name\n }\n mutationType {\n name\n }\n subscriptionType {\n name\n }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args {\n ...InputValue\n }\n isRepeatable\n }\n description\n }\n}\n\nfragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n specifiedByURL\n}\n\nfragment InputValue on __InputValue {\n name\n description\n type {\n ...TypeRef\n }\n defaultValue\n}\n\nfragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n}\n"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"operationName":"IntrospectionQuery","query":"query IntrospectionQuery {\n __schema {\n queryType {\n name\n }\n mutationType {\n name\n }\n subscriptionType {\n name\n }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args(includeDeprecated: true) {\n ...InputValue\n }\n isRepeatable\n }\n description\n }\n}\n\nfragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args(includeDeprecated: true) {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields(includeDeprecated: true) {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n specifiedByURL\n isOneOf\n}\n\nfragment InputValue on __InputValue {\n name\n description\n type {\n ...TypeRef\n }\n defaultValue\n isDeprecated\n deprecationReason\n}\n\nfragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n}\n"}

libraries/apollo-tooling/src/test/kotlin/com/apollographql/apollo3/tooling/SchemaDownloaderTests.kt

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ import com.apollographql.apollo3.mockserver.enqueueString
55
import com.apollographql.apollo3.testing.internal.runTest
66
import com.apollographql.apollo3.testing.pathToUtf8
77
import org.junit.Assert.assertEquals
8-
import org.junit.Assert.assertFalse
9-
import org.junit.Assert.assertTrue
108
import org.junit.Test
119
import java.io.File
1210

1311
private val preIntrospectionResponseJune2018 = pathToUtf8("apollo-tooling/src/test/fixtures/pre-introspection-response-june2018.json")
12+
private val introspectionRequestJune2018 = pathToUtf8("apollo-tooling/src/test/fixtures/introspection-request-june2018.json")
1413

1514
private val preIntrospectionResponseOctober2021 = pathToUtf8("apollo-tooling/src/test/fixtures/pre-introspection-response-october2021.json")
15+
private val introspectionRequestOctober2021 = pathToUtf8("apollo-tooling/src/test/fixtures/introspection-request-october2021.json")
1616

1717
private val preIntrospectionResponseDraft = pathToUtf8("apollo-tooling/src/test/fixtures/pre-introspection-response-draft.json")
18+
private val introspectionRequestDraft = pathToUtf8("apollo-tooling/src/test/fixtures/introspection-request-draft.json")
1819

1920
private val preIntrospectionResponseOneOf = pathToUtf8("apollo-tooling/src/test/fixtures/pre-introspection-response-oneOf.json")
21+
private val introspectionRequestOneOf = pathToUtf8("apollo-tooling/src/test/fixtures/introspection-request-oneOf.json")
2022

2123
private val introspectionResponse = pathToUtf8("apollo-tooling/src/test/fixtures/introspection-response.json")
2224

@@ -48,17 +50,8 @@ class SchemaDownloaderTests {
4850
)
4951

5052
mockServer.takeRequest()
51-
mockServer.takeRequest().body.utf8().let {
52-
assertFalse(it.contains(Regex("}\\s+description\\s+}\\s+}")))
53-
assertFalse(it.contains("specifiedByURL"))
54-
assertFalse(it.contains("isRepeatable"))
55-
assertFalse(it.contains("inputFields(includeDeprecated: true)"))
56-
assertFalse(it.contains(Regex("directives\\s+\\{\\s+name\\s+description\\s+locations\\s+args\\(includeDeprecated: true\\)")))
57-
assertFalse(it.contains(Regex("fields\\(includeDeprecated: true\\)\\s+\\{\\s+name\\s+description\\s+args\\(includeDeprecated: true\\)")))
58-
assertFalse(it.substringAfter("fragment InputValue on __InputValue {").contains("isDeprecated"))
59-
assertFalse(it.substringAfter("fragment InputValue on __InputValue {").contains("deprecationReason"))
60-
assertFalse(it.contains("isOneOf"))
61-
}
53+
val introspectionRequest = mockServer.takeRequest().body.utf8()
54+
assertEquals(introspectionRequestJune2018, introspectionRequest)
6255
assertEquals(introspectionResponse, tempFile.readText())
6356
}
6457

@@ -76,17 +69,8 @@ class SchemaDownloaderTests {
7669
)
7770

7871
mockServer.takeRequest()
79-
mockServer.takeRequest().body.utf8().let {
80-
assertTrue(it.contains(Regex("}\\s+description\\s+}\\s+}")))
81-
assertTrue(it.contains("specifiedByURL"))
82-
assertTrue(it.contains("isRepeatable"))
83-
assertFalse(it.contains("inputFields(includeDeprecated: true)"))
84-
assertFalse(it.contains(Regex("directives\\s+\\{\\s+name\\s+description\\s+locations\\s+args\\(includeDeprecated: true\\)")))
85-
assertFalse(it.contains(Regex("fields\\(includeDeprecated: true\\)\\s+\\{\\s+name\\s+description\\s+args\\(includeDeprecated: true\\)")))
86-
assertFalse(it.substringAfter("fragment InputValue on __InputValue {").contains("isDeprecated"))
87-
assertFalse(it.substringAfter("fragment InputValue on __InputValue {").contains("deprecationReason"))
88-
assertFalse(it.contains("isOneOf"))
89-
}
72+
val introspectionRequest = mockServer.takeRequest().body.utf8()
73+
assertEquals(introspectionRequestOctober2021, introspectionRequest)
9074
assertEquals(introspectionResponse, tempFile.readText())
9175
}
9276

@@ -104,17 +88,8 @@ class SchemaDownloaderTests {
10488
)
10589

10690
mockServer.takeRequest()
107-
mockServer.takeRequest().body.utf8().let {
108-
assertTrue(it.contains(Regex("}\\s+description\\s+}\\s+}")))
109-
assertTrue(it.contains("specifiedByURL"))
110-
assertTrue(it.contains("isRepeatable"))
111-
assertTrue(it.contains("inputFields(includeDeprecated: true)"))
112-
assertTrue(it.contains(Regex("directives\\s+\\{\\s+name\\s+description\\s+locations\\s+args\\(includeDeprecated: true\\)")))
113-
assertTrue(it.contains(Regex("fields\\(includeDeprecated: true\\)\\s+\\{\\s+name\\s+description\\s+args\\(includeDeprecated: true\\)")))
114-
assertTrue(it.substringAfter("fragment InputValue on __InputValue {").contains("isDeprecated"))
115-
assertTrue(it.substringAfter("fragment InputValue on __InputValue {").contains("deprecationReason"))
116-
assertFalse(it.contains("isOneOf"))
117-
}
91+
val introspectionRequest = mockServer.takeRequest().body.utf8()
92+
assertEquals(introspectionRequestDraft, introspectionRequest)
11893
assertEquals(introspectionResponse, tempFile.readText())
11994
}
12095

@@ -132,17 +107,8 @@ class SchemaDownloaderTests {
132107
)
133108

134109
mockServer.takeRequest()
135-
mockServer.takeRequest().body.utf8().let {
136-
assertTrue(it.contains(Regex("}\\s+description\\s+}\\s+}")))
137-
assertTrue(it.contains("specifiedByURL"))
138-
assertTrue(it.contains("isRepeatable"))
139-
assertTrue(it.contains("inputFields(includeDeprecated: true)"))
140-
assertTrue(it.contains(Regex("directives\\s+\\{\\s+name\\s+description\\s+locations\\s+args\\(includeDeprecated: true\\)")))
141-
assertTrue(it.contains(Regex("fields\\(includeDeprecated: true\\)\\s+\\{\\s+name\\s+description\\s+args\\(includeDeprecated: true\\)")))
142-
assertTrue(it.substringAfter("fragment InputValue on __InputValue {").contains("isDeprecated"))
143-
assertTrue(it.substringAfter("fragment InputValue on __InputValue {").contains("deprecationReason"))
144-
assertTrue(it.contains("isOneOf"))
145-
}
110+
val introspectionRequest = mockServer.takeRequest().body.utf8()
111+
assertEquals(introspectionRequestOneOf, introspectionRequest)
146112
assertEquals(introspectionResponse, tempFile.readText())
147113
}
148114
}

0 commit comments

Comments
 (0)