graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.58k stars 570 forks source link

PostGraphileRelayPreset bug: mutation with "null" foreign key value does not work (returns null) #2063

Closed TitanFighter closed 4 months ago

TitanFighter commented 4 months ago

Summary

In case of PostGraphileRelayPreset mutation with "null" fk value does not work (returns null)

Steps to reproduce

  1. Clone this repo: https://github.com/TitanFighter/ouch-my-finger
  2. Create simple two tables with foreign key:
DROP TABLE IF EXISTS contacts;
DROP TABLE IF EXISTS customers;

CREATE TABLE customers(
    id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    customer_name VARCHAR(255) NOT NULL
);

CREATE TABLE contacts(
    id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    phone VARCHAR(15) NOT NULL,
    customer_id INT REFERENCES customers (id)
);

INSERT INTO customers (customer_name) VALUES ('Some Name');
INSERT INTO contacts (phone, customer_id) VALUES  ('+1111111', 1);
  1. Create Postgre envs:

    export DATABASE_URL=postgres:///my_db
    export DATABASE_SCHEMAS=app_public
  2. Run server: node server-express.mjs

  3. Run mutation:

    mutation MyMutation {
    updateContact(
    input: {
      id: "WyJDb250YWN0IiwxXQ=="
      contactPatch: { phone: "1", customerByCustomerId: null }
    }
    ) {
    contact {
      id
      phone
      customerByCustomerId {
        id
        customerName
      }
    }
    }
    }

Expected results

{
  "data": {
    "updateContact": {
      "contact": {
        "id": "WyJDb250YWN0IiwxXQ==",
        "phone": "1",
        "customerByCustomerId": null
      }
    }
  }
}

Actual results

{
  "data": {
    "updateContact": null
  }
}

Possible Solution

package-lock.json created on 13.12.2023 with "graphile": "^5.0.0-beta.11" fixes the problem.

benjie commented 4 months ago

Fixed in #2064 and released in PostGraphile beta 24.