Skip to content

[federation] default to Federation v2 #1585

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
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -69,7 +69,7 @@ import kotlin.reflect.full.findAnnotation
*/
open class FederatedSchemaGeneratorHooks(
private val resolvers: List<FederatedTypeResolver>,
private val optInFederationV2: Boolean = false
private val optInFederationV2: Boolean = true
) : SchemaGeneratorHooks {
private val validator = FederatedSchemaValidator()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class FederatedSchemaGeneratorTest {

val config = FederatedSchemaGeneratorConfig(
supportedPackages = listOf("com.expediagroup.graphql.generator.federation.data.queries.federated.v1"),
hooks = FederatedSchemaGeneratorHooks(emptyList())
hooks = FederatedSchemaGeneratorHooks(emptyList(), optInFederationV2 = false)
)

val schema = toFederatedSchema(config = config)
Expand Down Expand Up @@ -212,7 +212,7 @@ class FederatedSchemaGeneratorTest {

val config = FederatedSchemaGeneratorConfig(
supportedPackages = listOf("com.expediagroup.graphql.generator.federation.data.queries.simple"),
hooks = FederatedSchemaGeneratorHooks(emptyList())
hooks = FederatedSchemaGeneratorHooks(emptyList(), optInFederationV2 = false)
)

val schema = toFederatedSchema(config, listOf(TopLevelObject(SimpleQuery())))
Expand Down Expand Up @@ -248,7 +248,7 @@ class FederatedSchemaGeneratorTest {

val config = FederatedSchemaGeneratorConfig(
supportedPackages = listOf("com.expediagroup.graphql.generator.federation.data.queries.simple"),
hooks = FederatedSchemaGeneratorHooks(emptyList())
hooks = FederatedSchemaGeneratorHooks(emptyList(), optInFederationV2 = false)
)

val schema = toFederatedSchema(config, listOf(TopLevelObject(NestedQuery())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,42 @@ scalar CustomScalar"""

const val BASE_SERVICE_SDL =
"""
schema {
schema @link(import : ["extends", "external", "inaccessible", "key", "override", "provides", "requires", "shareable", "tag", "FieldSet"], url : "https://specs.apollo.dev/federation/v2.0"){
query: Query
}

"Marks target object as extending part of the federated schema"
directive @extends on OBJECT | INTERFACE

"Marks target field as external meaning it will be resolved by federated schema"
directive @external on FIELD_DEFINITION

"Marks location within schema as inaccessible from the GraphQL Gateway"
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"Space separated list of primary keys needed to access federated object"
directive @key(fields: FieldSet!) repeatable on OBJECT | INTERFACE

"Links definitions within the document to external schemas."
directive @link(import: [String], url: String) repeatable on SCHEMA

"Overrides fields resolution logic from other subgraph. Used for migrating fields from one subgraph to another."
directive @override(from: String!) on FIELD_DEFINITION

"Specifies the base type field set that will be selectable by the gateway"
directive @provides(fields: FieldSet!) on FIELD_DEFINITION

"Specifies required input field set from the base type for a resolver"
directive @requires(fields: FieldSet!) on FIELD_DEFINITION

"Indicates that given object and/or field can be resolved by multiple subgraphs"
directive @shareable on OBJECT | FIELD_DEFINITION

"Allows users to annotate fields and types with additional metadata information"
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

type Query @extends {
_service: _Service!
getSimpleNestedObject: [SelfReferenceObject]!
hello(name: String!): String!
}
Expand All @@ -100,6 +131,13 @@ type SelfReferenceObject {
id: Int!
nextObject: [SelfReferenceObject]!
}

type _Service {
sdl: String!
}

"Federation type representing set of fields"
scalar FieldSet
"""

const val FEDERATED_SERVICE_SDL_V2 =
Expand Down Expand Up @@ -197,7 +235,7 @@ scalar _Any

class ServiceQueryResolverTest {

class CustomScalarFederatedHooks : FederatedSchemaGeneratorHooks(emptyList()) {
class CustomScalarFederatedHooks : FederatedSchemaGeneratorHooks(emptyList(), optInFederationV2 = false) {
override fun willGenerateGraphQLType(type: KType): GraphQLType? = when (type.classifier as? KClass<*>) {
CustomScalar::class -> graphqlCustomScalar
else -> super.willGenerateGraphQLType(type)
Expand Down Expand Up @@ -290,7 +328,7 @@ class ServiceQueryResolverTest {
fun `verify can retrieve Federation v2 SDL using _service query`() {
val config = FederatedSchemaGeneratorConfig(
supportedPackages = listOf("com.expediagroup.graphql.generator.federation.data.queries.federated.v2"),
hooks = FederatedSchemaGeneratorHooks(emptyList(), optInFederationV2 = true)
hooks = FederatedSchemaGeneratorHooks(emptyList())
)

val schema = toFederatedSchema(config = config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ class GraphQLGradlePluginIT : GraphQLGradlePluginAbstractIT() {

val expectedFederatedSchemaWithCustomScalar =
"""
schema {
schema @link(import : ["extends", "external", "inaccessible", "key", "override", "provides", "requires", "shareable", "tag", "FieldSet"], url : "https://specs.apollo.dev/federation/v2.0"){
query: Query
}

Expand All @@ -532,20 +532,32 @@ class GraphQLGradlePluginIT : GraphQLGradlePluginAbstractIT() {
"Marks target field as external meaning it will be resolved by federated schema"
directive @external on FIELD_DEFINITION

"Marks location within schema as inaccessible from the GraphQL Gateway"
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"Directs the executor to include this field or fragment only when the `if` argument is true"
directive @include(
"Included when true."
if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"Space separated list of primary keys needed to access federated object"
directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
directive @key(fields: FieldSet!) repeatable on OBJECT | INTERFACE

"Links definitions within the document to external schemas."
directive @link(import: [String], url: String) repeatable on SCHEMA

"Overrides fields resolution logic from other subgraph. Used for migrating fields from one subgraph to another."
directive @override(from: String!) on FIELD_DEFINITION

"Specifies the base type field set that will be selectable by the gateway"
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION

"Specifies required input field set from the base type for a resolver"
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @requires(fields: FieldSet!) on FIELD_DEFINITION

"Indicates that given object and/or field can be resolved by multiple subgraphs"
directive @shareable on OBJECT | FIELD_DEFINITION

"Directs the executor to skip this field or fragment when the `if` argument is true."
directive @skip(
Expand All @@ -559,6 +571,9 @@ class GraphQLGradlePluginIT : GraphQLGradlePluginAbstractIT() {
url: String!
) on SCALAR

"Allows users to annotate fields and types with additional metadata information"
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

type Query @extends {
_service: _Service!
helloWorld(name: String): String!
Expand All @@ -569,11 +584,11 @@ class GraphQLGradlePluginIT : GraphQLGradlePluginAbstractIT() {
sdl: String!
}

"Federation type representing set of fields"
scalar FieldSet

"Custom scalar representing UUID"
scalar UUID

"Federation type representing set of fields"
scalar _FieldSet
""".trimIndent()
val buildFileContents =
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal val DEFAULT_SCHEMA =

internal val FEDERATED_SCHEMA =
"""
schema {
schema @link(import : ["extends", "external", "inaccessible", "key", "override", "provides", "requires", "shareable", "tag", "FieldSet"], url : "https://specs.apollo.dev/federation/v2.0"){
query: Query
}

Expand All @@ -81,20 +81,32 @@ internal val FEDERATED_SCHEMA =
"Marks target field as external meaning it will be resolved by federated schema"
directive @external on FIELD_DEFINITION

"Marks location within schema as inaccessible from the GraphQL Gateway"
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"Directs the executor to include this field or fragment only when the `if` argument is true"
directive @include(
"Included when true."
if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"Space separated list of primary keys needed to access federated object"
directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
directive @key(fields: FieldSet!) repeatable on OBJECT | INTERFACE

"Links definitions within the document to external schemas."
directive @link(import: [String], url: String) repeatable on SCHEMA

"Overrides fields resolution logic from other subgraph. Used for migrating fields from one subgraph to another."
directive @override(from: String!) on FIELD_DEFINITION

"Specifies the base type field set that will be selectable by the gateway"
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION

"Specifies required input field set from the base type for a resolver"
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @requires(fields: FieldSet!) on FIELD_DEFINITION

"Indicates that given object and/or field can be resolved by multiple subgraphs"
directive @shareable on OBJECT | FIELD_DEFINITION

"Directs the executor to skip this field or fragment when the `if` argument is true."
directive @skip(
Expand All @@ -108,6 +120,9 @@ internal val FEDERATED_SCHEMA =
url: String!
) on SCALAR

"Allows users to annotate fields and types with additional metadata information"
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

type Query @extends {
_service: _Service!
helloWorld(name: String): String!
Expand All @@ -118,7 +133,7 @@ internal val FEDERATED_SCHEMA =
}

"Federation type representing set of fields"
scalar _FieldSet
scalar FieldSet
""".trimIndent()

class GraphQLGenerateSDLTaskIT : GraphQLGradlePluginAbstractIT() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class GenerateSDLMojoTest {
assertTrue(schemaFile.exists(), "schema file was generated")

val expectedSchema = """
schema {
schema @link(import : ["extends", "external", "inaccessible", "key", "override", "provides", "requires", "shareable", "tag", "FieldSet"], url : "https://specs.apollo.dev/federation/v2.0"){
query: Query
}

Expand All @@ -52,20 +52,32 @@ class GenerateSDLMojoTest {
"Marks target field as external meaning it will be resolved by federated schema"
directive @external on FIELD_DEFINITION

"Marks location within schema as inaccessible from the GraphQL Gateway"
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"Directs the executor to include this field or fragment only when the `if` argument is true"
directive @include(
"Included when true."
if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"Space separated list of primary keys needed to access federated object"
directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
directive @key(fields: FieldSet!) repeatable on OBJECT | INTERFACE

"Links definitions within the document to external schemas."
directive @link(import: [String], url: String) repeatable on SCHEMA

"Overrides fields resolution logic from other subgraph. Used for migrating fields from one subgraph to another."
directive @override(from: String!) on FIELD_DEFINITION

"Specifies the base type field set that will be selectable by the gateway"
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION

"Specifies required input field set from the base type for a resolver"
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @requires(fields: FieldSet!) on FIELD_DEFINITION

"Indicates that given object and/or field can be resolved by multiple subgraphs"
directive @shareable on OBJECT | FIELD_DEFINITION

"Directs the executor to skip this field or fragment when the `if` argument is true."
directive @skip(
Expand All @@ -79,6 +91,9 @@ class GenerateSDLMojoTest {
url: String!
) on SCALAR

"Allows users to annotate fields and types with additional metadata information"
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

type Query @extends {
_service: _Service!
helloWorld(name: String): String!
Expand All @@ -89,7 +104,7 @@ class GenerateSDLMojoTest {
}

"Federation type representing set of fields"
scalar _FieldSet
scalar FieldSet
""".trimIndent()
assertEquals(expectedSchema, schemaFile.readText().trim())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class GenerateSDLMojoTest {
assertTrue(schemaFile.exists(), "schema file was generated")

val expectedSchema = """
schema {
schema @link(import : ["extends", "external", "inaccessible", "key", "override", "provides", "requires", "shareable", "tag", "FieldSet"], url : "https://specs.apollo.dev/federation/v2.0"){
query: Query
}

Expand All @@ -52,20 +52,32 @@ class GenerateSDLMojoTest {
"Marks target field as external meaning it will be resolved by federated schema"
directive @external on FIELD_DEFINITION

"Marks location within schema as inaccessible from the GraphQL Gateway"
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"Directs the executor to include this field or fragment only when the `if` argument is true"
directive @include(
"Included when true."
if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"Space separated list of primary keys needed to access federated object"
directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
directive @key(fields: FieldSet!) repeatable on OBJECT | INTERFACE

"Links definitions within the document to external schemas."
directive @link(import: [String], url: String) repeatable on SCHEMA

"Overrides fields resolution logic from other subgraph. Used for migrating fields from one subgraph to another."
directive @override(from: String!) on FIELD_DEFINITION

"Specifies the base type field set that will be selectable by the gateway"
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION

"Specifies required input field set from the base type for a resolver"
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @requires(fields: FieldSet!) on FIELD_DEFINITION

"Indicates that given object and/or field can be resolved by multiple subgraphs"
directive @shareable on OBJECT | FIELD_DEFINITION

"Directs the executor to skip this field or fragment when the `if` argument is true."
directive @skip(
Expand All @@ -79,6 +91,9 @@ class GenerateSDLMojoTest {
url: String!
) on SCALAR

"Allows users to annotate fields and types with additional metadata information"
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

type Query @extends {
_service: _Service!
helloWorld(name: String): String!
Expand All @@ -89,11 +104,11 @@ class GenerateSDLMojoTest {
sdl: String!
}

"Federation type representing set of fields"
scalar FieldSet

"Custom scalar representing UUID"
scalar UUID

"Federation type representing set of fields"
scalar _FieldSet
""".trimIndent()
assertEquals(expectedSchema, schemaFile.readText().trim())
}
Expand Down
Loading