-
Notifications
You must be signed in to change notification settings - Fork 10
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
[FEAT] Support upto Federation v2.7 #27
Open
mak626
wants to merge
39
commits into
graphql-python:main
Choose a base branch
from
strollby:federation-v2_3
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…undant spaces and new lines
… marked directives to be composed into supergraph
… of a graphql type
…on version >= 2.1
Pull Request Test Coverage Report for Build 8788451656Details
💛 - Coveralls |
mak626
changed the title
[FEAT] Support upto Federation v2.6
[FEAT] Support upto Federation v2.7
Mar 8, 2024
Added support for federation v2.7 |
mak626
force-pushed
the
federation-v2_3
branch
2 times, most recently
from
April 22, 2024 10:31
689357c
to
3e4013b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Supported versions, v1.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7
All directives are purely based on apollo-specs.
Some non existent directive like
@extend
which acted like@key
was deprecated.Migration Guide
For V1
@extend
can be replaced by@extends
and@key
combinationFor V2 just
@key
is enough.Deprecate
enable_federation_2
in favour offederation_version
Updated Docs
...
Supported Features
sdl
(_service
on field): enable to add schema in federation (as is)Apollo Spec Supported
STABLE_VERSION
. Rover dev supports only upto v2.6LATEST_VERSION
All directives could be easily integrated with the help of graphene-directives.
Now every directive's values are validated at run time itself by graphene-directives.
Directives (v2.7)
Read about directives in official documentation
Each type which is decorated with
@key
or@extends
is added to the_Entity
union.The
__resolve_reference
method can be defined for each type that is an entity.Note that since the notation with double underscores can be problematic in Python for model inheritance this resolver method can also be named
_resolve_reference
(the__resolve_reference
method will take precedence if both are declared).This method is called whenever an entity is requested as part of the fulfilling a query plan.
If not explicitly defined, the default resolver is used.
The default resolver just creates instance of type with passed fieldset as kwargs, see
entity.get_entity_query
for more details__resolve_reference
, if you need to extract object before passing it to fields resolvers (example: FileNode)__resolve_reference
, if fields resolvers need only data passed in fieldset (example: FunnyText)Read more in official documentation.
Example
Here is an example of implementation based on the Apollo Federation introduction example.
It implements a federation schema for a basic e-commerce application over three services: accounts, products, reviews.
Accounts
First add an account service that expose a
User
type that can then be referenced in other services by itsid
field:Product
The product service exposes a
Product
type that can be used by other services via theupc
field:Reviews
The reviews service exposes a
Review
type which has a link to both theUser
andProduct
types.It also has the ability to provide the username of the
User
.On top of that it adds to the
User
/Product
types (that are both defined in other services) the ability to get their reviews.Federation
Note that each schema declaration for the services is a valid graphql schema (it only adds the
_Entity
and_Service
types).The best way to check that the decorator are set correctly is to request the service sdl:
Those can then be used in a federated schema.
You can find more examples in the unit / integration tests and examples folder.
There is also a cool example of integration with Mongoengine.
Other Notes
build_schema new arguments
schema_directives
(Collection[SchemaDirective]
): Directives that can be defined atDIRECTIVE_LOCATION.SCHEMA
with their argument values.include_graphql_spec_directives
(bool
): Includes directives defined by GraphQL spec (@include
,@skip
,@deprecated
,@specifiedBy
)enable_federation_2
(bool
): Whether to enable federation 2 directives (default False)federation_version
(FederationVersion
): Specify the version explicit (default LATEST_VERSION)In case both enable_federation_2 and federation_version are specified, federation_version is given higher priority
Directives Additional arguments
federation_version
: (FederationVersion
=LATEST_VERSION
) : You can use this to take a directive from a particular federation versionNote: The
federation_version
inbuild_schema
is given higher priority. If the directive you have chosen is not compatible, it will raise an errorCustom Directives
You can define custom directives as follows
This will automatically add @link and @composeDirective to schema
If you wish to add the schema_directives
@link
@composeDirective
manually.You can pass the
add_to_schema_directives
asFalse
Custom field name
When using decorator on a field with custom name
Case 1 (auto_camelcase=False)
This works correctly.
By default
fields
of@key
,@requires
and@provides
are not converted to camel case ifauto_camelcase
is set toFalse
Case 2 (auto_camelcase=True)
This will raise an error
@key, field "validEmail" does not exist on type "User"
.Because The decorator auto camel-cased the
field
value of key, as schema hasauto_camelcase=True
(default)To fix this, pass
auto_case=False
in the@key
,@requires
or@provides
argument