A scalar type was returned, but GraphQL was expecting an object

I want to query using custom DQL in GraphQL and return a scalar type:

schema

type URL {
  url: String!
}

type Query {
 co(tp: String!): Int @custom(dql: """
	query q($tp: string) {
		co(func: type($tp)) {
			count(uid)
		}
	}
	""")
}

query:

query MyQuery {
  co(tp: "URL")
}

response:

{
  "errors": [
    {
      "message": "A scalar type was returned, but GraphQL was expecting an object. This indicates an internal error - probably a mismatch between the GraphQL and Dgraph/remote schemas. The value was resolved as null (which may trigger GraphQL error propagation) and as much other data as possible returned.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "co"
      ]
    }
  ],
  "data": {
    "co": null
  },
...
...

Why is GraphQL expecting an object? Does GraphQL support returning scalar types from custom DQL? If so, how?

Thx

Currently, scalar as return types are not supported for custom queries/mutations but we plan to support it soon. There is already a request that we have for this and we’ll pick this up next month.

1 Like