graphile-contrib / postgraphile-plugin-connection-filter

Filtering on PostGraphile connections
MIT License
286 stars 32 forks source link

[BUG] Cannot use nested filters out of the box #145

Closed PedroD closed 3 years ago

PedroD commented 3 years ago

I have seen that we can either use filters in the root of a query, or nest them, as illustrated in the README:

image

However, when I try to use the nested filters, it says that the syntax is not valid.

This is how I setup my test environment for this:

Within the same folder I have this Dockerfile:

FROM node:alpine
LABEL description="Instant high-performance GraphQL API for your PostgreSQL database https://github.com/graphile/postgraphile"

# Install PostGraphile and PostGraphile connection filter plugin
RUN npm install -g postgraphile
RUN npm install -g postgraphile-plugin-connection-filter
RUN npm install -g graphile-build-pg @graphile-contrib/pg-many-to-many

ADD .postgraphilerc.js .postgraphilerc.js

EXPOSE 5000
ENTRYPOINT ["postgraphile", "-n", "0.0.0.0"]

Then my .postgraphilerc.js:

module.exports = {
    options: {
      connection: "postgres://postgres:test@host.docker.internal:5432/conso", // Put here your test DB credentials
      schema: ["public"],
      port: 5000,
      watch: true,
      appendPlugins: "postgraphile-plugin-connection-filter,@graphile-contrib/pg-many-to-many",
      disableDefaultMutations: true,
      graphileBuildOptions: {
        connectionFilterRelations: true, // default: false
        connectionFilterComputedColumns:true
      },
    },
  };

Then my docker-compose.yml

version: "3.3"
services:

    graphql_pgsql:
        container_name: graphql_pgsql
        restart: always
        image: graphql_pgsql
        build: .
        ports:
            - 5000:5000

So, for this two tables:

image

If I try:

{
allMarkFors{
  nodes{
    markForPartnerByMarkForPartnerId(filter:{
      name: {
        startsWith: "Maria"
      }
    }) {
      id
      name
    }
  }
}
}

I will get as a result:

{
  "errors": [
    {
      "message": "Unknown argument \"filter\" on field \"markForPartnerByMarkForPartnerId\" of type \"MarkFor\".",
      "locations": [
        {
          "line": 4,
          "column": 38
        }
      ]
    }
  ]
}
mattbretl commented 3 years ago

This is caused by using an invalid appendPlugins syntax, as described here: https://github.com/graphile-contrib/postgraphile-plugin-connection-filter/issues/141#issuecomment-890690459

mattbretl commented 3 years ago

[semi-automated message] I'm going to close this issue because it's not a bug in the plugin, but please feel free to continue the conversation below. :slightly_smiling_face: