gridsome-source-sanity icon indicating copy to clipboard operation
gridsome-source-sanity copied to clipboard

belongsTo nodes + referenced document filter not returning data

Open bokinga opened this issue 5 years ago • 7 comments

Hi,

After local install 'sanity-gridsome' example and starting dev environment I tried to test belongsTo and filter data for related node, in this case for Post and Author.

I attached graphql playground screenshoots with concrete example.

  1. Author implements belongsTo (founded in schema and docs) but seems like no data is attached.

  2. With Post I tried to use filter for related nodes (authors:author) also existing with docs and implemented but no data returned (when filter removed, 3rd example, all is fine and Authors are listed)

Please, am I doing something wrong? Thanks.

Screen Shot 2020-01-31 at 11 55 55

Environment: node -v v10.16.3

npm -v 6.13.1

gridsome -v @gridsome/cli v0.3.1

sanity -v @sanity/cli version 0.146.0

bokinga avatar Jan 31 '20 11:01 bokinga

Hi, some additional info.

I added new field to sanity Post model, only referencing one Author: { name: 'author', title: 'Author', type: 'reference', to: [{ type: 'author' }] },

1. Again I have no referenced post on the author query using graphql Screen Shot 2020-01-31 at 13 30 09

2. In gridsome.server.js tried to use standard @sanity/client fetch on author with post references and I got results:

Authors: sanity-gridsome-web: { _id: '1b1c7451-c976-48fd-b416-73bf5a356f10', sanity-gridsome-web: name: 'My Name', sanity-gridsome-web: posts: sanity-gridsome-web: [ { title: 'Picture Perfect Cropping with Hotspots and stuff' }, sanity-gridsome-web: { title: 'A CMS I Can use on My Phone. Finally!' }, sanity-gridsome-web: { title: 'Exploration powered by structured content' }, sanity-gridsome-web: { title: 'My First Introduction to Portable Text' }, sanity-gridsome-web: { title: 'My brand new blog powered by Sanity.io' } ] }`

Query: const authorsQuery = '*[_type == "author"] {name, _id, "posts": *[_type == "post" && references(^._id)]{title}}' const authorsParams = {} client.fetch(authorsQuery, authorsParams).then(authors => { console.log('Authors:') authors.forEach(author => { console.log(author) }) })

bokinga avatar Jan 31 '20 12:01 bokinga

Hi! We need to look into this – let us come back to you!

kmelve avatar Feb 01 '20 01:02 kmelve

Great project. Any further thoughts on this issue?

ajrowland avatar Apr 26 '20 16:04 ajrowland

Hi! We haven't gotten around to looking at this yet. We'll update this thread once we have.

kmelve avatar Apr 27 '20 21:04 kmelve

Having the same issue. Tried to follow the "Taxonomy pages" docs but I get no data.

DenisValcke avatar Aug 09 '20 18:08 DenisValcke

Curious about the status of this; I'm having the same issue as well.

riledigital avatar Nov 06 '20 20:11 riledigital

Looks like the issue persists. I've been reading numerous blogs that reference using belongsTo like this. Curious how it worked for these folks!

typeoneerror avatar Sep 07 '21 08:09 typeoneerror