question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to have ID type in schema for primary keys?

See original GitHub issue

Hi,

it seems that Hasura doesn’t generate the graphql type ID (https://graphql.github.io/graphql-spec/June2018/#sec-ID) for primary keys. Instead it generates a scalar type matching the type of the primary key in the database.

So, in case my primary key is a bigint then in the schema I will have

scalar bigint

type todo {
  id: bigint!
  ...
}

The problem is that other tools (eg. https://github.com/mobxjs/mst-gql) depend on the existence of a unique identifier for types and expects it to be the one field with type ID.

Would it be possible to have a Hasura server setting / environment variable, which enables generation of ID types for primary fields instead of the default mechanism?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:27
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
philschonholzercommented, Jul 21, 2020

The new Remote Relationships with v1.3 do not work with Sanity.io because their id’s are of type ID! which Hasura does not support. Using another type like uuid! gets you an exception when trying to create a new remote relationships:

[
    {
        "definition": {
            "remote_field": {
                "allPackages": {
                    "arguments": {
                        "where": {
                            "_id": {
                                "eq": "$package_id"
                            }
                        }
                    }
                }
            },
            "name": "Package_ID",
            "hasura_fields": [
                "package_id"
            ],
            "remote_schema": "Sanity",
            "table": {
                "schema": "public",
                "name": "Orders"
            }
        },
        "reason": "in table \"Orders\": in remote relationship\"Package_ID\": cannot validate remote relationship because expected type \"ID\" but got \"uuid\"",
        "type": "remote_relationship"
    }
]

A possible solution would be to define the type that is needed by a remote schema (like ID!)

2reactions
adrien-mgcommented, Nov 10, 2020

Do we have any update on this? This is a blocker for us too trying to integrate with Strapi which uses ID as a type for its collections 😞

in table "origin_table": in remote relationship "remote_table": cannot validate remote relationship because expected type "ID" but got "Int"
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I define a different primary key other than _id in ...
In MongoDB, there is no primary key. All you need is an unique: true index and you're good to go. const DocumentSchema =...
Read more >
Mongodb Primary Key: Example to set _id field with ObjectId()
In MongoDB, _id field as the primary key for the collection so that each document can be uniquely identified in the collection.
Read more >
Database Schema Structure - DbSchema
Columns are defined to hold a specific type of data such as numeric, dates, or text. Column names can't be duplicated in a...
Read more >
SHOW PRIMARY KEYS - Snowflake Documentation
Lists primary keys for the specified table, or for all tables in the current or specified schema, or for all tables in the...
Read more >
Primary Keys in Relational Databases - YouTube
Beginner video - an introduction to primary keys in relational databases. Primary Keys need to be UNIQUE and NOT NULL, but not really ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found