石墨烯的联合实现
graphene-federation的Python项目详细描述
石墨烯联合会
石墨烯的联合支持
基于python graphene lib的联邦规范实现的草稿版本 https://www.apollographql.com/docs/apollo-server/federation/federation-spec/
风险自负
基于讨论:https://github.com/graphql-python/graphene/issues/953#issuecomment-508481652
现在支持:
- sdl(服务字段)使得可以在联合中添加模式(原样)
- @key decorator(实体支持)跨服务边界执行查询
- 扩展扩展远程类型
- 外部将字段标记为外部
TOdo实现:
- @需要
- @提供
importgraphenefromgraphene_federationimportbuild_schema,key@key(fields='id')# mark File as Entity and add in EntityUnion https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#keyclassFile(graphene.ObjectType):id=graphene.Int(required=True)name=graphene.String()defresolve_id(self,info,**kwargs):return1defresolve_name(self,info,**kwargs):returnself.namedef__resolve_reference(self,info,**kwargs):# https://www.apollographql.com/docs/apollo-server/api/apollo-federation/#__resolvereferencereturnget_file_by_id(self.id)
importgraphenefromgraphene_federationimportbuild_schemaclassQuery(graphene.ObjectType):...passschema=build_schema(Query)# add _service{sdl} field in Query
importgraphenefromgraphene_federationimportexternal,extend@extend(fields='id')classMessage(graphene.ObjectType):id=external(graphene.Int(required=True))defresolve_id(self,**kwargs):return1
有关详细信息,请参见examples
或者最好检查integration_tests
与MongoEngine的集成也很酷example
供款:
运行测试:
make test
- 如果更改了dockerfile或需求,请在
make test
之前运行make build