Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add condition for a table that is related to other(while joining tables) #2009

Closed
Prabhanjali opened this issue Apr 2, 2024 · 8 comments

Comments

@Prabhanjali
Copy link

Prabhanjali commented Apr 2, 2024

Summary

We have two tables AAAA and BBBB. Now I am trying to joining AAAA with BBBB and getting some data based on conditions

{
  AAAA(filter: {ab: {isNull: false}}) {
    nodes {
      id
      BBBB{
        type
      }
    }
    totalCount
  }
}

Here I need to add a condition where my type is "ccdd" in table BBBB

Additional context

@benjie
Copy link
Member

benjie commented Apr 2, 2024

This is more a question for the filter plugin, but something like this:

{
  AAAA(filter: {ab: {isNull: false}, BBBB: { type: { isEqual: "ccdd" } }}) {
    nodes {
      id
      BBBB{
        type
      }
    }
    totalCount
  }
}

You need to turn on relational filters; see: https://github.com/graphile-contrib/postgraphile-plugin-connection-filter?tab=readme-ov-file#connectionfilterrelations

@Prabhanjali
Copy link
Author

What should be the version of the postgraphile for this filter to work?

This filter is not working in this version
"postgraphile": "^4.13.0",
"postgraphile-plugin-connection-filter": "^2.3.0"

@benjie
Copy link
Member

benjie commented Apr 19, 2024

Any release from the last couple years should work; do make sure you read the filter plugins documentation though - especially the part I mentioned above about enabling relational filters.

@Prabhanjali
Copy link
Author

This is not working for me,
image
I am getting the above error.

I have added this connectionFilterRelations: true. But still it is not working
Can you please let me know what is causing the issue?

@benjie
Copy link
Member

benjie commented Apr 22, 2024

Seems like you’re querying field 🟥🟥🟥🟥 on type 🟥🟥🟥🟥, but that field doesn’t exist. You should use GraphiQL or similar to build your query so it will show you what’s wrong.

@Prabhanjali
Copy link
Author

This is the query I am using

{
  Users(
    filter: {userName: {equalTo: "raghav"}, Account: {accountStatus: {equalTo: "active"}}}
  ) {
    nodes {
      userName
      Account {
        accountName
        accountId
        accountStatus
      }
    }
    totalCount
  }
}

Error:
"message": "Field "Account"" is not defined by type "UsersFilter".

@Prabhanjali
Copy link
Author

Hey! I found the issue,
I just missed placing connectionFilterRelations: true inside graphileBuildOptions.

graphileBuildOptions: {
      connectionFilterRelations: true, // default: false
 }

Adding this worked!

@benjie
Copy link
Member

benjie commented Apr 22, 2024

Great; glad it's working! You should note that this is exactly what I linked you to 3 weeks ago and then referenced again 3 days ago.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants