groq-js icon indicating copy to clipboard operation
groq-js copied to clipboard

Accessing nested objects fails

Open yesoreyeram opened this issue 3 years ago • 3 comments

First of all, thank you for the amazing work.

When accessing properties deep nested inside object, query fails silently with null data.

simple way to reproduce :

describe('failing', () => {
  it('array', async () => {
    const dataset = {
      users: [
        { name: 'foo', age: 12 },
        { name: 'bar', age: 30 },
      ],
    };
    const query = `*.users`;
    const tree = parse(query);
    const value = await evaluate(tree, { dataset });
    const data = await value.get();
    expect(data).toStrictEqual([
      { name: 'foo', age: 12 },
      { name: 'bar', age: 30 },
    ]);
  });
});

Behaviour in GROQ playground

image

Behaviour in jest

image

yesoreyeram avatar Jan 28 '22 12:01 yesoreyeram

Seems like this problem is occurring in the previous versions too. And this error is also occurring when finding relations. What version of GROQ we are using on groq.dev? as the problem is not occurring there

MathurAditya724 avatar Jan 29 '22 11:01 MathurAditya724

Seems like this problem is occurring in the previous versions too. And this error is also occurring when finding relations. What version of GROQ we are using on groq.dev? as the problem is not occurring there

It looks like groq.dev is using 0.1.3

  • https://github.com/sanity-io/groq-cli/blob/master/package.json#L35

magicfoodhand avatar Jun 11 '22 17:06 magicfoodhand

(*).users seems to work as expected with the latest version

magicfoodhand avatar Jun 11 '22 17:06 magicfoodhand