Closed zivfuture closed 2 years ago
I've never tried this, but it should work. You'd need to be inheriting from InputObjectType<T>
though.
Then you should just call .AddType<ProductUpdateInputType>().AddType<ProductAddInputType>()
and see what happens!
@benmccallum i got an error when start the application
If you post the error you're getting we might be able to help
I think something like: the same type or key was already registered :) @zivfuture what is the error? I`m not fully sure if you can have 2x object types on same object..
@benmccallum @damikun
I think something like: the same type or key was already registered .
yes , this is the error.
Looking at this again, it's worth noting that the naming conventions in HotChocolate derive the name from the backing type, in this case ProductInput
, so unless you specify the name explicitly, with descriptor.Name("SomeName")
and a diff for the other, there's of course going to be a conflict.
Notably this varies from GraphQL-DotNet which derives it from the wrapping type.
@benmccallum @benmccallum Sorry, I cat't catch your mean. where to specify the name? I try to change the api code
public class Mutation
{
public int AddProduct(ProductInput input) { ......}
public int UpdateProduct(ProductInput input) { ......}
}
to
public class Mutation
{
public int AddProduct(ProductAddInputType input) { ......} //change ProductInput to ProductAddInputType
public int UpdateProduct(ProductUpdateInputType input) { ......} //
}
. I failed. Error is HotChocolate.SchemaException:“Unable to resolve type reference `Input: GraphQL.ProductAddInputType `. - Type: Mutation”
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.
I have a product mutation api (add & update & ...) like this
As you see. many apis has same argument. but the field's nullable is diffent. For UpdateProduct api. the product's id must not be null, the other fields can be null. For AddProduct api ,It's the opposite.
I don't want to create so many same classes except diffent nullable.
Don't repeat you self.
I tried to create diffent graphql type to descripe the nullable.