Skip to content

Commit c5594c2

Browse files
dariuszkuctapaderster
authored andcommitted
federation: add tests to verify custom directive support (ExpediaGroup#388)
1 parent 5ed8bc3 commit c5594c2

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

graphql-kotlin-federation/src/main/kotlin/com/expediagroup/graphql/federation/FederatedSchemaGeneratorHooks.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import kotlin.reflect.full.findAnnotation
4343
*/
4444
open class FederatedSchemaGeneratorHooks(private val federatedTypeRegistry: FederatedTypeRegistry) : SchemaGeneratorHooks {
4545
private val directiveDefinitionRegex = "(^#.+$[\\r\\n])?^directive @\\w+.+$[\\r\\n]*".toRegex(setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE))
46-
private val customDirectivesRegex = "@(?!extends)(?!external)(?!key)(?!provides)(?!requires)(?!deprecated)\\w+(?:\\(.*(?=\\))\\))?".toRegex(setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE))
46+
private val customDirectivesRegex = "\\s*@(?!extends)(?!external)(?!key)(?!provides)(?!requires)(?!deprecated)\\w+(?:\\(.*(?=\\))\\))?".toRegex(
47+
setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE))
4748
private val scalarDefinitionRegex = "(^#.+$[\\r\\n])?^scalar (_FieldSet|_Any)$[\\r\\n]*".toRegex(setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE))
4849
private val emptyQueryRegex = "^type Query \\{$\\s+^\\}$\\s+".toRegex(setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE))
4950
private val validator = FederatedSchemaValidator()

graphql-kotlin-federation/src/test/kotlin/com/expediagroup/graphql/federation/FederatedSchemaGeneratorTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ directive @extends on OBJECT | INTERFACE
4040
#Specifies the base type field set that will be selectable by the gateway
4141
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
4242
43+
directive @custom on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
44+
4345
#Space separated list of primary keys needed to access federated object
4446
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE
4547
@@ -68,7 +70,8 @@ type Query @extends {
6870
}
6971
7072
type Review {
71-
body: String!
73+
body: String! @custom
74+
content: String @deprecated(reason : "no longer supported, replace with use Review.body instead")
7275
id: String!
7376
}
7477

graphql-kotlin-federation/src/test/kotlin/com/expediagroup/graphql/federation/execution/ServiceQueryResolverTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Book implements Product @extends @key(fields : "id") {
4242
4343
type Review {
4444
body: String!
45+
content: String @deprecated(reason : "no longer supported, replace with use Review.body instead")
4546
id: String!
4647
}
4748

graphql-kotlin-federation/src/test/kotlin/test/data/queries/federated/Product.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package test.data.queries.federated
1818

19+
import com.expediagroup.graphql.annotations.GraphQLDirective
1920
import com.expediagroup.graphql.annotations.GraphQLIgnore
2021
import com.expediagroup.graphql.federation.directives.ExtendsDirective
2122
import com.expediagroup.graphql.federation.directives.ExternalDirective
@@ -94,7 +95,11 @@ type Review {
9495
id: String!
9596
}
9697
*/
97-
data class Review(val id: String, val body: String)
98+
data class Review(
99+
val id: String,
100+
@CustomDirective val body: String,
101+
@Deprecated(message = "no longer supported", replaceWith = ReplaceWith("use Review.body instead")) val content: String? = null
102+
)
98103

99104
/*
100105
type User {
@@ -108,3 +113,6 @@ data class User(
108113
@ExternalDirective val userId: Int,
109114
@ExternalDirective val name: String
110115
)
116+
117+
@GraphQLDirective(name = "custom")
118+
annotation class CustomDirective

0 commit comments

Comments
 (0)