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

Strawberry Shake produces CS8604 #3985

Closed
Alxandr opened this issue Jul 23, 2021 · 4 comments
Closed

Strawberry Shake produces CS8604 #3985

Alxandr opened this issue Jul 23, 2021 · 4 comments

Comments

@Alxandr
Copy link
Contributor

Alxandr commented Jul 23, 2021

Describe the bug
Using Strawberry Shake 12 preview 26 I get CS8604 (Possible null reference argument for parameter).

To Reproduce

https://github.com/glen-84/hc-3985 (.NET 8, SS 13.8.1)

Steps to reproduce the behavior:
Use the following schema:

schema {
  query: Query
}

type Query {
  customer: Customer
}

interface Customer {
  name: PersonName! @deprecated(reason: "Moved to person type")
}

type Person implements Customer {
  name: PersonName!
}

type PersonName {
  firstName: String!
  middleName: String
  lastName: String!
  displayName: String!
}

the following query:

fragment customer on Customer {
  name {
    firstName
    middleName
    lastName
    displayName
  }
}

query test() {
  customer { ...customer }
}

and the following config:

{
  "schema": "schema.graphql",
  "documents": "**/*.graphql",
  "extensions": {
    "strawberryShake": {
      "name": "TestClient",
      "url": "https://example.com/graphql",
      "dependencyInjection": true,
      "strictSchemaValidation": true,
      "hashAlgorithm": "sha256",
      "useSingleFile": true,
      "requestStrategy": "Default",
      "outputDirectoryName": "Generated",
      "noStore": true,
      "emitGeneratedCode": true,
      "razorComponents": false,
      "records": {
        "inputs": true,
        "entities": true
      },
      "transportProfiles": [
        {
          "default": "Http"
        }
      ]
    }
  }
}

This produces the following code:

    public partial record PersonData : ICustomerData
    {
        public PersonData(global::System.String __typename, global::Test.State.PersonNameData? name = default !)
        {
            this.__typename = __typename ?? throw new global::System.ArgumentNullException(nameof(__typename));
            Name = name;
        }

        public global::System.String __typename { get; init; }

        public global::Test.State.PersonNameData? Name { get; init; } // <-- nullable
    }

        private global::Test.ITest_Customer? MapITest_Customer(global::Test.State.ICustomerData? data)
        {
            if (data is null)
            {
                return null;
            }

            ITest_Customer? returnValue;
            if (data is global::Test.State.PersonData person)
            {
                returnValue = new global::Test.Test_Customer_Person(MapNonNullableITest_Customer_Name(person.Name)); // <-- MapNonNullableITest_Customer_Name expects non-null customer name
            }
            else
            {
                throw new global::System.NotSupportedException();
            }

            return returnValue;
        }

        private global::Test.ITest_Customer_Name MapNonNullableITest_Customer_Name(global::Test.State.PersonNameData data) // <-- does not accept null
        {
            ITest_Customer_Name returnValue = default !;
            if (data.__typename.Equals("PersonName", global::System.StringComparison.Ordinal))
            {
                returnValue = new Test_Customer_Name_PersonName(data.FirstName ?? throw new global::System.ArgumentNullException(), data.MiddleName, data.LastName ?? throw new global::System.ArgumentNullException(), data.DisplayName ?? throw new global::System.ArgumentNullException());
            }
            else
            {
                throw new global::System.NotSupportedException();
            }

            return returnValue;
        }

Expected behavior
The generated code should not produce warnings.

Desktop (please complete the following information):

  • OS: Windows
  • Version 10
@Alxandr Alxandr added the 🐛 bug Something isn't working label Jul 23, 2021
@michaelstaib michaelstaib added this to the Backlog milestone Nov 22, 2021
@atrauzzi
Copy link

Just encountered this as well, any chance of it being addressed, or is there perhaps a workaround/config setting?

@danielstarck
Copy link

I've run into this as well but with a slightly different scenario: https://github.com/danielstarck/strawberry-shake-cs8604-repro. Remove either schema.ext.graphql or the field id from the type Something in schema.graphql to get CS8604 upon build.

@stale stale bot added the ⌛ stale Nothing happened with this issue in quite a while label Oct 1, 2022
@Ceaphyrel
Copy link

This is still happening in 12.18.0 (StrawberryShake.CodeGeneration.CSharp.Analyzers) as well as in the newer 13.0.5 StrawberryShake.Server

@glen-84
Copy link
Collaborator

glen-84 commented Jun 6, 2024

Fixed in #7033. Available in 14.x.

@glen-84 glen-84 closed this as completed Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants