Forum Discussion
Looks like you can perfectly pass variables to graphql in handlebars.
Your query ID might need to be an integer: query privateUserStats($id: INT!) {
I tested did by creating a list of categories depending on the depth I set with a prop and this works:
My graphql file:
query firstTest($depth: Int!) {
categories(constraints: {depth: {eq: $depth}, topicsCount: {gt: 0}}) {
edges {
node {
id
topicsCount
viewHref
shortTitle
depth
avatar {
url
}
}
}
}
}
My handlebars file:
{{#gql "firstTest" variables=(hash depth=component.props.category_depth)}}
<ul>
{{#with data.categories.edges as |edges|}}
{{#each edges}}
{{#with node as |categorie|}}
<li>
<img src="{{categorie.avatar.url}}" style="width:30px;"><a href="{{categorie.viewHref}}">{{categorie.shortTitle}}</a> ({{categorie.topicsCount}} topics) - depth: {{categorie.depth}}
</li>
{{/with}}
{{/each}}
{{/with}}
</ul>
{{/gql}}
json file:
{
"id": "firstTest",
"markupLanguage": "HANDLEBARS",
"defaults": {
"config": {
"applicablePages": ["COMMUNITY", "CATEGORY", "FORUM_BOARD"],
"dynamicByCoreNode": false,
"description": "handlebars test"
},
"props": [
{
"id": "category_depth",
"dataType": "STRING",
"list": false,
"label": "list depth",
"description": "level of categories to show",
"control": "INPUT"
}
]
},
"components": [
{
"id": "custom.widget.firstTest"
}
],
"grouping": "CUSTOM",
"aboutThis": null
}
Thanks for the suggestions. It helped lead me to what I think is the root of the problem.
{{#gql "privateUserStats" variables=(hash id=user.id)}}
However, when we query the user collection directly, ID are returned like "user:12345" not simply "12345". I attempted to use the "concat" helper in the handlebars query to prepend "user:" to the variable value, but Khoros threw an exception:
Exception while fetching data (/component/render) : com.github.jknack.handlebars.HandlebarsException: privateUserStats:1:115: could not find helper: 'concat'
Any ideas on how I can prepend "user:" to the variable before sending to the graphQL query?
- MattV2 months agoKhoros Staff
Try this
{{#gql "privateUserStats" variables=(hash id=(join "user:" user.id ""))}}