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

[GROQ] Joins fail depending on depth of query #2017

Closed
andyrichardson opened this issue Sep 21, 2020 · 8 comments
Closed

[GROQ] Joins fail depending on depth of query #2017

andyrichardson opened this issue Sep 21, 2020 · 8 comments

Comments

@andyrichardson
Copy link
Contributor

andyrichardson commented Sep 21, 2020

About

There seems to be a bug in GROQ (running queries in "vision") where joins don't resolve past a depth of one.

This may be related to #1918

Reproduction

Depth of 1 (working)

Reproduction

Here is an example of a query with a join (of depth 1)

*[_type=="library"][0] {
  "books": items -> items[_type=="book"] -> _id
}

Expected result

A flat list of ID's

{ "books": ["book_1", "book_2", "book_3"] }

Actual result ✅

A flat list of ID's

{ "books": ["book_1", "book_2", "book_3"] }

Depth of 2 (failing) <--- the bug

Here is an example of a query with a join (of depth 2)

*[_type=="library"][0] {
  "authors": items -> items[_type=="book"] -> authors[] -> _id
}

Expected result

A flat list of ID's

{ "authors": ["author_1", "author_2", "author_3"] }

Actual result ❌

An empty array

{ "authors": [] }

Depth of 2 (working)

Here is an example of a query with a join (of depth 2)

*[_type=="library"][0] {
  "authors": items -> items[_type=="book"] {
      authors[] -> { _id }
  }
}

Expected result

A nested list of ID's

{ "authors": [
  { "authors": [{ "_id": "author_1" }] },
  { "authors": [{ "_id": "author_2" }, { "_id": "author_3" }] }
] }

Actual result ✅

A nested list of ID's

{ "authors": [
  { "authors": [{ "_id": "author_1" }] },
  { "authors": [{ "_id": "author_2" }, { "_id": "author_3" }] }
] }
@atombender
Copy link
Member

I think Depth of 2 (failing) is wrong. It should be:

*[_type=="library"][0] {
  "authors": items -> items[_type=="book"][] -> authors[] -> _id
  //                                      ^^
}

@samwhale
Copy link

Agreed @atombender, but it seems like even when adding that in it returns an empty array

@andyrichardson
Copy link
Contributor Author

@atombender it doesn't look to be syntax error unfortunately as the prior example also uses items[_type=="book"] and gets a successful response.

From what I can tell with GROQ items[_type=="book"] is equivalent to items[] only with the inclusion of filter.

@atombender
Copy link
Member

Indeed, this may be touching on a long-standing bug with regard to the -> operator with arrays. We are currently working on a big change that already fixes these issues, but it's not planned for release until October at the earliest. In the mean time, I'll see if I can find a workaround for you.

@andyrichardson
Copy link
Contributor Author

Indeed, this may be touching on a long-standing bug with regard to the -> operator with arrays. We are currently working on a big change that already fixes these issues, but it's not planned for release until October at the earliest. In the mean time, I'll see if I can find a workaround for you.

@atombender am I right in thinking this is still an issue? I noticed it's been acknowledged on the docs

Screen Shot 2021-02-10 at 17 51 10

@atombender
Copy link
Member

Yes. The good news is that we have a fix forthcoming in a new API version. I don't have a release date for you yet, but it's possible we're going to allow some beta testing soon. I'll get back to you.

@atombender
Copy link
Member

The new API version is live now. Do you think you can you test your use case against the new version?

@andyrichardson
Copy link
Contributor Author

Thanks @atombender I'll give it a shot 👍

@rexxars rexxars closed this as completed Jun 9, 2021
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

4 participants