-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
apollo-compiler/src/test/graphql/com/example/deeply_nested_fragments/TestOperation.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
query query1 { | ||
a { | ||
...aFragment | ||
} | ||
} | ||
|
||
query query2 { | ||
a { | ||
...aFragment | ||
} | ||
} | ||
|
||
query query3 { | ||
a { | ||
...aFragment | ||
} | ||
} | ||
|
||
query query4 { | ||
a { | ||
...aFragment | ||
} | ||
} | ||
|
||
query query5 { | ||
a { | ||
...aFragment | ||
} | ||
} | ||
|
||
|
||
|
||
fragment aFragment on A { | ||
b { | ||
...bFragment | ||
} | ||
} | ||
|
||
fragment bFragment on B { | ||
c { | ||
...cFragment | ||
} | ||
} | ||
|
||
fragment cFragment on C { | ||
d { | ||
...dFragment | ||
} | ||
} | ||
|
||
fragment dFragment on D { | ||
e { | ||
...eFragment | ||
} | ||
} | ||
|
||
fragment eFragment on E { | ||
f { | ||
...fFragment | ||
} | ||
} | ||
|
||
fragment fFragment on F { | ||
g { | ||
...gFragment | ||
} | ||
} | ||
|
||
fragment gFragment on G { | ||
h { | ||
...hFragment | ||
} | ||
} | ||
|
||
fragment hFragment on H { | ||
i { | ||
...iFragment | ||
} | ||
} | ||
|
||
fragment iFragment on I { | ||
j { | ||
...jFragment | ||
} | ||
} | ||
|
||
fragment jFragment on J { | ||
k { | ||
...kFragment | ||
} | ||
} | ||
|
||
fragment kFragment on K { | ||
l { | ||
...lFragment | ||
} | ||
} | ||
|
||
fragment lFragment on L { | ||
m { | ||
...mFragment | ||
} | ||
} | ||
|
||
fragment mFragment on M { | ||
n { | ||
...nFragment | ||
} | ||
} | ||
|
||
fragment nFragment on N { | ||
o { | ||
...oFragment | ||
} | ||
} | ||
|
||
fragment oFragment on O { | ||
x | ||
y | ||
} |
127 changes: 127 additions & 0 deletions
127
apollo-compiler/src/test/graphql/com/example/deeply_nested_fragments/schema.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
type Query { | ||
a: A! | ||
} | ||
|
||
|
||
interface A { | ||
b: B! | ||
} | ||
|
||
type A1 implements A { | ||
b: B! | ||
} | ||
|
||
interface B { | ||
c: C! | ||
} | ||
|
||
type B1 implements B { | ||
c: C! | ||
} | ||
|
||
interface C { | ||
d: D! | ||
} | ||
|
||
type C1 implements C { | ||
d: D! | ||
} | ||
|
||
interface D { | ||
e: E! | ||
} | ||
|
||
type D1 implements D { | ||
e: E! | ||
} | ||
|
||
interface E { | ||
f: F! | ||
} | ||
|
||
type E1 implements E { | ||
f: F! | ||
} | ||
|
||
interface F { | ||
g: G! | ||
} | ||
|
||
type F1 implements F { | ||
g: G! | ||
} | ||
|
||
interface G { | ||
h: H! | ||
} | ||
|
||
type G1 implements G { | ||
h: H! | ||
} | ||
|
||
interface H { | ||
i: I! | ||
} | ||
|
||
type H1 implements H { | ||
i: I! | ||
} | ||
|
||
interface I { | ||
j: J! | ||
} | ||
|
||
type I1 implements I { | ||
j: J! | ||
} | ||
|
||
interface J { | ||
k: K! | ||
} | ||
|
||
type J1 implements J { | ||
k: K! | ||
} | ||
|
||
interface K { | ||
l: L! | ||
} | ||
|
||
type K1 implements K { | ||
l: L! | ||
} | ||
|
||
interface L { | ||
m: M! | ||
} | ||
|
||
type L1 implements L { | ||
m: M! | ||
} | ||
|
||
interface M { | ||
n: N! | ||
} | ||
|
||
type M1 implements M { | ||
n: N! | ||
} | ||
|
||
interface N { | ||
o: O! | ||
} | ||
|
||
type N1 implements N { | ||
o: O! | ||
} | ||
|
||
|
||
interface O { | ||
x: Int! | ||
y: Int! | ||
} | ||
|
||
type O1 implements O @typePolicy(keyFields: "x") { | ||
x: Int! | ||
y: Int! | ||
} |
102 changes: 102 additions & 0 deletions
102
apollo-compiler/src/test/kotlin/com/apollographql/apollo3/compiler/PerfTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.apollographql.apollo3.compiler | ||
|
||
import com.apollographql.apollo3.annotations.ApolloExperimental | ||
import com.apollographql.apollo3.compiler.TargetLanguage.KOTLIN_1_5 | ||
import com.apollographql.apollo3.compiler.TestUtils.checkTestFixture | ||
import org.junit.Test | ||
import java.io.File | ||
import kotlin.time.ExperimentalTime | ||
import kotlin.time.measureTime | ||
|
||
@OptIn(ExperimentalTime::class, ApolloExperimental::class) | ||
class PerfTest { | ||
@Test | ||
fun generateExpectedClasses() { | ||
val folder = File("src/test/graphql/com/example/deeply_nested_fragments") | ||
val options = options(folder, MODELS_RESPONSE_BASED) | ||
options.outputDir.deleteRecursively() | ||
val repeat = 1 | ||
|
||
val codegenDuration = measureTime { | ||
repeat(repeat) { | ||
ApolloCompiler.write(options) | ||
} | ||
} | ||
println("codegenDuration=$codegenDuration.") | ||
|
||
// checkOutput(folder, options.outputDir) | ||
// // Check that generated sources compile | ||
// val compileDuration = measureTime { | ||
// KotlinCompiler.assertCompiles(actualFiles.toSet(), false) | ||
// } | ||
} | ||
|
||
private fun checkOutput(folder: File, outputDir: File, codegenModels: String) { | ||
val expectedRoot = folder.resolve("kotlin/$codegenModels") | ||
// Because codegen will put files under a given packageName, we skip the first 2 folders | ||
val actualRoot = outputDir.resolve("com/example") | ||
|
||
val actualFiles = actualRoot.walk().filter { | ||
it.isFile | ||
} | ||
|
||
val expectedFiles = expectedRoot.walk().filter { | ||
it.isFile && it.extension == "expected" | ||
} | ||
|
||
expectedFiles.forEach { expected -> | ||
val relativePath = expected.relativeTo(expectedRoot).path.removeSuffix(".expected") | ||
val actual = actualRoot.resolve(relativePath) | ||
if (!actual.exists()) { | ||
throw Exception("No actual file for ${actual.absolutePath}") | ||
} | ||
|
||
// Do not generate a diff everytime the version changes | ||
actual.replaceVersionWithPlaceHolder() | ||
checkTestFixture(actual = actual, expected = expected) | ||
} | ||
|
||
actualFiles.forEach { actual -> | ||
val relativePath = actual.relativeTo(actualRoot).path | ||
val expected = expectedRoot.resolve("$relativePath.expected") | ||
if (!expected.exists()) { | ||
throw Exception("No expected file at ${expected.absolutePath}") | ||
} | ||
// no need to call checkTestFixture again, this has been taken care of | ||
} | ||
} | ||
|
||
private fun File.replaceVersionWithPlaceHolder() { | ||
writeText( | ||
readText().replace( | ||
"This class was automatically generated by Apollo GraphQL version '$APOLLO_VERSION'", | ||
"This class was automatically generated by Apollo GraphQL version '${'$'}VERSION'" | ||
) | ||
) | ||
} | ||
|
||
companion object { | ||
|
||
private fun options(folder: File, codegenModels: String): Options { | ||
val schemaFile = folder.listFiles()!!.find { it.isFile && (it.name == "schema.sdl" || it.name == "schema.json" || it.name == "schema.graphqls") } | ||
?: File("src/test/graphql/schema.sdl") | ||
|
||
val graphqlFiles = setOf(File(folder, "TestOperation.graphql")) | ||
|
||
return Options( | ||
executableFiles = graphqlFiles, | ||
schemaFile = schemaFile, | ||
outputDir = File("build/generated/test/${folder.name}/kotlin/$codegenModels/"), | ||
packageName = "com.example.${folder.name}" | ||
).copy( | ||
codegenModels = codegenModels, | ||
generateFragmentImplementations = true, | ||
generateFilterNotNull = true, | ||
moduleName = folder.name, | ||
flattenModels = false, | ||
targetLanguage = KOTLIN_1_5, | ||
useSemanticNaming = false | ||
) | ||
} | ||
} | ||
} |