Skip to content

[4.x] Add back a test + tweak a function name + tweak API stability #6551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class EntryPoints {
).writeTo(outputDir, true, metadataOutputFile)

if (upstreamCodegenMetadata.isEmpty()) {
registry.extraCodeGenerator().generate(codegenSchema.schema.toGQLDocument(), outputDir)
registry.schemaCodeGenerator().generate(codegenSchema.schema.toGQLDocument(), outputDir)
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ class EntryPoints {
operationManifestFile = operationManifestFile,
).writeTo(outputDir, true, null)

registry.extraCodeGenerator().generate(codegenSchema.schema.toGQLDocument(), outputDir)
registry.schemaCodeGenerator().generate(codegenSchema.schema.toGQLDocument(), outputDir)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ internal class DefaultApolloCompilerRegistry : ApolloCompilerRegistry {
}
}

fun extraCodeGenerator(): SchemaCodeGenerator {
fun schemaCodeGenerator(): SchemaCodeGenerator {
return SchemaCodeGenerator { document, outputDirectory ->
extraSchemaCodeGenerators.forEach {
it.generate(document, outputDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,49 @@ package com.apollographql.apollo.compiler.keyfields

import com.apollographql.apollo.ast.GQLDocument
import com.apollographql.apollo.ast.GQLExecutableDefinition
import com.apollographql.apollo.ast.GQLFragmentDefinition
import com.apollographql.apollo.ast.GQLOperationDefinition
import com.apollographql.apollo.ast.parseAsGQLDocument
import com.apollographql.apollo.ast.toGQLDocument
import com.apollographql.apollo.ast.validateAsSchemaAndAddApolloDefinition
import com.apollographql.apollo.compiler.internal.ApolloExecutableDocumentTransform
import com.apollographql.apollo.compiler.internal.checkKeyFields
import okio.Path.Companion.toPath
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.fail

class KeyFieldsTest {
@Test
fun testAddRequiredFields() {
val schema = "src/test/kotlin/com/apollographql/apollo/compiler/keyfields/schema.graphqls"
.toPath()
.toGQLDocument()
.validateAsSchemaAndAddApolloDefinition()
.getOrThrow()

val document = "src/test/kotlin/com/apollographql/apollo/compiler/keyfields/operations.graphql".toPath()
.toGQLDocument()
val definitions = document.definitions

val operation = definitions
.filterIsInstance<GQLOperationDefinition>()
.first()

try {
checkKeyFields(operation, schema, emptyMap())
fail("an exception was expected")
} catch (e: Exception) {
assertTrue(e.message?.contains("are not queried") == true)
}

// The document contains a single operation
val operationWithKeyFields = ApolloExecutableDocumentTransform("ifFragments", true).transform(schema, document, emptyList()).definitions.single() as GQLOperationDefinition
checkKeyFields(operationWithKeyFields, schema, emptyMap())
}

@Test
fun testExtendInterfaceTypePolicyDirective() {
val schema = "src/test/kotlin/com/apollographql/apollo/compiler/keyfields/extendsSchema.graphqls"
Expand Down
Loading