hasura / hasura/graphql-engine

Foreign Keys types are not mapped properly in relay

Open
#8,138 2 comments 0 reactions 0 assignees View on GitHub
k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

Let's create a simple relation:
```
table pen {
id uuid, primary key, unique
name text
}
```
```
table pig {
id uuid, primary key, unique
name text
pen uuid references(pen.id)
}
```

Now insert some pens. Now with relay, we might query `pen` it and get a node that looks like this:

```
"node": {
"id": "WzEsICJwdWJsaWMiLCAicGVuIiwgIjcwZmRkYTU1LTI2NGQtNGZhNy1hYTg2LWYzOWZhZTZmNGQwZiJd",
"name": "lxry pig pen"
}
```

Ok, all good so far. Now let's try insert a `pig`:

```
mutation MyMutation {
insert_pig_one(object: {name: "fatty", pen: "WzEsICJwdWJsaWMiLCAicGVuIiwgIjcwZmRkYTU1LTI2NGQtNGZhNy1hYTg2LWYzOWZhZTZmNGQwZiJd"}) {
name
id
}
}
```

Oh, shit. We get an error:
```
{
"errors": [
{
"extensions": {
"path": "$.selectionSet.insert_pig_one.args.object",
"code": "data-exception"
},
"message": "invalid input syntax for type uuid: \"WzEsICJwdWJsaWMiLCAicGVuIiwgIjcwZmRkYTU1LTI2NGQtNGZhNy1hYTg2LWYzOWZhZTZmNGQwZiJd\""
}
]
}
```

This is because it's expecting a uuid, but the relay endpoint never even exposes a uuid! The only way to even find out what it is would be to base-64 code that ID and then extract the uuid manually.

This seems like a pretty serious problem? No?

Contributor guide

Open the contributing guide

Research direction

Reproduce the pen/pig schema, relay query, and insert_pig_one mutation shown in the issue. Trace how relay node IDs are exposed and how the pen foreign key is handled during insertion; done means the relay ID can be used for the foreign-key mutation without requiring manual decoding. No repository files or tests are named, and the issue has had no recent activity.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, postgres
Domain
api, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.