hasura / hasura/graphql-engine

Remote relationsip alias cause `__typename` mismatch between schema and runtime value

Open
#10,779 1 comment 0 reactions 0 assignees View on GitHub
k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

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

### Environment

OSS, Docker

### What is the current behaviour?

When querying a remote relationship with an alias, the `__typename` field from the remote schema loses its configured prefix, resulting in an inconsistency between type names returned by direct remote schema queries and those accessed through relationships.

This causes runtime and type generation mismatches, since GraphQL Code Generator correctly applies the prefix to generated types, but the runtime result (when aliasing is used) does not include it.

### What is the expected behaviour?

The `__typename` field should always include the configured prefix (e.g., `cf_Entry`) regardless of whether the remote relationship is queried directly, or via an alias.

### How to reproduce the issue?

1. Add Contentful (or any remote schema) to Hasura with a configured prefix, e.g., `cf_`.
2. Create a table in Hasura, e.g., `article`.
3. Add a remote relationship from `article` to a Contentful type, e.g., `contentful_entry` → `cf_entry`.
4. Run the following queries:

✅ Works — direct remote schema query

Query:
```graphql
query {
cf_entryCollection(limit: 1) {
items {
__typename
sys { id }
}
}
}
```
Result:
```json
{
"data": {
"cf_entryCollection": {
"items": [
{
"__typename": "cf_Entry",
"sys": { "id": "123" }
}
]
}
}
}
```

✅ Works — remote relationship without alias

Query:
```graphql
query {
article {
id
contentful_entry {
__typename
sys { id }
}
}
}
```
Result:
```json
{
"data": {
"article": [
{
"id": 1,
"contentful_entry": {
"__typename": "cf_Entry",
"sys": { "id": "123" }
}
}
]
}
}
```

✅ Works — direct remote schema query with alias

Query:
```graphql
query {
cfEntries: cf_entryCollection(limit: 1) {
items {
__typename
sys { id }
}
}
}
```
Result:
```json
{
"data": {
"cfEntries": {
"items": [
{
"__typename": "cf_Entry",
"sys": { "id": "123" }
}
]
}
}
}
```

❌ Fails — remote relationship with alias

Query:
```graphql
query {
article {
id
contentfulEntry: contentful_entry {
__typename
sys { id }
}
}
}
```
Result:
```json
{
"data": {
"article": [
{
"id": 1,
"contentfulEntry": {
"__typename": "Entry", // ❌ missing prefix
"sys": { "id": "123" }
}
}
]
}
}
```

### Any possible solutions/workarounds you're aware of?

For now I've given up on alias in gql and map them manually.

### Keywords

Remote, remote schema, remote relationship, __typename, aliases

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the remote relationship alias case described in the issue, comparing __typename with direct and non-aliased relationship queries. Trace the remote relationship response handling for aliased fields and identify where the configured prefix is lost. Done means aliased remote relationships return the same prefixed __typename as the other query paths, with regression coverage for the demonstrated case.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.