graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Cannot convert from 'System.Collections.Generic.IReadOnlyList<StrawberryShake.EntityIdOrData>' to ...

Open rafagp-dev opened this issue 3 years ago • 10 comments

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

rafagp-dev avatar Jan 18 '22 18:01 rafagp-dev

Can you post to me or pascal on slack (slack.chillicream.com) the full schema file?

michaelstaib avatar Jan 18 '22 20:01 michaelstaib

Hi, are you able to see the cause of this error?

touriganational avatar Jan 20 '22 11:01 touriganational

Hi, any update?

touriganational avatar Feb 02 '22 15:02 touriganational

The query is not valid GraphQL.

results {
      id
}

Results is a union type and thus needs fragments to access any field.

michaelstaib avatar Feb 24 '22 12:02 michaelstaib

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
  }
}

rafagp-dev avatar Feb 24 '22 16:02 rafagp-dev

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
  }
}

rafagp-dev avatar Feb 24 '22 16:02 rafagp-dev

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.

stale[bot] avatar May 08 '22 18:05 stale[bot]

Any update on this issue?

rafagp-dev avatar May 09 '22 13:05 rafagp-dev

@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?

rhyshamilton avatar Jul 14 '22 15:07 rhyshamilton

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.

rafagp-dev avatar Jul 14 '22 17:07 rafagp-dev

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 (:

gt4Rhys avatar Jul 15 '22 15:07 gt4Rhys