rivantsov / vita

VITA Application Framework
MIT License
59 stars 15 forks source link

[Question] Sharing data objects between GraphQL and REST #177

Closed jasonlaw closed 3 years ago

jasonlaw commented 3 years ago

Hi @rivantsov ,

Do you think it is a bad idea to share the data object between GraphQL and REST?

There is an issue when I trying to do so, in my data objects below, I would like the Company's account quarriable with an argument, but there is no way to do with simply attribute.

Appreciate your advice.

Thank you.


[DebuggerDisplay("{Name}")]
    public class Company
    {
        public string Name { get; set; }
        public string DomainName { get; set; }
        //Required as attribute for REST, but method for GraphQL
        //public IList<Account> Accounts { get; set; }
      [GraphQLName("accounts")]
       public IList<Account> GetAccounts([Null] string id) => default;
    }
    [DebuggerDisplay("{Id}/{Name}")]
    public class Account
    {
        public string Id { get; set; }
        public string LoginName { get; set; }
        public string Name { get; set; }
    } 
rivantsov commented 3 years ago

you can have them "both". Try the following, uncomment Accounts property, and add attribute [GraphQLIgnore]. As a result, in REST you have both, but GetAccounts is just an empty method, does not break anything. In GraphQL you have only getAccounts field.

jasonlaw commented 3 years ago

This is really great, thank you very much! :)