graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Server: GraphQL API error with CockroachDB

Open lucarestagno opened this issue 3 years ago • 3 comments
trafficstars

Steps to reproduce:

  • Connect a CockroachDB
  • Select the CrDB in the navigation tree
  • Click on a CDB table in the Nav Tree

You get an error response:

{
  "errors": [
    {
      "extensions": {
        "code": "unexpected",
        "internal": {
          "arguments": [],
          "error": {
            "description": "source SQL:\nSELECT  json_build_object('aggregate', json_build_object('count', COUNT(*) ) ) AS \"root\" FROM  (SELECT   FROM  (SELECT  *  FROM \"public\".\"cdb_posts\"  WHERE ('true')     ) AS \"_root.base\"      ) AS \"_root\"      \n                                                                                                         ^",
            "exec_status": "FatalError",
            "hint": "try \\h SELECT",
            "message": "at or near \"from\": syntax error",
            "status_code": "42601"
          },
          "prepared": true,
          "statement": "SELECT  json_build_object('aggregate', json_build_object('count', COUNT(*) ) ) AS \"root\" FROM  (SELECT   FROM  (SELECT  *  FROM \"public\".\"cdb_posts\"  WHERE ('true')     ) AS \"_root.base\"      ) AS \"_root\"      "
        },
        "path": "$"
      },
      "message": "database query error"
    }
  ]
}

Request URL: /v1/graphql Request Body:

{
  "query": "query TableRows {\n      cdb_posts (limit: 10,offset: 0) {\n          title\nid\n    }\n    cdb_posts_aggregate {\n      aggregate {\n        count\n      }\n    }\n  }",
  "variables": null,
  "operationName": "TableRows"
}

There's an error in the SQL statement executed on the server

SELECT  json_build_object('aggregate', json_build_object('count', COUNT(*) ) ) AS "root" FROM  (SELECT   FROM  (SELECT  *  FROM "public"."cdb_posts"  WHERE ('true')     ) AS "_root.base"      ) AS "_root"      

-> SELECT FROM

lucarestagno avatar Aug 30 '22 14:08 lucarestagno

More information:

If you create a table in cockroachdb and don't specify a primary key cockroachdb generates a primary key for you.

codedmart avatar Aug 31 '22 13:08 codedmart

More information:

If you create a table in cockroachdb and don't specify a primary key cockroachdb generates a primary key for you.

The issue seems related to the fact that CockroacHDB doesn't support this syntax SELECT FROM, while Postgres does.

We opened an issue to the CockroachDB repository to get a more consistent behavior https://github.com/cockroachdb/cockroach/issues/87428 that got closed in favour of https://github.com/cockroachdb/cockroach/issues/83255

lucarestagno avatar Sep 08 '22 13:09 lucarestagno

Discussed after standup: This is blocked by https://github.com/cockroachdb/cockroach/issues/83255 but we have a workaround in progress.

sassela avatar Sep 21 '22 08:09 sassela

Luca verified this works as expected yesterday, closing

sassela avatar Sep 28 '22 08:09 sassela