Page MenuHomePhabricator

Asking for unit field on SnakValueQuantity fails
Open, Needs TriagePublicBUG REPORT

Description

Running this query at https://graphql.toolforge.org produces an error:

{
  wikidata {
    entity(id: "Q1297") {
      claims {
        mainsnak {
          datavalue {
            __typename
            ... on SnakValueQuantity {
              SnakValueQuantity: value {
                amount
                unit {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

Error:

  "message": "Invalid URL: 1",
  "locations": [
    {
      "line": 11,
      "column": 17
    }
  ],
  "path": [
    "wikidata",
    "entity",
    "claims",
    91,
    "mainsnak",
    "datavalue",
    "SnakValueQuantity",
    "unit"
  ],
  "extensions": {
    "code": "INTERNAL_SERVER_ERROR",
    "exception": {
      "input": "1",
      "stacktrace": [
        "TypeError [ERR_INVALID_URL]: Invalid URL: 1",
        "    at onParseError (internal/url.js:241:17)",
        "    at parse (internal/url.js:257:3)",
        "    at new URL (internal/url.js:332:5)",
        "    at /data/project/graphql/www/js/types/entity.js:437:14",
        "    at field.resolve (/data/project/graphql/www/js/node_modules/graphql-extensions/dist/index.js:134:26)",
        "    at field.resolve (/data/project/graphql/www/js/node_modules/apollo-server-express/node_modules/apollo-server-core/dist/utils/schemaInstrumentation.js:52:26)",
        "    at resolveFieldValueOrError (/data/project/graphql/www/js/node_modules/graphql/execution/execute.js:467:18)",
        "    at resolveField (/data/project/graphql/www/js/node_modules/graphql/execution/execute.js:434:16)",
        "    at executeFields (/data/project/graphql/www/js/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/data/project/graphql/www/js/node_modules/graphql/execution/execute.js:713:10)"
      ]
    }
  }
},

This is because I am asking for the "unit" field and it returns a "1" (String) instead of a link (String) when no unit is specified. It therefore fails to get the entity.

Event Timeline

Change 779578 had a related patch set uploaded (by Lectrician1; author: Lectrician1):

[labs/tools/graphql@master] graphql: Fix null quantity unit bug This fixes the case in which a unit of '1' (no unit) is returned by the REST API and graphql cannot parse it to be an entity. The endpoint now returns null when this happens instead. Bug: T291637

https://gerrit.wikimedia.org/r/779578

Change 779578 had a related patch set uploaded (by Lectrician1; author: Lectrician1):

[labs/tools/graphql@master] graphql: Fix null quantity unit bug

https://gerrit.wikimedia.org/r/779578