Package: ariadne-extensions
Ariadne ExtensionsSet of scripts and helper utilities to extendAriadne GraphQL libraryInstallpip install ariadne-extensionsFeaturesFederation supportSupport forFederation SpecificationFeaturesGenerate federation schema types and directives (_Any,_FieldSet, ...)Implements{_service{sdl}}queryDetects boundary types and generates_EntitiesunionImplements resolve reference helpers for boundary types queried over{_entities}query (resolve_referenceandresolve_referencesdecorators)Documentationariadne_extensions.federation.FederatedManagerFederatedManageris a class responsible for creating and executable schema that complies with Federation Specification. Similar to whatmake_executable_schemadoes with ordinary schema file.Create a FederatedManager instance passing in path to your schema file and QueryType instance. Manager needs to query_type to register_entitiesand_serviceresolvers.query_type=QueryType()manager=federation.FederatedManager(schema_sdl_file='/some/path/schema.graphql',query=query_type,)Register any otherObjectTypes and resolvers by either calling andadd_typesmethod, or by extendingmanager.typeslist.photo_type=ObjectType('Photo')thumbnail_type=ObjectType('Thumbnail')manager.add_types(photo_type,thumbnail_type)manager.types.append(snake_case_fallback_resolvers)Finally, get a combiled schema. This compiled schema will extend types defined in '/some/path/schema.graphql' with directives, types and queries, that required by Federation Specification protocol.schema=manager.get_schema()ariadne_extensions.federation.FederatedObjectTypeIf you are using GraphQL Federation, your service schema probably implements some so called "boundary objects". That's whereFederatedObjectTypeis useful.FederatedObjectTypeimplementsresolve_referenceandresolve_referencesdecorator. Those are used to register functions, that will be called when a federation gateway calls{_entities{}}query.Let's sayUseris a boundary type, with a singleidkey. You need to implement a function, that will accept a dictionary of keys ({'id': ...} in our example) and return aUserinstance.
FederatedManager will call this function for every_entities([{__typename: 'User', id: ...}])query.user_type=federation.FederatedObjectType('User')@user_type.resolve_referencedefresolve_user_reference(representation,obj,info):user_id=representation.get('id')returnget_user_by_id(user_id)FederatedObjectTypeextends Ariadne'sObjectType. You can still use thefielddecorator,set_aliasmethod and others as in regularObjectType, and others.@user_type.field('name')defresolve_billing_account(obj,*_,id):returnf'{obj.first_name}{obj_last_name}'Don't forget to adduser_typeto our manager.manager.add_types(user_type)Exampletype User @key(fields: "id") @extends {
    id: ID! @external
    photos: [Photo]!
}

type Photo {
    id: ID!
    url: String!
    description: String
}fromos.pathimportdirname,joinfromariadneimportQueryType,ObjectType,snake_case_fallback_resolversfromariadne_extensionsimportfederationquery_type=QueryType()manager=federation.FederatedManager(schema_sdl_file=join(dirname(__file__),'schema.graphql'),query=query_type,)user_type=federation.FederatedObjectType('User')photo_type=ObjectType('Photo')@user_type.resolve_referencedefresolve_user_reference(representation,obj,info):user_id=representation.get('id')returnget_user_by_id(user_id)@user_type.field('name')defresolve_billing_account(obj,*_,id):returnf'{obj.first_name}{obj_last_name}'manager.add_types(user_type,photo_type)manager.add_types(snake_case_fallback_resolvers)schema=manager.get_schema()