I'm using Graphene in Django as a backend.
I have Query as follows:
class Query(object):
constructor_info = graphene.Field(UnTypedDataType, vin=graphene.String(required=True))
def resolve_constructor_info(self, info, **kwargs):
vin = kwargs.get('vin')
locale = info.context.LANGUAGE_CODE
constructor_info = get_kp_dict(vin, locale)
options = []
for option in constructor_info["vehicle"]["vehicleEquipment"]:
options.append(
{
'code': option['codeEquipment'],
'description': option['equipmentDescription']
}
)
vehicle = {
'model_year': constructor_info["vehicle"]['voExterior']['modelYear'],
'short_description': constructor_info["vehicle"]['voExterior']['shortModelTypeDescription'],
'long_description': "",
'exterior': "",
'interior': constructor_info["vehicle"]['voExterior']['descriptionUpholstery'],
'places': constructor_info["vehicle"]['voExterior']['numberOfPlaces'],
'doors': constructor_info["vehicle"]['voExterior']['numberOfDoors'],
'catalog_price': constructor_info["vehicle"]['voExterior']['priceCatalogueWithoutOptions'],
'catalog_price_with_options': constructor_info["vehicle"]['voExterior']['priceCatalogue'],
'first_registartion': constructor_info["vehicle"]['entryDate'],
'vin': constructor_info["vehicle"]['chassisNumber'],
'commission': constructor_info["vehicle"]['commissionNumber'],
'power_kw': constructor_info["vehicle"]['powerKW'],
'model_code': constructor_info["vehicle"]['modelCode'],
'options': options
}
return UnTypedDataType(data=vehicle)
And UnTypedDataType is as follows:
class UnTypedDataType(graphene.ObjectType):
data = graphene.Field(UnTypedObject)
On the frontend I get result as:
const GET_CONSTRUCTOR_INFO = gql`
query getConstructorInfo($vin: String!) {
constructorInfo(vin: $vin) {
data
}
}
`;
And in data
I get the vehicle object.
But, is there any way to remove data and to get the result as follows:
const GET_CONSTRUCTOR_INFO = gql`
query getConstructorInfo($vin: String!) {
constructorInfo(vin: $vin) {
model_year
short_description
long_description
... THE REST ...
}
}
`;