|
| 1 | +@file:Suppress("MethodOverloading") |
1 | 2 | /*
|
2 | 3 | * Copyright 2019 Expedia, Inc
|
3 | 4 | *
|
@@ -27,9 +28,11 @@ import com.expediagroup.graphql.federation.directives.KeyDirective
|
27 | 28 | import com.expediagroup.graphql.federation.directives.ProvidesDirective
|
28 | 29 | import com.expediagroup.graphql.federation.exception.InvalidFederatedSchema
|
29 | 30 | import graphql.schema.GraphQLObjectType
|
| 31 | +import graphql.schema.GraphQLTypeReference |
30 | 32 | import graphql.schema.GraphQLTypeUtil
|
31 | 33 | import io.mockk.mockk
|
32 | 34 | import org.junit.jupiter.api.BeforeEach
|
| 35 | +import org.junit.jupiter.api.Test |
33 | 36 | import org.junit.jupiter.api.TestInstance
|
34 | 37 | import org.junit.jupiter.params.ParameterizedTest
|
35 | 38 | import org.junit.jupiter.params.provider.Arguments
|
@@ -99,6 +102,27 @@ class FederatedSchemaValidatorProvidesDirectiveTest {
|
99 | 102 | }
|
100 | 103 | }
|
101 | 104 |
|
| 105 | + @Test |
| 106 | + fun `validated nested relationship with @provide directive`() { |
| 107 | + // order of object instantiation matters |
| 108 | + // - BUG #397 - typeA -> typeB with provides (apply validation) -> reference typeA |
| 109 | + // - NO ISSUE - typeB with provides -> typeA (no validation) -> reference typeB |
| 110 | + val validatedType = schemaGenerator.objectType(NestedProvidedType::class) as? GraphQLObjectType |
| 111 | + assertNotNull(validatedType) |
| 112 | + assertEquals(NestedProvidedType::class.simpleName, validatedType.name) |
| 113 | + validator.validateGraphQLType(validatedType) |
| 114 | + assertNotNull(validatedType.getDirective("key")) |
| 115 | + |
| 116 | + val typeWithProvides = schemaGenerator.objectType(NestedProvides::class) as? GraphQLObjectType |
| 117 | + assertNotNull(typeWithProvides) |
| 118 | + validator.validateGraphQLType(typeWithProvides) |
| 119 | + val providedField = typeWithProvides.getFieldDefinition("provided") |
| 120 | + assertNotNull(providedField) |
| 121 | + assertNotNull(providedField.getDirective("provides")) |
| 122 | + val providedType = GraphQLTypeUtil.unwrapType(providedField.type).last() as? GraphQLTypeReference |
| 123 | + assertNotNull(providedType) |
| 124 | + } |
| 125 | + |
102 | 126 | // ======================= TEST DATA ===========
|
103 | 127 | /*
|
104 | 128 | type SimpleProvides @key(fields : "id") {
|
@@ -276,4 +300,33 @@ class FederatedSchemaValidatorProvidesDirectiveTest {
|
276 | 300 | @ExternalDirective val id: String,
|
277 | 301 | @ExternalDirective val data: ProvidedInterface = throw UnsupportedOperationException("not implemented")
|
278 | 302 | )
|
| 303 | + |
| 304 | + /* |
| 305 | + type NestedProvidedType @extends @key(fields : "id") { |
| 306 | + id: String! @external |
| 307 | + nested: NestedProvides! |
| 308 | + text: String! @external |
| 309 | + } |
| 310 | +
|
| 311 | + type NestedProvides @key(fields : "id") { |
| 312 | + description: String! |
| 313 | + id: String! |
| 314 | + provided: NestedProvidedType! @provides(fields : "text") |
| 315 | + } |
| 316 | + */ |
| 317 | + @KeyDirective(fields = FieldSet("id")) |
| 318 | + private class NestedProvides(val id: String, val description: String) { |
| 319 | + |
| 320 | + @ProvidesDirective(fields = FieldSet("text")) |
| 321 | + fun provided() = NestedProvidedType(id, "some text") |
| 322 | + } |
| 323 | + |
| 324 | + @KeyDirective(fields = FieldSet("id")) |
| 325 | + @ExtendsDirective |
| 326 | + private class NestedProvidedType( |
| 327 | + @ExternalDirective val id: String, |
| 328 | + @ExternalDirective val text: String |
| 329 | + ) { |
| 330 | + fun nested(): NestedProvides = NestedProvides("123", "some description") |
| 331 | + } |
279 | 332 | }
|
0 commit comments