graphql / graphql/graphql-spec
Conditional resolving / optional expanding
- Dominant language
- JavaScript
- Stars
- 14.6k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
It would be nice if you could somehow make resolving conditional whether i request subfieds at all:
ExampleData:
```
vehicleData = [
{
licenseplate: "AB-CD123",
customerNo: "1234"
},
...
]
customerData = [
{
CusteormNo: "1234",
Name: "John Doe"
}
]
```
How it is
```
schemas:
type vehicle {
licenseplate: String
CustomerNo: String
Customer: Customer
}
type Customer {
CustomerNo: String
Name: String
}
Resolver:
Vehicle: {
Customer: ({ CustomerNo }, args, context, info) => {
return customers.find( x => x.CustomerNo == CustomerNo )
},
},
```
```
query for vehicle without customer:
query ExampleQuery {
vehicles{
licenseplate
CustomerNo
}
}
query for vehicle with customer:
query ExampleQuery {
vehicles{
licenseplate
Customer {
CustomerNo
Name
}
}
}
```
How i wish it would be
```
schemas:
type vehicle {
licenseplate: String
Customer: String | Customer <- dynamic fields?
}
type Customer {
CustomerNo: String
Name: String
}
Resolver:
Vehicle: {
Customer: ({ Customer }, args, context, info) => {
if( _noSubfields_ ) return Customer; /* no expensive resolving */
return customers.find( x => x.Customer== Customer)
},
},
```
```
query for vehicle without customer:
query ExampleQuery {
vehicles{
licenseplate
Customer
}
}
query for vehicle with customer:
query ExampleQuery {
vehicles{
licenseplate
Customer {
CustomerNo
Name
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.