Graphql-engine: How to have ID type in schema for primary keys?

Created on 14 Sep 2019  路  9Comments  路  Source: hasura/graphql-engine

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?

server ideas

Most helpful comment

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!)

All 9 comments

I was looking for the same thing. It would be quite useful!

For example apollo uses it for caching.

any update on this?

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!)

@philschonholzer One workaround suggested in community regarding sanity.io is here: https://discord.com/channels/407792526867693568/516590536875048990/727192434391646351

Quoting:

ended up adding a new field with a different id as a string. Not ideal but I don't see a way to change the type for the id schema as its autogenerated. The string works great though. thanks again.

I am getting this same issue, but I actually have an Int type and not ID... which still causes an issue even though the types match.

cannot validate remote relationship because expected type "Int" but got "Int"

I'm attempting to integrate the Monday.com Item schema.

https://monday.com/developers/v2#queries-section-items

Any thoughts when this issue will be resolved?

@kamescg Seems like you might be hitting this issue: https://github.com/hasura/graphql-engine/issues/5133

Is this issue on the roadmap? It has turned into a blocker for us, as we can't use Remote Schemas as-is, since they depend on IDs that are shared across systems (uuids in Hasura).

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 :disappointed:

in table "origin_table": in remote relationship "remote_table": cannot validate remote relationship because expected type "ID" but got "Int"
Was this page helpful?
0 / 5 - 0 ratings