Inline fragments not working with `use_struct_references: true` and `pointer: optional`
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 143
- Avg merge
- 4h 50m
- Merged PRs (30d)
- 1
Description
**Describe the bug**
Seems like turning on `use_struct_references` and setting `pointer: optional` breaks the ability to read from inline fragments.
**To Reproduce**
Problem happens at runtime.
Setting `use_struct_references: true` and `pointer: optional` leads to the removal of the interface(?) that is supposed to be usable for grabbing data from inline fragments.
In the docs design.md, there is a block of code similar to
```
if pm, ok := transaction.PaymentMethod.GetDetails().(destination.ChargeCreditCardChargeCreditCardTransactionPayloadTransactionPaymentMethodDetails); ok {
}
```
While this code doesn't throw a compiler error with the default config, when you adjust the config vars mentioned above, doesn't seem like there is a way to get the inline fragment data. Messages similar to `invalid operation: transaction.PaymentMethod.GetDetails() (value of type *destination.ChargeCreditCardChargeCreditCardTransactionPayloadTransactionPaymentMethodDetails) is not an interface` pop up.
I am using this library to query/send mutations to Braintree. The reason I set the config vars above is primarily because Braintree's API doesn't handle Golang default values for Braintree's GraphQL inputs.
Here's what this mutation looks like:
```
mutation ChargeCreditCard(
$input: ChargeCreditCardInput!) {
chargeCreditCard(input: $input) {
transaction {
id
legacyId
status
createdAt
paymentMethod {
id
details {
__typename
... on CreditCardDetails {
cardholderName
last4
brandCode
expirationMonth
expirationYear
}
}
}
}
}
}
```
**Expected behavior**
Generating code in such a way that this behavior works. Unless I'm doing something incorrectly/sub-optimally?
**genqlient version**
`main`
**Additional context**
Add any other context about the problem here.
Contributor guide
Research direction
Start with the inline-fragment example in docs design.md and reproduce the mutation using use_struct_references: true and pointer: optional. Inspect the generated PaymentMethod.GetDetails() type and compare it with the default configuration; done means inline fragment data can still be accessed without the invalid type assertion error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, graphql
- Domain
- api, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100