Federation implementation for graphene
Project description
graphene-federation
Federation support for graphene
Draft version, of federation specs implementation on top of Python graphene lib https://www.apollographql.com/docs/apollo-server/federation/federation-spec/
Use at your own risk
Based on discussion: https://github.com/graphql-python/graphene/issues/953#issuecomment-508481652
Supports now:
- sdl (_service fields) # make possible to add schema in federation (as is)
- @key decorator (entity support) # to perform Queries across service boundaries
- extend # extend remote types
- external # mark field as external
Todo implement:
- @requires
- @provides
import graphene
from graphene_federation import build_schema, key
@key(fields='id') # mark File as Entity and add in EntityUnion https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#key
class File(graphene.ObjectType):
id = graphene.Int(required=True)
name = graphene.String()
def resolve_id(self, info, **kwargs):
return 1
def resolve_name(self, info, **kwargs):
return self.name
def __resolve_reference(self, info, **kwargs): # https://www.apollographql.com/docs/apollo-server/api/apollo-federation/#__resolvereference
return get_file_by_id(self.id)
import graphene
from graphene_federation import build_schema
class Query(graphene.ObjectType):
...
pass
schema = build_schema(Query) # add _service{sdl} field in Query
import graphene
from graphene_federation import external, extend
@extend(fields='id')
class Message(graphene.ObjectType):
id = external(graphene.Int(required=True))
def resolve_id(self, **kwargs):
return 1
For more details see examples
Or better check integration_tests
Also cool example of integration with Mongoengine
For contribution:
Run tests:
make test
- if you've changed Dockerfile or requirements run
make build
beforemake test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for graphene-federation-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a960d920952b540a5f543c66b2de0f5a45d5a6d50d16e41e43c42ea665dd8791 |
|
MD5 | 88f2885602164213607765b2029fabd9 |
|
BLAKE2b-256 | a9cf6f74d9b1e39cd54c8b305fe5add2564b994fa3849f83f371dd2e2c41929b |