Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#4492·ent

[entgql] Missing schema qualification for M2M join tables

Author: michaelkruppCreated Mar 26, 2026Updated Mar 26, 2026
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior

When using entgql (specifically the collection templates) with a multi-schema PostgreSQL setup, GraphQL queries that resolve Relay Connections for Many-to-Many (M2M) relationships fail during the totalCount calculation.

The Issue was previously fixed in ent itself in https://github.com/ent/ent/issues/3082 but the entgql collecton templates still have the old behavior: https://github.com/ent/contrib/blame/master/entgql/template/collection.tmpl#L370

The generated code in gql_collection.go (derived from templates/collection.tmpl) initializes the join table using sql.Table(model.ModelTable) but fails to call .Schema(iq.schemaConfig.Table). This results in a SQL query like:

sql
SELECT COUNT(*) FROM "table" WHERE ...

Instead of:

sql
SELECT COUNT(*) FROM "schema"."table" WHERE ...

This causes a relation "..." does not exist error unless the PostgreSQL search_path is manually configured on the connection pool to include the specific schema.

Expected Behavior

The entgql collection templates should be schema-aware, consistent with the core ent templates (as addressed in core issue #3082). The generated join table selector should include the schema configuration so that queries are properly qualified, e.g.:

go
joinT := sql.Table(model.ModelTable)
joinT.Schema(iq.schemaConfig.<relation>) // This call is currently missing

Steps to Reproduce

Steps:

  1. Define an ent schema with an M2M relationship.
  2. Configure the project to use multiple PostgreSQL schemas (e.g., via ent.SchemaConfig).
  3. Enable entgql and use the Relay Connection annotations on the M2M edge.
  4. Attempt to query the connection with the totalCount field from a database connection where the search_path does not include the target schema.
  5. The query will fail with pq: relation "..." does not exist.

Your Environment

Tech Version
Go 1.25.8
Ent 0.14.5
Database Postgreql
Driver pgx

Source: ent/ent

View original on GitHubView discussion on GitHub