Graphql-engine: [v1.3.0-beta.2] Error remote relationship: cannot validate remote relationship because expected type \"Int\" but got \"Int\"

Created on 18 Jun 2020  路  11Comments  路  Source: hasura/graphql-engine

Hi

Steps to reproduce:
1) Create table with remote Int Column
2) Add remote scheme with "Int" type
3) Try create remote relationship

[
    {
        "definition": {
            "remote_field": {
                "bot_directions": {
                    "arguments": {
                        "key": "$direction_key"
                    }
                }
            },
            "name": "dk",
            "hasura_fields": [
                "direction_key"
            ],
            "remote_schema": "hasura-backend",
            "table": {
                "schema": "public",
                "name": "bot_groups"
            }
        },
        "reason": "in table \"bot_groups\": in remote relationship\"dk\": cannot validate remote relationship because expected type \"Int\" but got \"Int\"",
        "type": "remote_relationship"
    }
]
remote-joins supporneeds-action

Most helpful comment

Per guidance in Discord preview channel, I'm adding another error example I encountered trying to create a remote relationship with a sanity.io schema. The goal is to store the "likes" by a user on a sanity object in postgres and be able to get back the user's likes and data about the object with a single query.

Steps to reproduce:

  1. Create sanity.io dataset and deploy autogenerated GraphqQL schema for it. Add as remote schema in Hasura instance.
  2. Create table w/ text column
  3. Add remote schema to "id" field on sanity object
  4. Try to create remote relationship

Error

[
    {
        "definition": {
            "remote_field": {
                "Experiences": {
                    "arguments": {
                        "id": "$experience_id"
                    }
                }
            },
            "name": "experience_instance",
            "hasura_fields": [
                "experience_id"
            ],
            "remote_schema": "sanity",
            "table": {
                "schema": "public",
                "name": "likes"
            }
        },
        "reason": "in table \"likes\": in remote relationship\"experience_instance\": cannot validate remote relationship because expected type \"ID\" but got \"String\"",
        "type": "remote_relationship"
    }
]

I also tried with a uuid column but got the same error. I assume the issue is with the ID type on the sanity schema but I am a bit confused with it being a standard gql scalar type that I also assume is pretty common. If it doesn't map to a text or uuid column what would it map to?

All 11 comments

Per guidance in Discord preview channel, I'm adding another error example I encountered trying to create a remote relationship with a sanity.io schema. The goal is to store the "likes" by a user on a sanity object in postgres and be able to get back the user's likes and data about the object with a single query.

Steps to reproduce:

  1. Create sanity.io dataset and deploy autogenerated GraphqQL schema for it. Add as remote schema in Hasura instance.
  2. Create table w/ text column
  3. Add remote schema to "id" field on sanity object
  4. Try to create remote relationship

Error

[
    {
        "definition": {
            "remote_field": {
                "Experiences": {
                    "arguments": {
                        "id": "$experience_id"
                    }
                }
            },
            "name": "experience_instance",
            "hasura_fields": [
                "experience_id"
            ],
            "remote_schema": "sanity",
            "table": {
                "schema": "public",
                "name": "likes"
            }
        },
        "reason": "in table \"likes\": in remote relationship\"experience_instance\": cannot validate remote relationship because expected type \"ID\" but got \"String\"",
        "type": "remote_relationship"
    }
]

I also tried with a uuid column but got the same error. I assume the issue is with the ID type on the sanity schema but I am a bit confused with it being a standard gql scalar type that I also assume is pretty common. If it doesn't map to a text or uuid column what would it map to?

I ran into the same problem.
I'm surprise more people are not seeing this since virtually every remote join will be on a remote ID field but you can't create a source field of that type.

Also got the same problem with sanity.io using v1.3.0-beta.4

Problem can still be reproduced on v1.3.0 release.

The issue here is that the graphql types must be exactly the same for the remote relationship to be valid. You cannot join String with ID as such. Although I do agree that coercing values is useful.

I also agree that ID field is very common identifier type in Remote Schemas and there should be a way to make ID types in Hasura. We already have an issue tracking this: https://github.com/hasura/graphql-engine/issues/2881 . Let's continue discussion in this issue.

As for the OP's issue:

@kuzmi4 Can you give the table definition and a sample remote schema definition which is causing this failure? I am not able to reproduce this.

I made demo scene with same problem

Hasura: https://issues-5133.herokuapp.com/console
Remote scheme: https://glitch.com/edit/#!/honored-clover-jumper?path=index.js%3A35%3A14

Just try add remote relationship

Interestingly i am not able to map string to string field also

  • I have remote query which has String! as input variable (id)

  • In remote relationship , i try to map it to text column of the table

,"reason":"in table \"vam.physical_account\": in remote relationship\"fetch_bal\": cannot validate remote relationship because type \"Account\"only objects or scalar types expected","type":"remote_relationship"}],"path":"$.args[0].args","error":"in table \"vam.physical_account\": in remote relationship\"fetch_bal\": cannot validate remote relationship because type \"Account\"only objects or scalar types expected","code":"constraint-violation"}

@kuzmi4 Thank you for the repro and sorry for the delay. We will fix it ASAP.

@tanmaypatil The error message seems to not talk about the type of Account. It should ideally print that as well. We will fix the error message. Meanwhile, can you show the definition of the remote relationship by showing the API call from the network tab when you try to create this?

@tirumaraiselvan


Please note that account is query type.


request url http://localhost:9693/apis/migrate
Payload { "name": "table_physical_account_create_remote_relationship_map_phy_acct", "up": [ { "type": "create_remote_relationship", "args": { "name": "map_phy_acct", "remote_schema": "phy_acct", "remote_field": { "account": { "arguments": { "id": "$account_number" } } }, "hasura_fields": [ "account_number" ], "table": { "name": "physical_account", "schema": "vam" } } } ], "down": [ { "type": "delete_remote_relationship", "args": { "name": "map_phy_acct", "table": { "name": "physical_account", "schema": "vam" } } } ], "skip_execution": false }

Response is `{"code":"data_api_error","message":"{\"internal\":[{\"definition\":{\"remote_field\":{\"account\":{\"arguments\":{\"id\":\"$account_number\"}}},\"name\":\"map_phy_acct\",\"hasura_fields\":[\"account_number\"],\"remote_schema\":\"phy_acct\",\"table\":{\"schema\":\"vam\",\"name\":\"physical_account\"}},\"reason\":\"in table \\"vam.physical_account\\": in remote relationship\\"map_phy_acct\\": cannot validate remote relationship because type \\"Account\\"only objects or scalar types expected\",\"type\":\"remote_relationship\"}],\"path\":\"$.args[0].args\",\"error\":\"in table \\"vam.physical_account\\": in remote relationship\\"map_phy_acct\\": cannot validate remote relationship because type \\"Account\\"only objects or scalar types expected\",\"code\":\"constraint-violation\"}"}
account query type

@kuzmi4 From the error message it seems that you were trying to create a remote relationship between Int and [Int], if that is the case, it'll be fixed via this PR. The same error may also be thrown if you're trying to join [Int] with Int (which seems unlikely because hasura doesn't support native array types for table columns), but with the above PR the error message will show exactly what types are being attempted to join.

@codingkarthik good news. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anisjonischkeit picture anisjonischkeit  路  3Comments

bogdansoare picture bogdansoare  路  3Comments

tirumaraiselvan picture tirumaraiselvan  路  3Comments

Fortidude picture Fortidude  路  3Comments

leoalves picture leoalves  路  3Comments