4

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?

1 Answer 1

2

It works for me, I'm able to reproduce this issue my side.

if the graphql query used variables in parameters then always expected to send the value of the query variables to be {}. if we pass query variables value to be null then this issue occurs.

Expected Request:

{"query":"query myquery($uri: String = \"tcm:5-394-64\") \n{ \n
page (cmUri:$uri) {\n id,\n \titemId,\n
\tlastPublishDate,\n title,\n \turl,\n \ttaxonomies{\n
id,key,title\n }\n }\n }\n","variables":{},"operationName":"myquery"}

enter image description here

{"query":"query myquery($uri: String = \"tcm:5-394-64\") \n{ \n
page (cmUri:$uri) {\n id,\n \titemId,\n
\tlastPublishDate,\n title,\n \turl,\n \ttaxonomies{\n
id,key,title\n }\n }\n }\n","variables":{"uri":"tcm:5-295-64"},"operationName":"myquery"}

enter image description here

I hope it helps.

1
  • Thanks, Velu. I don't quite understand why I have to pass an empty variable array but you are correct, it works this way.
    – Quirijn
    Commented Jan 30, 2019 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.