v5: Mutations with foreign keys that have default values are not-null in the GraphQL schema
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 625
- Avg merge
- 5h 23m
- Merged PRs (30d)
- 24
Description
### Summary
When an SQL table has a foreign key column with a default value, in the GraphQL schema this turns into a not-null input.
### Steps to reproduce
Use this database schema to start Postgraphile:
```sql
CREATE TABLE IF NOT EXISTS "group"
(
"group_id" integer NOT NULL GENERATED ALWAYS AS IDENTITY,
"name" text NOT NULL,
PRIMARY KEY ("group_id")
);
CREATE TABLE IF NOT EXISTS "test"
(
"test_id" integer NOT NULL GENERATED ALWAYS AS IDENTITY,
"group" integer NOT NULL DEFAULT 1,
"group_without_fk" integer NOT NULL DEFAULT 1,
"name" text NULL,
PRIMARY KEY ("test_id"),
FOREIGN KEY ("group") REFERENCES "group"("group_id")
);
```
### Expected results
The `createTest` mutation doesn't require the field `group` as input. The mutation accepts input without `group` as input and that results in the database using the default value as per the SQL schema definition.
### Actual results
The `createTest` mutation requires the field `group`:
### Additional context
postgraphile 5.0.0-rc.1
### Possible Solution
Make foreign key input not required if the SQL schema allows that.
Contributor guide
Assessment
This issue has not been assessed yet.