hasura / hasura/graphql-engine

Server: Error when Renaming a computed field in GraphQL API

Open
#8,699 0 comments 1 reaction 0 assignees View on GitHub
c/server k/bug t/native-dbs
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: 2.8.4

### Environment

Cloud

### What is the current behaviour?

Computed field in GQL can't use a column name same a s a DB column name (e.g. "id"), even when the DB column name is mapped to a different column name (e.g. "_id") in GQL.

### What is the expected behaviour?

It should be possible to name a computed field to any value (including a DB column name), as long as it doesn't have a naming conflict with an existing GQL column name.

### How to reproduce the issue?

1. Create a Hasura cloud project and add a database.
2. Create and track table with the following schema:

```
CREATE TABLE test_cast_1
(
id int NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
name TEXT,
net_worth bigint
);
```

3. [Rename](https://hasura.io/docs/latest/graphql/core/databases/postgres/schema/custom-field-names/#introduction) the "id" column to "_id" in GQL.

![Rename Field in GQL](https://user-images.githubusercontent.com/101733366/179577103-8b73725c-b946-46ef-9213-161038741788.png)

4. [Define an SQL function](https://hasura.io/docs/latest/graphql/core/databases/postgres/schema/custom-functions/#pg-create-sql-functions):

```
CREATE FUNCTION stringify_networth(test_value test_cast_1)
RETURNS TEXT AS $$
SELECT test_value.net_worth
$$ LANGUAGE sql STABLE;
```

5. [Add a computed field](https://hasura.io/docs/latest/graphql/core/databases/postgres/schema/computed-fields/#pg-adding-computed-field) and name it as "id"

![Computed Field Named Id](https://user-images.githubusercontent.com/101733366/179579584-6df2868d-ce2b-416e-b15e-7e29b0a9b982.png)

6. "Save" the computed field. See the following error:

**Inconsistent object: field definition conflicts with postgres column**

### Screenshots or Screencast

![Screen Shot 2022-07-18 at 11 40 02 AM](https://user-images.githubusercontent.com/101733366/179580149-e141be17-0204-4bf5-87f6-d8b2bf881bd4.png)

### Keywords

Computed field, Rename field, SQL function

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.