RE: 7.2.1 - GraphQL returning invalid URL for accessing content?

thumbnail
Fernando Fernandez, modified 5 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
Hi all,
I'm exploring GraphQL in 7.2 GA2, using Altair as a chrome extension. 
I'm currently able to find a content with this query:
query{
  structuredContentByKey(key: "35506", siteId: 20124){
    friendlyUrlPath
    title
    renderedContents{
      renderedContentURL
      templateName
    }
  }
}
The query result is:
{
  "data": {
    "structuredContentByKey": {
      "friendlyUrlPath": "directions-generic",
      "title": "Directions - generic",
      "renderedContents": [
        {
          "renderedContentURL": "http://localhost:8080/o/graphql/v1.0/structured-contents/35508/rendered-content/28105",
          "templateName": "Basic Web Content"
        },
        {
          "renderedContentURL": "http://localhost:8080/o/graphql/v1.0/structured-contents/35508/rendered-content/35566",
          "templateName": "Alternative BWC template"
        }
      ]
    }
  }
}

But the URL provided by the query is failing with a 400 status and the following message is appearing on the log:
[AbstractGraphQLHttpServlet:141] Bad GET request: path was not "/schema.json" or no query variable named "query" given


Is this a bug or am I doing something wrong?
TIA
Fernando
thumbnail
Fernando Fernandez, modified 5 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
Meanwhile, if the OpenAPI service is used, it works:

http://localhost:8080/o/headless-delivery/v1.0/structured-contents/35508/rendered-content/35566

The rendered content is returned, formatted by the correct template.
thumbnail
Javier Gamarra, modified 5 Years ago. Expert Posts: 348 Join Date: 2/12/15 Recent Posts
Good catch, that's a bug. I've created this ticket to track it: https://issues.liferay.com/browse/LPS-105982 Thanks!
thumbnail
Javier Gamarra, modified 5 Years ago. Expert Posts: 348 Join Date: 2/12/15 Recent Posts
As a temporal workaround, if you know the templateId, you can use renderedContentTemplate(templateId: X) 
thumbnail
Fernando Fernandez, modified 5 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
Thanks Javier, it works! :-)
The final query is:
query{
  structuredContentRenderedContentTemplate(structuredContentId: 35508 , templateId: 35566 )
}

Oddly, this query expects the article primary key instead of the articleId used in the other query. Any idea why?
Thanks
Fernando
thumbnail
Jack Bakker, modified 5 Years ago. Liferay Master Posts: 978 Join Date: 1/3/10 Recent Posts
Hi Fernando, you could try:
query{
  structuredContentByKey(key: "35506",siteKey: "yourSiteKey"){
    renderedContentTemplate(templateId: 35566)
  }
}
yourSiteKey would be same as group_.groupkey in db (which I think is always? the same as the site name)
thumbnail
Fernando Fernandez, modified 5 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
Thanks Jack! Your suggested query also works:
query{
  structuredContentByKey( key: "35506", siteKey: "Guest" ){
    renderedContentTemplate(templateId: 35566)
  }
}
thumbnail
Jack Bakker, modified 5 Years ago. Liferay Master Posts: 978 Join Date: 1/3/10 Recent Posts
I am leaning to using keys wherever I can, so that I can avoid looking in the database. 
thumbnail
Javier Gamarra, modified 5 Years ago. Expert Posts: 348 Join Date: 2/12/15 Recent Posts
Yes, the idea in the future is to move away from ids (that typically only appear in the database) into keys and external reference codes and show those in the UI.