umbraco-community / umbraco-graphql

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

Restructuring the root query type #11

Closed rasmusjp closed 6 years ago

rasmusjp commented 6 years ago

Right now the "content queries" are directly on the root query:

type UmbracoQuery {
    contentAtRoot: [PublishedContent]!
    contentById: PublishedContent
    people: [People]!
    products: [Products]!
}

To avoid cluttering the root type (e.g. if we want to implement #3, #8 and dictionary in #9), and make the data more discoverable I think we should move them to sub types.

I think something the types below will make the data more discoverable and make it easier to add new "query objects" to the root query without it being to cluttered

type ContentQuery {
    atRoot: [PublishedContent]!
    byId(id: ID!): PublishedContent
    byType: ContentByTypeQuery!
    byUrl(url: String!): PublishedContent
    site: PublishedContent
}

type ContentByTypeQuery {
    People(id: ID!): People
    Products(id: ID!): Products
}

# Not sure if this is needed
type MediaQuery {
    byId(id: ID!): PublishedContent
}

type DictionaryQuery {
    all: [DictionaryItem]!
    byKey: DictionaryItem
}

# Root query
type UmbracoQuery {
    content: ContentQuery!
    media: MediaQuery!
    dictionary: DictionaryQuery!
}

Maybe even adding a ContentAtRootQuery with all the types that's allow at root

type ContentAtRootQuery {
    all: [PublishedContent]!
    People: [People]!
    Products: [Products]!
}
PeteDuncanson commented 6 years ago

So to use this you would need a query like so?

{ UmbracoQuery { ContentByType { People { name, avatar } } } }

Have I read that right?

rasmusjp commented 6 years ago

Not quite. The query ends up like this:

{
  content {
    byType {
      People(id: 1234) {
        name
        avatar
      }
    }
  }
}

with the changes in bd656a8d I've moved contentById and contentAtRoot to content so the queries will look like

{
  content {
    byId(id: 1234) {
      _contentData {
        name
      }
    }
    atRoot {
      all {
        _contentData {
          name
        }
      }
      People {
        avatar
      }
    }
  }
}

One thing I'm not sure about is if we should rename content to publishedContent.

PeteDuncanson commented 6 years ago

Ohhh I like that, that reads much nicer. I approve :)