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

Support the in operator for an array of objects #6315

Merged
merged 6 commits into from
Jul 11, 2018

Conversation

LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Jul 5, 2018

While using Prismic.io as my data source I encountered the problem that I can't filter for tags anymore like with using markdown. I found this issue:
#3643
Kyle suggested that the tests should be modified first so that other people (who can actually fix that 😆 ) can figure it out.

Would be cool of course if the initial request of the issue could be done, not only my issue with Prismic. Feel free to edit this PR to make it work 👍

I added everything like Prismic is outputting it and how GraphiQL suggests the query/filter. At the moment the result is null. The can filter for Prismic tags was just a random name, there's probably a better solution.

Query output:
image

Filter attempt:
image

Filter with query variable:
image

@LekoArts LekoArts requested a review from m-allanson July 5, 2018 20:18
@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 5, 2018

Deploy preview for using-drupal ready!

Built with commit 3e0839d

https://deploy-preview-6315--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 5, 2018

Deploy preview for gatsbygram ready!

Built with commit 3e0839d

https://deploy-preview-6315--gatsbygram.netlify.com

@pieh pieh self-assigned this Jul 6, 2018
@pieh
Copy link
Contributor

pieh commented Jul 7, 2018

So main thing here is that we shouldn't even use in operator for array of objects (in sift that will only really work for scalars or array of scalars - it uses Array.indefOf, so it would never work for newly construct objects). We should use elemMatch.

As this never actually worked I think it wouldn't be breaking change to change from in to elemMatch operator in schema?

KyleAMathews
KyleAMathews previously approved these changes Jul 7, 2018
Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @pieh! And yeah, since this never worked, this wouldn't be a breaking change (at worst, what was a null result for someone's site now returns data).

Merge and release whenever you're ready.

@LekoArts LekoArts changed the title Add support for arguments on GraphQL fields that return arrays Support the in operator for an array of objects Jul 7, 2018
@LekoArts
Copy link
Contributor Author

LekoArts commented Jul 7, 2018

@pieh Cool, thanks for the fix! 😊

@LekoArts
Copy link
Contributor Author

LekoArts commented Jul 9, 2018

@pieh so ready to merge? Will test it immediately then ☺️

@pieh
Copy link
Contributor

pieh commented Jul 9, 2018

Not yet, as mentioned in my comment - I need to change operator name to elemMatch which fits better to what this operator do than in - still need to update code that does that for fields created by setFieldsOnGraphQLNodeType api.

Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@m-allanson m-allanson merged commit ce03884 into gatsbyjs:master Jul 11, 2018
@m-allanson
Copy link
Contributor

Released as gatsby@2.0.0-beta.22

@LekoArts LekoArts deleted the feature/prismic-tags-graphql branch July 11, 2018 09:30
@LekoArts
Copy link
Contributor Author

@m-allanson @pieh Not working for me 😦

image

The second elemMatch doesn't get autocompleted.

image

ErisDS added a commit to ErisDS/gatsby that referenced this pull request Sep 18, 2018
refs gatsbyjs#6315

- In was changed to elemMatch for arrays of objects but this one reference was missed
@ErisDS ErisDS mentioned this pull request Sep 18, 2018
DSchau pushed a commit that referenced this pull request Sep 18, 2018
When trying to filter an array of objects:

- In v1 `in` gets autocompleted, but doesn't work, and `elemMatch` is undefined. 
- In v2 `elemMatch` gets autocompleted and works 🎉 

I got a bit confused between which version I was on, and this lil typo got me even more confused 😅 

Thanks for Gatsby v2 ❤️ 

-----

refs #6315

- In was changed to elemMatch for arrays of objects but this one reference was missed
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

Successfully merging this pull request may close these issues.

5 participants