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

Request: Enable filtering for non array properties contained in an array #4111

Closed
danhounshell opened this issue Feb 17, 2018 · 4 comments
Closed

Comments

@danhounshell
Copy link
Contributor

Description

This was previously raised in #1645, allowing for filtering for a property in an array using the example:

query Foo {
  allX(
    filter: { id: { in: ['1', '2', '3'] } }
  ) {
    ....
  }
}

@KyleAMathews answered that it is already a feature and showed an example using tags: { in: [$tag] }. He is correct, but it only works for properties, like tags, that are arrays. It does not work for properties that are strings. The example above, filtering by id, does not work.

It would be great if in and notin were supported by all property types.

FWIW I was able to work around this by adding an ids field to the node in onCreateNode that is basically just an array with the one single value of the id of the node. Then it my queries I query for fields: { ids: { in: [$ids] } }.

Actual result

Query throws a graphQL error, syntax is not supported.

Expected behavior

Query should resolve and include any nodes with ids of 123, 456 or 789.

Steps to reproduce

1. Perform a graphQL allThings query with a filter for id existing in an array of strings:
filter: { id: { in: ['123', '456', '789'] } }

@adam-kuhn
Copy link

I'm willing to give this a try

@fk fk added the GraphQL label Feb 19, 2018
@pieh
Copy link
Contributor

pieh commented Feb 19, 2018

@adam-kuhn couple hints if You want to implement this:

Here we add operators to filters in schema:

And here's where actual filtering take place - https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/run-sift.js

@adam-kuhn
Copy link

hey... I think this is over my head. So don't expect a solution from me. Thanks for the hints, I'll still attempt to get my head around this, just for the sake of learning

@m-allanson
Copy link
Contributor

No problem, thanks for giving it a shot!

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

No branches or pull requests

5 participants