Skip to content

Commit

Permalink
exclude empty keyfields
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed May 26, 2022
1 parent 2187cce commit 270491e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ private fun SchemaValidationScope.keyFields(
}

val interfacesKeyFields = interfaces.map { keyFields(allTypeDefinition[it]!!, allTypeDefinition, keyFieldsCache) }
.filter { it.isNotEmpty() }

val distinct = interfacesKeyFields.distinct()
if (distinct.size > 1) {
val extra = interfaces.indices.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.junit.Test
import java.io.File
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class KeyFieldsTest {
@Test
Expand Down Expand Up @@ -87,4 +88,12 @@ class KeyFieldsTest {
)
assertEquals(13, issue.sourceLocation.line)
}

@Test
fun testInterfacesWithoutKeyFields() {
val doc = File("src/test/kotlin/com/apollographql/apollo3/compiler/keyfields/interfacesWithoutKeyFields.graphqls")
.toSchemaGQLDocument()
.withApolloDefinitions()
assertTrue(doc.validateAsSchema().issues.isEmpty())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type Query {
book: Book!
}

interface Node @typePolicy(keyFields: "id") {
id: String!
}

interface Product {
upc: String!
}

type Book implements Node & Product{
id: String!
upc: String!
title: String!
}

0 comments on commit 270491e

Please sign in to comment.