ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.27k stars 748 forks source link

Generated union type classes are empty with SS13.0.5 and .NET7 when using fragments #5992

Open svelue opened 1 year ago

svelue commented 1 year ago

Is there an existing issue for this?

Product

Strawberry Shake

Describe the bug

When creating a client, based on a schema with union types the generated classes does not contain the requested fields when they are requested using fragments. Same clients are working as expected with SS12.x

Steps to reproduce

StrawberryShakeUnionTypeBug

The repo contains a simple client which shows the error.

Relevant log output

No response

Additional Context?

No response

Version

13.0.5

nikcio commented 1 year ago

Hi, @svelue do you know if there have been any updates on this one? I think I'm having the same problem with my application right now.

svelue commented 1 year ago

Hey, I don't know, I think we removed all fragments from our SS configurations and never tried again so far.

PotiraiRostyslav commented 1 year ago

I have a similar problem. Here is what I found in the generated client. A full constructor call is generated for only one of the union types. For all other types, the constructor call is incomplete `private global::StrawberryShakeTests.State.ICatalogUnitedServicesData Deserialize_NonNullableICatalogUnitedServicesData(global::System.Text.Json.JsonElement? obj) { if (!obj.HasValue) { throw new global::System.ArgumentNullException(); }

        var typename = obj.Value.GetProperty("__typename").GetString();
        if (typename?.Equals("AdditionalCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.AdditionalCatalogServiceData(typename, id: Deserialize_NonNullableString(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "id")), serviceActiveDays: Deserialize_Int32(global::StrawberryShake.Json.JsonElementExtensions.GetPropertyOrNull(obj, "serviceActiveDays")));
        }

        if (typename?.Equals("LogoOnMainPageCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.LogoOnMainPageCatalogServiceData(typename);
        }

        if (typename?.Equals("CvDbCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.CvDbCatalogServiceData(typename);
        }

        if (typename?.Equals("HotCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.HotCatalogServiceData(typename);
        }

        if (typename?.Equals("LogoInPortalCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.LogoInPortalCatalogServiceData(typename);
        }

        if (typename?.Equals("LogoInRubricCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.LogoInRubricCatalogServiceData(typename);
        }

        if (typename?.Equals("VacancyPackageCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.VacancyPackageCatalogServiceData(typename);
        }

        if (typename?.Equals("VacancyPublicationCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.VacancyPublicationCatalogServiceData(typename);
        }

        if (typename?.Equals("MarketingCatalogService", global::System.StringComparison.Ordinal) ?? false)
        {
            return new global::StrawberryShakeTests.State.MarketingCatalogServiceData(typename);
        }

        throw new global::System.NotSupportedException();
    }`

Query: `query GetFullOrder($id: ID!) { myOrder(id: $id) { id positions { count details { ...OrderPositionPublicationItem ...OrderPositionHotItem ...OrderPositionVacancyPackageItem ...OrderPositionCvdbItem ...OrderPositionAdditionalItem ...OrderPositionLogoOnMainItem ...OrderPositionLogoInPortalItem ...OrderPositionLogoInRubricItem ...OrderPositionMarketingItem typename } typename } typename } } fragment OrderPositionPublicationItem on OrderPositionVacancyPublicationServiceDetails { service { detailsUnion { ... on VacancyPublicationCatalogService { id serviceActiveDays typename } typename } typename } __typename }

fragment OrderPositionHotItem on OrderPositionHotServiceDetails { service { detailsUnion { ... on HotCatalogService { id serviceActiveDays typename } typename } typename } typename }

fragment OrderPositionVacancyPackageItem on OrderPositionVacancyPackageServiceDetails { service { detailsUnion { ... on VacancyPackageCatalogService { id serviceActiveDays typename } typename } typename } typename }

fragment OrderPositionCvdbItem on OrderPositionCvDbServiceDetails { service { detailsUnion { ...on CvDbCatalogService { id serviceActiveDays typename } typename } typename } typename }

fragment OrderPositionAdditionalItem on OrderPositionAdditionalServiceDetails { service { detailsUnion { ...on AdditionalCatalogService { id serviceActiveDays typename } typename } typename } typename }

fragment OrderPositionLogoOnMainItem on OrderPositionLogoOnMainServiceDetails { service { detailsUnion { ... on LogoOnMainPageCatalogService { id serviceActiveDays typename } typename } typename } typename }

fragment OrderPositionLogoInPortalItem on OrderPositionLogoInPortalServiceDetails { service { detailsUnion { ... on LogoInPortalCatalogService { id serviceActiveDays typename } typename } typename } typename }

fragment OrderPositionLogoInRubricItem on OrderPositionLogoInRubricServiceDetails { service { detailsUnion { ... on LogoInRubricCatalogService { id serviceActiveDays typename } typename } typename } typename }

fragment OrderPositionMarketingItem on OrderPositionMarketingServiceDetails { service { detailsUnion { ... on MarketingCatalogService { id serviceActiveDays typename } typename } typename } typename }`

DominicMaas commented 11 months ago

I think I've just hit this as well

svelue commented 5 months ago

@michaelstaib Any updates on this one? Unfortunately this problem gets worse when using uniontypes in uniontypes. Since fragments are not working strawberryshake does not generate a common interface but a lot identical ones with _1, _2, ... suffix. This makes it quite hard and error prone to map the client results.

michaelstaib commented 5 months ago

SS gets a new generator soon ... we are at the moment busy with the server and fusion, but will soon start iterating on Strawberry Shake again.