I want to remove fields from output JSON with default values (0, false) to reduce size of response, but can't find a way how to do it in HotChocolate/GraphQl. I didn't find a settings to control it (JsonFormatter), "Optional" also not for this purposes, and there is not options to do it via query syntax.
After query to graphQl I receive a long list, with many default values in JSON output, simple example, pay attention to "sortOrder" and "isDeleted":
"values": [{
"id": 448,
"name": "Dr.",
"isDeleted": false,
"sortOrder": 0
}, {
"id": 449,
"name": "Mr.",
"isDeleted": true,
"sortOrder": 0
}, {
"id": 450,
"name": "Mrs.",
"isDeleted": false,
"sortOrder": 1
}]
Expecting result:
"values": [{
"id": 448,
"name": "Dr.",
}, {
"id": 449,
"name": "Mr.",
"isDeleted": true,
}, {
"id": 450,
"name": "Mrs.",
"sortOrder": 1
}]
Query:
getLookups(withDeleted: true) {
id
name
isDeleted
values {
id
name
isDeleted
sortOrder
}
}
Type description:
descriptor.BindFields(BindingBehavior.Explicit);
descriptor.Interface<ILookupValueType>();
descriptor.Field(f => f.Id).Type<NonNullType<IntType>>();
descriptor.Field(f => f.Name).Type<StringType>();
descriptor.Field(f => f.Image).Type<StringType>();
descriptor.Field(f => f.IsDeleted).Type<BooleanType>();
descriptor.Field(f => f.IsDefault).Type<BooleanType>();
descriptor.Field(f => f.SortOrder).Type<IntType>();
P.S. Please, don't offer pagination, it is not what I need.
And thank you for your help.