C# in Graphql: directly include an object in Type and also Inputtype

Asked

Viewed 38 times

2

I have a class of users:

public class Usuario
{
    public int id { get; set; }
    public string nome { get; set; }
}

To use the above object in Graphql, I wrote the following code:

public class UsuarioType : ObjectGraphType<Usuario>
{
    public UsuarioType()
    {
        Field(f => f.id).Description("ID do Usuário");
        Field(f => f.nome).Description("Nome do Usuário");
    }
}

The same for Inputtype:

public class UsuarioInputType : InputObjectGraphType<Usuario>
{
    public UsuarioInputType()
    {
        Field(f => f.id).Description("ID do Usuário");
        Field(f => f.nome).Description("Nome do Usuário");
    }
}

Doubt: in order to facilitate maintenance by avoiding repeating the fields (id and nome), is not possible convert directly an Object in Objectgraphtype and/or Inputobjectgraphtype?

  • Are different implementations with interfaces so far I don’t see how to do that. It will also depend on which code you are using have how to tell which site you are using has some to do Graphql in C#. Graphql dotnet does not give, as reported implements different interfaces ...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.