agentejo / CockpitQL

GraphQL addon for Cockpit CMS - https://github.com/agentejo/cockpit
70 stars 7 forks source link

How to query only fields that i need? #2

Closed renatomattos2912 closed 6 years ago

renatomattos2912 commented 6 years ago

Hi, i'm testing this module and i can query in my collections just like i do in traditional REST cockpit API, but i want to use some cool graphql features like query in collection and get only the fields that i need, how can i do this with this module?

aheinze commented 6 years ago

let's say you have a collection named posts then you can do a query like this:

allPosts {
    _id,
    title
    content
  }

Greets Artur

renatomattos2912 commented 6 years ago

Is possible to query nested collection?

I tries this bellow:

query { allCategories { _id, Subcategories { Name } } }

but i'm getting this error bellow: { "errors": [ { "message": "Cannot query field \"Subcategories\" on type \"Categories\".", "category": "graphql", "locations": [ { "line": 4, "column": 5 } ] } ] }

But in REST the collection Categories have a nestes Subcategories, so i dont know why this graphql query is not working.

Ps: When i query only for fileds of the root collection, it works.

aheinze commented 6 years ago

please update to the latest codebase then this should work:

query { 
   allCategories(populate:1) {
       _id, 
      Subcategories { 
         Name 
      } 
   } 
}
renatomattos2912 commented 6 years ago

Ok, great. Thanks for your help.