hasura / hasura/graphql-engine
Server: Error when Renaming a computed field in GraphQL API
- 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.

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"

6. "Save" the computed field. See the following error:
**Inconsistent object: field definition conflicts with postgres column**
### Screenshots or Screencast

### Keywords
Computed field, Rename field, SQL function
Contributor guide
Assessment
This issue has not been assessed yet.