Skip to content

Remote relationsip alias cause __typename mismatch between schema and runtime value #10779

@a1mak

Description

@a1mak

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

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