这是indexloc提供的服务,不要输入任何密码
Skip to content

One to One relationship - column values are already determined #8522

@albttx

Description

@albttx

Version Information

Server Version:
CLI Version (for CLI related issue):

CLI Version : v2.5.2
hasura docker image: hasura/graphql-engine:v2.3.1

I want to upsert data into a nested table, Here is my schemas.

CREATE TABLE users (
    id                  UUID NOT NULL UNIQUE PRIMARY KEY DEFAULT uuid_generate_v4(),
    email               VARCHAR(256) UNIQUE,
    password            VARCHAR(128),
    created_at          TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at          TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    deleted_at          TIMESTAMPTZ
);

CREATE TABLE user_companies (
    user_id             UUID UNIQUE NOT NULL PRIMARY KEY REFERENCES users(id),
    company_name        VARCHAR(256) NOT NULL,
    company_siret       INTEGER      NOT NULL UNIQUE,
    company_naf_code    VARCHAR(256) NOT NULL
);

This is the GraphQL Query

mutation ($user: users_insert_input!) {
  insert_user(object: $user, on_conflict: {
    constraint: users_pkey,
    update_columns: [id]
  }) {
    id
    user_company {
      company_name
    }
  }
}
{
  "user": {
    "id": "8922f66f-2306-419e-ab63-8835b9b72190",
    "user_company": {
      "data": {
        "company_name": "test2",
        "company_naf_code": "43",
        "company_siret": 43
      },
      "on_conflict": {
        "constraint": "user_companies_pkey",
        "update_columns": ["company_name"]
      }
      
    }
  }
}

And this is the output

{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_user.args.object[0].user_company",
        "code": "validation-failed"
      },
      "message": "cannot insert object relationship \"user_company\" as \"id\" column values are already determined"
    }
  ]
}

Noticed that:

  • This simple insert work
{
  "user": {
    "email": "test@gmail.com",
    "user_company": {
      "data": {
        "company_name": "test2",
        "company_naf_code": "42",
        "company_siret": 4
      }
    }
  }
}
  • Using the email as constraint works, (I can upsert)
mutation ($user: users_insert_input!) {
  insert_user(object: $user, on_conflict: {
    constraint: users_email_key,
    update_columns: [email]
  }) {
    id
    user_company {
      company_name
    }
  }
}
{
  "user": {
    "email": "test42@gmail.com",
    "user_company": {
      "data": {
        "company_name": "test2",
        "company_naf_code": "42",
        "company_siret": 42
      },
      "on_conflict": {
        "constraint": "user_companies_pkey",
        "update_columns": ["company_name"]
      }
      
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    k/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions