class Product(SQLAlchemyObjectType):
class Meta:
model = ProductModel
interfaces = (relay.Node, )
@classmethod
def get_node(cls, id, context, info):
#must implement to relay
pass
class Query(graphene.ObjectType):
product = graphene.Field(Product, id=graphene.String())
node = relay.Node.Field()
def resolve_product(self, args, context, info):
session = context['session']
id_ = from_global_id(args['id'])[1]
p = session.query(ProductModel).filter(ProductModel.id == id_).first()
return p
我正在尝试使用 GraphQL + Relay + Grephene。但我有点困惑。我可以使用中继支持这两个查询吗?还是在真正实施时我只会支持第二个?
我是否总是需要将 globalId 转换为数据库主键?
图 QL:
{
product (id: "XYZ"){
id
title
}
}
中继:
{
node(id: "XYZ") {
id
... on product {
title
}
}