postgresqlgraphqlmany-to-manypostgraphile

postgraphile - how to enable many to many relation field


I have Uploads table.

Uploads has many-to-many relation with Parties table.

the junction table is Uploads_Parties, it contains: upload_id & party_id as fields.

how can i make postgraphile to consider these relation in the schema generation ?

attempts:

  1. many-to-many plugin - https://github.com/graphile-contrib/pg-many-to-many. after adding the plugin no effect was taking place.
  2. smart tags plugin - https://www.graphile.org/postgraphile/make-pg-smart-tags-plugin/ - i tried adding foreign key relation between the Uploads.upload_id -> Uploads_Parties.upload_id, but then postgraphile throw an error.

Server init code

const SmartTagsPlugin = makePgSmartTagsFromFilePlugin(
  resolve(__dirname, '../../postgraphile.tags.jsonc'),
);
...
appendPlugins: [
        SmartTagsPlugin,
        PgManyToManyPlugin]
...

tags.jsonc

"config": {
    "class": {
      "upload_service.upload": {
        "tags": {
          "foreignKey": [
            "(id) references upload_service.uploads_parties (upload_id)|@fieldName uploadDataSet"
          ]
        }
      }
    }
  }

Solution

  • the solution was the tags.jsonc, only pointing the fk the other way around: uploads.upload_id <- uploads_parties.upload_id.

    "config": {
        "class": {
          "upload_service.uploads_parties": {
            "tags": {
              "foreignKey": [
                "(upload_id) references upload_service.uploads (id)|@fieldName fileUpload"
              ]
            }
          }
        }
      }
    

    i also have these plugins:

        pgSimplifyInflector,
        postgraphilePluginConnectionFilter,
        pgOrderByRelatedPlugin,
        pgAggregatesPlugin,