Husqvik / GraphQlClientGenerator

GraphQL C# client generator
MIT License
213 stars 49 forks source link

The type X already contains a definition for 'Title' #142

Closed janbartosek closed 1 year ago

janbartosek commented 1 year ago

Hi,

our graphql schema has some union types and the generator creates the code with multiple same-name fields.

The Union type is composed of two object types A and B, both have field "title".

Any idea how to solve this? Thanks!

public class MyUnionType
{
   public Guid? Id { get; set; } // A
   public string Title { get; set; } // A

   public string Hint { get; set; } // B
   public string Title { get; set; } // B
}
Husqvik commented 1 year ago

I guess if the type is the same it can be just deduplicated. If the type is different then I don't think we could anything but keeping the first or last. But in that case the design of the type is incorrect as a single property is ambiguous .

Husqvik commented 1 year ago

Do you use the latest generator version? Because there already is deduplication for UNION fields.

janbartosek commented 1 year ago

Yes I do. Even though there is not the latest version in the NuGet I downloaded the repository and tried it with my built of version 0.9.16.

Husqvik commented 1 year ago

Can you provide the schema metadata so I can use it for replicating the issue locally?

query IntrospectionQuery {
    __schema {
      queryType { name }
      mutationType { name }
      subscriptionType { name }
      types {
        ...FullType
      }
      directives {
        name
        description
        locations
        args {
          ...InputValue
        }
      }
    }
  }

  fragment FullType on __Type {
    kind
    name
    description
    fields(includeDeprecated: true) {
      name
      description
      args {
        ...InputValue
      }
      type {
        ...TypeRef
      }
      isDeprecated
      deprecationReason
    }
    inputFields {
      ...InputValue
    }
    interfaces {
      ...TypeRef
    }
    enumValues(includeDeprecated: true) {
      name
      description
      isDeprecated
      deprecationReason
    }
    possibleTypes {
      ...TypeRef
    }
  }

  fragment InputValue on __InputValue {
    name
    description
    type { ...TypeRef }
    defaultValue
  }

  fragment TypeRef on __Type {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
            ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
              }
            }
          }
        }
      }
    }
  }
Husqvik commented 1 year ago

The problem should be solved now (the new package not available yet)