Graphene Federation
raw JSON → 3.3.0 verified Fri May 01 auth: no python
Federation implementation for Graphene. Adds support for Apollo Federation (v1 and v2) to GraphQL schemas built with graphene. Current version 3.3.0 supports Federation v2.11 directives. Active development.
pip install graphene-federation Common errors
error ImportError: cannot import name 'enable_federation_2' from 'graphene_federation' ↓
cause enable_federation_2 was removed in v3.2.0.
fix
Use federation_version parameter: schema = build_schema(query=Query, federation_version=2)
error NameError: name 'extend' is not defined ↓
cause The @extend decorator was removed in v3.2.0.
fix
Replace @extend with @extends and ensure @key is present.
error TypeError: build_schema() got an unexpected keyword argument 'federation_2' ↓
cause Old code still using enable_federation_2 pattern but upgrade to v3.2.0 removed it.
fix
Use build_schema(query=Query, federation_version=2) instead.
error AttributeError: module 'graphene_federation' has no attribute 'cost' ↓
cause Using older version (<3.3.0) of graphene-federation that does not include 'cost' directive.
fix
Upgrade to v3.3.0: pip install --upgrade graphene-federation
Warnings
breaking In v3.2.0, the @extend directive was removed. Replace with @extends + @key for V1, or just @key for V2. ↓
fix Replace @extend decorator with @extends (and @key if not already present).
deprecated enable_federation_2() function is deprecated. Use federation_version parameter in build_schema() instead. ↓
fix Remove enable_federation_2() call and pass federation_version=2 to build_schema().
gotcha Federation v2 requires all types to have @key directive. Missing @key on an entity type leads to runtime errors in Apollo Gateway. ↓
fix Add @key to all entity types using '@key('id')' or other field combinations.
gotcha When using Federation v2 with @shareable, ensure that fields marked @shareable are resolved consistently across subgraphs or expect composition errors. ↓
fix Define resolvers returning identical values for @shareable fields or avoid marking them as shareable if they differ.
Imports
- build_schema
from graphene_federation import build_schema - extends
from graphene_federation import extends - key
from graphene_federation import key - external
from graphene_federation import external - provides
from graphene_federation import provides - requires
from graphene_federation import requires - authenticated
from graphene_federation import authenticated - requiresScopes
from graphene_federation import requiresScopes - policy
from graphene_federation import policy - shareable
from graphene_federation import shareable - inaccessible
from graphene_federation import inaccessible - tag
from graphene_federation import tag - override
from graphene_federation import override - composeDirective
from graphene_federation import composeDirective - link__Purpose
from graphene_federation import link__Purpose - external
from graphene_federation import external - cost
from graphene_federation import cost - listSize
from graphene_federation import listSize - context
from graphene_federation import context - fromContext
from graphene_federation import fromContext - enable_federation_2 wrong
from graphene_federation import enable_federation_2correct
Quickstart
import graphene
from graphene_federation import build_schema, key, extends
@key('id')
@extends
class Product(graphene.ObjectType):
id = graphene.ID(required=True)
name = graphene.String()
class Query(graphene.ObjectType):
product = graphene.Field(Product, id=graphene.ID(required=True))
def resolve_product(self, info, id):
return Product(id=id)
schema = build_schema(query=Query)
print(schema)