graphql-platform
graphql-platform copied to clipboard
Cannot convert from 'System.Collections.Generic.IReadOnlyList<StrawberryShake.EntityIdOrData>' to ...
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
This is thrown when is trying to generate code:
StrawberryShake.CodeGeneration.CSharp.Analyzers/StrawberryShake.CodeGeneration.CSharp.Analyzers.CSharpClientGenerator/GraphqlClient.StrawberryShake.cs(5463,115): error CS1503: Argument 1: cannot convert from 'System.Collections.Generic.IReadOnlyList<StrawberryShake.EntityIdOrData>' to 'System.Collections.Generic.IReadOnlyList<GraphQL.IClosePayment_CommitPayments_Results>
Steps to reproduce
query:
mutation ClosePayment($commitPaymentInput: [CommitPaymentInput!]!) {
commitPayments(payments: $commitPaymentInput) {
results {
id
}
}
}
schema:
...
union PaymentActionResult = ClaimPayment | PolicyPayment | PaymentCommitFailure | AccessDeniedError
type PaymentActionsResultList {
results: [PaymentActionResult!]!
}
...
Relevant log output
No response
Additional Context?
I believe the error is on the results list, but have no idea why that happens.
Product
Strawberry Shake
Version
12.5.0.0
Can you post to me or pascal on slack (slack.chillicream.com) the full schema file?
Hi, are you able to see the cause of this error?
Hi, any update?
The query is not valid GraphQL.
results {
id
}
Results is a union type and thus needs fragments to access any field.
The query is not valid GraphQL.
results { id }Results is a union type and thus needs fragments to access any field.
I am sorry the query that I post was incorrect. This is the correct one:
mutation ClosePayment($commitPaymentInput: [CommitPaymentInput!]!) {
commitPayments(payments: $commitPaymentInput) {
...ClosePaymentResultList
}
}
fragment ClosePaymentStaus on Payment {
id
}
fragment ClosePaymentResultList on PaymentActionsResultList {
results {
...ClosePaymentStaus
}
}
The query is not valid GraphQL.
results { id }Results is a union type and thus needs fragments to access any field.
I am sorry the query that I post was incorrect. This is the correct one:
mutation ClosePayment($commitPaymentInput: [CommitPaymentInput!]!) {
commitPayments(payments: $commitPaymentInput) {
...ClosePaymentResultList
}
}
fragment ClosePaymentStaus on Payment {
id
}
fragment ClosePaymentResultList on PaymentActionsResultList {
results {
...ClosePaymentStaus
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Any update on this issue?
@rafagp-dev or @touriganational, were either of you able to resolve this?
Setting "noStore": true in the .graphqlrc.json seems to fix this for me, but doing so does away with any caching benefits. Not sure if it's a long-term solution or if either of you had a more full-proof one?
Nope. We are using other field that dont use a list of unions for now, since that data is not too relevant for the moment in our project.
Thanks for the prompt response on this.
I've been able to look at this a bit more, and the issue, for me at least, seems to be that whenever I pass a union type as a field on an object type, things go awry on Strawberry Shake (there's never any issues on Hot Chocolate or Banana Cake Pop).
So something like:
public interface IUserResult
{
// omitted for brevity
}
public class UserResultType : UnionType<IUserResult>
{
// omitted for brevity
}
[ExtendObjectType(OperationTypeNames.Mutation)]
public class UserMutations
{
public async Task<IUserResult> SignUpAsync(string email, IUserService service)
{
// omitted for brevity
}
}
Since the mutations conventions (which I'm using) create a Payload object, they include a "userResult" field and "errors" field, which is where the issue lies. Errors query fine, but "userResults" do not.
If mutation conventions are disabled, then things work fine and I'm able to query the union directly without fields, but it means losing out on the "errors" field and a lot of the other niceness that comes with mutation conventions (inputs etc).
e.g.
mutation SignUp {
signUp(input: { email: "[email protected]" }) {
__typename,
... on User {
email
}
}
}
I'm hoping I'm missing something super obvious here, hence the detailed reply, as I'm hoping someone might be able to jump in and save the day (: