Skip to main content

Federation implementation for graphene

Project description

graphene-federation

Federation support for graphene

Build: CircleCI

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 before make test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphene-federation-0.0.3.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file graphene-federation-0.0.3.tar.gz.

File metadata

  • Download URL: graphene-federation-0.0.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/38.5.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/2.7.15+

File hashes

Hashes for graphene-federation-0.0.3.tar.gz
Algorithm Hash digest
SHA256 74b393daf8811fdd10e4b8395f33e3be667e0e4f6f9508c372758f6fd38f03c1
MD5 29b7819a481432ab100ac79838cf6bad
BLAKE2b-256 f5fa0d121060c30cc716e61e6b66af7b9dc94e7a4adf13995dc52dfee9c87a5a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page