I'm trying to use the new GraphQL features of the content service in Tridion 9. The following GraphQL query works fine:
{
page (cmUri:"tcm:10-1310-64")
{
lastPublishDate,
title
}
}
This returns something like this:
{
"data": {
"page": {
"lastPublishDate": "2019-01-09T17:53:01.893+01:00",
"title": "My page"
}
}
}
Next, I want to use variables in the query (see https://graphql.org/learn/queries/ for information). My new GraphQL query goes like this:
query myquery($uri: String) {
page (cmUri:$uri) {
lastPublishDate,
title
}
}
When I make this request, I need to add a query variable called uri to the request, and it still works like a charm!
So far all good. Now, I want to define a default value for my '$uri' variable in the query:
query myquery($uri: String = "tcm:10-1310-64") {
page (cmUri:$uri) {
lastPublishDate,
title
}
}
When I run this query without query parameters, I would expect the default value (tcm:10-1310-64) to be used. Instead, I get the following response from the server:
{
"timestamp": 1548255295101,
"status": 500,
"error": "Internal Server Error",
"exception": "java.lang.NullPointerException",
"message": "No message available",
"path": "/cd/api"
}
The content service's core log has this:
2019-01-23 15:54:55,100 ERROR [http-nio2-8081-exec-5] [dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is
java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
at graphql.execution.ValuesResolver.coerceArgumentValues(ValuesResolver.java:77)
at graphql.execution.Execution.execute(Execution.java:71)
at graphql.GraphQL.execute(GraphQL.java:554)
at graphql.GraphQL.parseValidateAndExecute(GraphQL.java:496)
...
It seems as if the content service is unable to resolve default variables.
Is this perhaps a bug? Or am I doing something wrong?