graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

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

Open a1mak opened this issue 2 months ago • 1 comments

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_entrycf_entry.
  4. Run the following queries:

✅ Works — direct remote schema query

Query:

query {
  cf_entryCollection(limit: 1) {
    items {
      __typename
      sys { id }
    }
  }
}

Result:

{
  "data": {
    "cf_entryCollection": {
      "items": [
        {
          "__typename": "cf_Entry",
          "sys": { "id": "123" }
        }
      ]
    }
  }
}

✅ Works — remote relationship without alias

Query:

query {
  article {
    id
    contentful_entry {
      __typename
      sys { id }
    }
  }
}

Result:

{
  "data": {
    "article": [
      {
        "id": 1,
        "contentful_entry": {
          "__typename": "cf_Entry",
          "sys": { "id": "123" }
        }
      }
    ]
  }
}

✅ Works — direct remote schema query with alias

Query:

query {
  cfEntries: cf_entryCollection(limit: 1) {
    items {
      __typename
      sys { id }
    }
  }
}

Result:

{
  "data": {
    "cfEntries": {
      "items": [
        {
          "__typename": "cf_Entry",
          "sys": { "id": "123" }
        }
      ]
    }
  }
}

❌ Fails — remote relationship with alias

Query:

query {
  article {
    id
    contentfulEntry: contentful_entry {
      __typename
      sys { id }
    }
  }
}

Result:

{
  "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

a1mak avatar Oct 16 '25 07:10 a1mak

This appears to be a bug where the configured prefix is lost from __typename when aliasing remote relationship fields. Since the prefix becomes part of the actual type name in the unified schema, it should be included regardless of aliasing.

I've raised this to the team, thanks for reporting @a1mak 🙏

robertjdominguez avatar Oct 31 '25 17:10 robertjdominguez