umbraco-community / umbraco-graphql

An implementation of GraphQL for Umbraco 8 using GraphQL for .NET.
MIT License
64 stars 32 forks source link

Change the way to nest Umbraco built in fields to ease readability of queries #42

Closed PeteDuncanson closed 5 years ago

PeteDuncanson commented 5 years ago

While demo'ing GraphQL at the UK Umbraco Fest I made some bigger queries (see this video for an example: https://drive.google.com/file/d/1kOmHV2cxHo2ZnoEzRjp3ubSl5msQOmqq/view). They needed to get to multiple IPublishedContent items and then access that items build in Umbraco properties (url and name in this case).

I found the syntax for these very wordy as you have to nest it in via the _contentData object and it made the whole thing not read very well. I think we need a rethink on this one. Currently I'm thinking we either use underscores as a prefix for the built in fields or add "node" to the front of it or even "umb". Underscores win for me as it means they will appear at the top of the Intellisense and all grouped together.

So instead of this:

{
    content {
        byId( id: 123 ) {
            _contentData {
                name,
                url
            }
            parent {
                _contentData {
                    name
                }
            }
        }
    }
}

I propose we use something like this:

{
    content {
        byId( id: 123 ) {
            _name,
            _url
            parent {
                _name
            }
        }
    }
}
rasmusjp commented 5 years ago

I've done some testing (and checked the Umbraco source) and it's not allowed to create properties with a leading _.

So moving the fields back to PublishedContent and prefixing them with _ instead shouldn't be a problem.

rasmusjp commented 5 years ago

PR open in #44