Skip to content

Implementing federation spec #280

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 5 commits into from
Aug 12, 2019
Merged

Conversation

dariuszkuc
Copy link
Collaborator

@dariuszkuc dariuszkuc commented Jul 25, 2019

Create new graphql-kotlin-federation module that extends graphql-kotlin-schema-generator to generate federated GraphQL schemas. Federated GraphQL architecture is an alternative to schema stitching approach that relies on declarative programming composition of schemas.

graphql-kotlin-federation adds support for the following:

  • new @key, @extends, @external, @requires and @provides directives
  • new _FieldSet and _Any scalar types
  • new _Entity union type of all federated types
  • new _service query that returns _Service object with sdl field
  • new _entity query that returns list of _Entity objects

In order to generate federate schemas we have to annotate the underlying type with proper new directives and then use new toFederatedSchema function to build the schema (instead of toSchema function from graphql-kotlin-schema-generator). FederatedSchemaGeneratorHooks also require to specify FederatedTypeRegistry that holds a mapping between federated type names and their corresponding resolver. Those new FederatedTypeResolvers are used to instantiate the federated types based on the federated _entity query generated from the gateway.

See: https://www.apollographql.com/docs/apollo-server/federation/introduction/

Resolves: #238

@dariuszkuc dariuszkuc force-pushed the federation branch 2 times, most recently from f5fac85 to b175ada Compare August 3, 2019 04:43
@codecov
Copy link

codecov bot commented Aug 3, 2019

Codecov Report

Merging #280 into master will increase coverage by 3.58%.
The diff coverage is 86.99%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #280      +/-   ##
============================================
+ Coverage     64.56%   68.15%   +3.58%     
- Complexity      194      263      +69     
============================================
  Files           103      115      +12     
  Lines          1064     1275     +211     
  Branches        152      196      +44     
============================================
+ Hits            687      869     +182     
- Misses          363      385      +22     
- Partials         14       21       +7
Impacted Files Coverage Δ Complexity Δ
...or/src/main/kotlin/com/expedia/graphql/toSchema.kt 100% <ø> (ø) 0 <0> (ø) ⬇️
...om/expedia/graphql/generator/types/QueryBuilder.kt 100% <ø> (ø) 4 <0> (-1) ⬇️
...xpedia/graphql/generator/types/InterfaceBuilder.kt 100% <ø> (ø) 2 <0> (ø) ⬇️
...in/com/expedia/graphql/federation/types/_Entity.kt 100% <100%> (ø) 0 <0> (?)
...dia/graphql/federation/FederatedSchemaGenerator.kt 100% <100%> (ø) 4 <4> (?)
...xpedia/graphql/federation/FederatedTypeRegistry.kt 100% <100%> (ø) 2 <2> (?)
.../expedia/graphql/federation/FederationException.kt 100% <100%> (ø) 1 <1> (?)
...n/com/expedia/graphql/federation/types/_Service.kt 100% <100%> (ø) 1 <1> (?)
...aphql/federation/FederatedSchemaGeneratorConfig.kt 100% <100%> (ø) 5 <5> (?)
...pedia/graphql/federation/InvalidFederatedSchema.kt 100% <100%> (ø) 1 <1> (?)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39c023f...e7e5de1. Read the comment docs.

@dariuszkuc dariuszkuc marked this pull request as ready for review August 6, 2019 04:57
…in-schema-generator to generate federated GraphQL schemas. Federated GraphQL architecture is an alternative to schema stitching approach that relies on declarative programming composition of schemas.

graphql-kotlin-federation adds support for the following:

new @key, @extends, @external, @requires and @provides directives
new _FieldSet and _Any scalar types
new _Entity union type of all federated types
new _service query that returns _Service object with sdl field
new _entity query that returns list of _Entity objects
In order to generate federate schemas we have to annotate the underlying type with proper new directives and then use new toFederatedSchema function to build the schema (instead of toSchema function from graphql-kotlin-schema-generator). FederatedSchemaGeneratorHooks also require to specify FederatedTypeRegistry that holds a mapping between federated type names and their corresponding resolver. Those new FederatedTypeResolvers are used to instantiate the federated types based on the federated _entity query generated from the gateway.

See: https://www.apollographql.com/docs/apollo-server/federation/introduction/

Resolves: ExpediaGroup#238
type _Service {
sdl: String!
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be interesting to default the type description and add a link to section in the spec.
People will keep getting confused by _Entity and _Service for a while

}
```

#### Extended Service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should precise which service ReviewService here I believe

* class User(
* @property:ExternalDirective val userId: String,
* @property:ExternalDirective val name: String
* )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean if we have a third property here it wouldn't be exposed in the graph?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would result in invalid schema

}

type Query {
_service: _Service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the service is not "federate-able" should its SDL contain _service?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dariuszkuc dariuszkuc merged commit c398ae4 into ExpediaGroup:master Aug 12, 2019
@dariuszkuc dariuszkuc deleted the federation branch August 12, 2019 19:19
smyrick pushed a commit to smyrick/graphql-kotlin that referenced this pull request Sep 11, 2019
* Create new graphql-kotlin-federation module that extends graphql-kotlin-schema-generator to generate federated GraphQL schemas. Federated GraphQL architecture is an alternative to schema stitching approach that relies on declarative programming composition of schemas.

graphql-kotlin-federation adds support for the following:

new @key, @extends, @external, @requires and @provides directives
new _FieldSet and _Any scalar types
new _Entity union type of all federated types
new _service query that returns _Service object with sdl field
new _entity query that returns list of _Entity objects
In order to generate federate schemas we have to annotate the underlying type with proper new directives and then use new toFederatedSchema function to build the schema (instead of toSchema function from graphql-kotlin-schema-generator). FederatedSchemaGeneratorHooks also require to specify FederatedTypeRegistry that holds a mapping between federated type names and their corresponding resolver. Those new FederatedTypeResolvers are used to instantiate the federated types based on the federated _entity query generated from the gateway.

See: https://www.apollographql.com/docs/apollo-server/federation/introduction/

Resolves: ExpediaGroup#238
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
* Create new graphql-kotlin-federation module that extends graphql-kotlin-schema-generator to generate federated GraphQL schemas. Federated GraphQL architecture is an alternative to schema stitching approach that relies on declarative programming composition of schemas.

graphql-kotlin-federation adds support for the following:

new @key, @extends, @external, @requires and @provides directives
new _FieldSet and _Any scalar types
new _Entity union type of all federated types
new _service query that returns _Service object with sdl field
new _entity query that returns list of _Entity objects
In order to generate federate schemas we have to annotate the underlying type with proper new directives and then use new toFederatedSchema function to build the schema (instead of toSchema function from graphql-kotlin-schema-generator). FederatedSchemaGeneratorHooks also require to specify FederatedTypeRegistry that holds a mapping between federated type names and their corresponding resolver. Those new FederatedTypeResolvers are used to instantiate the federated types based on the federated _entity query generated from the gateway.

See: https://www.apollographql.com/docs/apollo-server/federation/introduction/

Resolves: ExpediaGroup#238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Apollo Federation Support
4 participants