GraphQL & Custom Fields

12 views
Skip to first unread message

Alex

unread,
Aug 22, 2021, 9:35:39 AMAug 22
to dotCMS User Group
Happy Sunday, everyone!

Does GraphQL support custom fields?  I am trying to do a query with the urlTitle field  of the Product Collection on the demo and I get an empty response.  I get the same result when I try to use the urlTitle custom field from any of our content types.

Am I doing something wrong?  I know I can query with the urlMap and then split it on the "/", but it is easier if I do it with the urlTitle field.

Query:

query ContentAPI {
  ProductCollection(query: "+urlTitle:*snow*", limit: 10, offset: 0, sortBy: "score") {
    title
    urlMap
    category {
      name
      inode
    }
    retailPrice
    image {
      versionPath
    }
  }
}

Response:

{
  "data": {
    "ProductCollection": []
  }
}

Falzone, Chris

unread,
Aug 23, 2021, 8:09:33 AMAug 23
to dot...@googlegroups.com
I haven't used GraphQL with dotcms but I think your query needs to include the structure name with the field.

query: "+ProductCollection.urlTitle:*snow*"

That's how it works in every other method to pull content from dotCMS, so I could only assume the same would apply here.  The doc page for GraphQL does a bad job here because it only uses the title field for examples, which is sort of a special case in dotCMS that doesn't need the structure name included.

Hope that helps.  As I said, I am not really sure because I've not used the GraphQL stuff at all.

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/96d5e3e7-8ae7-42b2-a1e8-89b1daa79f09n%40googlegroups.com.


--

Christopher Falzone

DevOps Engineer

A Q U E N T  /  VITAMIN T

Lex Medeiros

unread,
Aug 23, 2021, 9:16:57 AMAug 23
to dot...@googlegroups.com
Dear Chris:

As always your transcendental knowledge  has brought an insight into everything!

Thank you!  Adding the content type/structure name preceded by a "." works on the field name works. 

I will send feedback on the documentation so it is updated.

Thank you again,

Alex

Alex

unread,
Sep 12, 2021, 11:13:37 PMSep 12
to dotCMS User Group
Hi, Chris!

I have another question, do you know how to sort based on a nested field?  For example, here is a relationship GraphQL query, taken from https://dotcms.com/headless-cms-graphql on the playground area.  I want to sort by the title of activities.  I have tried many ways, but it has not been successful yet.

query relationshipQuery {
  destinationCollection(
    limit: 10,
    offset: 0,
    sortBy: "score"
  ){
    title
    activities{
      title
      urlTitle
      image{
         idPath

Falzone, Chris

unread,
Sep 13, 2021, 10:40:37 AMSep 13
to dot...@googlegroups.com
I don't know the GraphQL stuff, but I assume it is just passing on the sort to ElasticSearch, so you should be able to sort the same way as any query, something like:  

sortBy: "product.retailPrice product.title"

Reply all
Reply to author
Forward
0 new messages