Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline fragments not working with use_struct_references: true and pointer: optional #278

Open
partounian opened this issue Jun 6, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@partounian
Copy link

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.

@partounian partounian added the bug Something isn't working label Jun 6, 2023
@partounian
Copy link
Author

Is it possible to just apply the optional: pointer and/or the use_struct_references: true just for inputs, not outputs?

@benjaminjkraft
Copy link
Collaborator

Apologies for the delay in responding, this issue got buried. This may be useful input to how we tune these options (optional: pointer is probably the one at issue), but in the meantime you can deref the pointer and then type-assert.

@partounian
Copy link
Author

Oh interesting, I didn't know that was possible. Thanks for the info!

@partounian
Copy link
Author

I'll leave up to you to close if you desire :) @benjaminjkraft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants