[entgql] Missing schema qualification for M2M join tables
- 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:
SELECT COUNT(*) FROM "table" WHERE ...Instead of:
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.:
joinT := sql.Table(model.ModelTable)
joinT.Schema(iq.schemaConfig.<relation>) // This call is currently missingSteps to Reproduce
Steps:
- Define an
entschema with an M2M relationship. - Configure the project to use multiple PostgreSQL schemas (e.g., via
ent.SchemaConfig). - Enable
entgqland use theRelay Connectionannotations on the M2M edge. - Attempt to query the connection with the
totalCountfield from a database connection where thesearch_pathdoes not include the target schema. - 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