Closed
Description
I would like to not define the input variables multiple times when they are equivalent for all resolver. How can I achieve that?
import graphene
class GeoInput(graphene.InputObjectType):
lat = graphene.Float(required=True)
lng = graphene.Float(required=True)
@property
def latlng(self):
return "({},{})".format(self.lat, self.lng)
class Address(graphene.ObjectType):
latlng = graphene.String()
class Test(graphene.ObjectType):
test_string = graphene.String()
class Query(graphene.ObjectType):
address = graphene.Field(Address, geo=GeoInput(required=True))
test = graphene.Field(Test, geo=GeoInput(required=True))
def resolve_address(self, info, geo):
return Address(latlng=geo.latlng)
def resolve_test(self, info, geo):
return Test(test_string="({},{})".format(geo.lat, geo.lng))
schema = graphene.Schema(query=Query)
query = """
query something{
address(geo: {lat:32.2, lng:12}) {
latlng
}
test(geo: {lat:32.2, lng:12}) {
testString
}
}
"""
if __name__ == "__main__":
result = schema.execute(query)
print(result.data["address"]["latlng"],
result.data["test"]["testString"])
Is there any way doing it for the whole query class, like initializing variables?