Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Discussion about missing field in query results for a document in a private GitHub repo

43 replies
Last updated: May 15, 2020
{
      name: 'contacts',
      title: 'Contacts',
      type: 'array',
      of: [
        { type: 'contact_person' }
      ]
    }
May 15, 2020, 9:37 AM
if contact_person is a document you need:

...
type: "array",
of: [{ type: "reference", to: { type: "contact_person" } }],
May 15, 2020, 9:40 AM
It’s not, it’s just embedded in the document
May 15, 2020, 9:41 AM
Do I have to make contact_person in to a document?
May 15, 2020, 9:41 AM
At least everything works in the studio, but my query doesn’t return the contacts field as part of the main document.
May 15, 2020, 9:41 AM
what is a contact_person? 🙂
May 15, 2020, 9:41 AM
Object
May 15, 2020, 9:41 AM
export default {
  name: 'contact_person',
  type: 'object',
  title: 'Contact person',
  fields: [
    {
      name: 'name',
      title: 'Name',
      type: 'string'
    },
    {
      name: 'email',
      title: 'Email',
      type: 'string'
    },
    {
      name: 'field',
      title: 'Field of expertise',
      type: 'string'
    }
  ]
};
May 15, 2020, 9:42 AM
how does your query look?
May 15, 2020, 9:42 AM
export async function preload({ params, query }) {
    const noticeQuery = `*[_type == "notice"][0]`;
    const noticeProjection = `{
      ...,
      body[]{
        ...,
        children[]{
          ...,
          "asset": asset->
        }
      }
    }`;
    
    const notice = await client.fetch(noticeQuery + noticeProjection);
May 15, 2020, 9:42 AM
did you deploy to sanity after you created the object?
May 15, 2020, 9:44 AM
sanity deploy
May 15, 2020, 9:44 AM
I’m running the studio locally (and deployed)
May 15, 2020, 9:44 AM
deployed to Netlify. I’ll try to deploy again.
May 15, 2020, 9:44 AM
Is the field not returned on the front-end side or not even in the playground after running
sanity graphql deploy
?
May 15, 2020, 9:47 AM
I’ve never run
sanity graphql deploy
, I’m deploying our studio only to Netlify and running it locally.
May 15, 2020, 9:47 AM
Can you see the values if you inspect your document within the Studio?
May 15, 2020, 9:47 AM
I could, but for some reason the schema didn’t update after deploying, so the studio offered me to unset the
contacts
May 15, 2020, 9:48 AM
I see, so the deploy might not have happened successfully. Do you see any errors in your Netlify build log?
May 15, 2020, 9:49 AM
I’ll re-build and re-deploy. Locally running I can see the
contacts
field in the studio.
May 15, 2020, 9:49 AM
Re-deployed and now it’s there
May 15, 2020, 9:51 AM
However the query still return nothing!
May 15, 2020, 9:51 AM
const noticeQuery = `*[_type == "notice"][0]`;
    const noticeProjection = `{
      contacts,
      ...,
      body[]{
        ...,
        children[]{
          ...,
          "asset": asset->
        }
      }
    }`;
May 15, 2020, 9:51 AM
It is there when I inspect the data in studio. But not when I query the data.
May 15, 2020, 9:53 AM
What happens if you try without
contacts
and leave
...,
intact?
May 15, 2020, 9:54 AM
Also, are you sure it is there on the specific single
notice
document you are querying with
[0]
?
May 15, 2020, 9:55 AM
What happens if you try without
contacts
and leave
...,
intact?
May 15, 2020, 9:54 AM
Still missing contacts. And there is only one document.
May 15, 2020, 9:55 AM
Also, are you sure it is there on the specific single
notice
document you are querying with
[0]
?
May 15, 2020, 9:55 AM
Re-deployed and now it’s there
May 15, 2020, 9:51 AM
However the query still return nothing!
May 15, 2020, 9:51 AM
const noticeQuery = `*[_type == "notice"][0]`;
    const noticeProjection = `{
      contacts,
      ...,
      body[]{
        ...,
        children[]{
          ...,
          "asset": asset->
        }
      }
    }`;
May 15, 2020, 9:51 AM
If you have the Vision plugin installed in your Studio, are you able to get the data there with the same query?
May 15, 2020, 9:58 AM
If you have the Vision plugin installed in your Studio, are you able to get the data there with the same query?
May 15, 2020, 9:58 AM
If you have the Vision plugin installed in your Studio, are you able to get the data there with the same query?
May 15, 2020, 9:58 AM
No, it’s not there with Vision
May 15, 2020, 9:59 AM
Only when I inspect the document
May 15, 2020, 9:59 AM
It is there when I inspect the data in studio. But not when I query the data.
May 15, 2020, 9:53 AM
That’s strange. Is the document published?
May 15, 2020, 10:04 AM
Yes
May 15, 2020, 10:04 AM
Do you have any repo you could share? (in DM if you prefer) - or a zip of the schema files.
May 15, 2020, 10:04 AM
Wait a sec.
May 15, 2020, 10:04 AM
It’s a private github repo. Who can I add to it?
May 15, 2020, 10:05 AM
(Resolved in DM)
May 15, 2020, 4:39 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?