Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences β†’

I'm having a issue with deploying graphql query something about top level schema error.

11 replies
Last updated: Sep 12, 2020

I'm having a issue with deploying graphql query something about top level schema error. I have tried moving the schema type into it's own object which usually works but I still get the same error for the following code
This is the exact errot I am getting

Error: Encountered anonymous inline image "logoImage" for field/type "LogoImage". To use this field with GraphQL you will need to create a top-level schema type for it. See <https://docs.sanity.io/help/schema-lift-anonymous-object-type>
homepage.js

{
      name: "logoImageWhite",
      type: "logoImage",
      title: "Logo White Image",
    },
    {
      name: "logoImageColor",
      type: "logoImage",
      title: "Logo Color Image",
    },
logoImage.js

export default {
  title: "Logo Image",
  type: "object",
  name: "logoImage",
  fields: [
    {
      name: "logoImage",
      type: "image",
      title: "Logo Image",
      fields: [
        {
          name: "alt",
          type: "string",
          title: "Alt Tag",
          options: {
            isHighlighted: true, // &lt;-- make this field easily accessible
          },
        },
      ],
    },
  ],
};

Sep 11, 2020, 7:40 PM

I know why your getting the error, im trying to find the sanity doc that references this.

Sep 11, 2020, 9:13 PM

On second thought - your probably getting some sort of naming collision - your using logoImage as a name on the top level, and as a fieldName.

Sep 11, 2020, 9:16 PM

hmm I tried

export default {
  title: "Logo Image",
  type: "object",
  name: "logoImage",
  fields: [
    {
      name: "logoImageBlock",
      type: "image",
      title: "Logo Image",
      fields: [
        {
          name: "alt",
          type: "string",
          title: "Alt Tag",
          options: {
            isHighlighted: true, // &lt;-- make this field easily accessible
          },
        },
      ],
    },
  ],
};
and got the error

Error: Encountered anonymous inline image "logoImageBlock" for field/type "LogoImage". To use this field with GraphQL you will need to create a top-level schema type for it. See <https://docs.sanity.io/help/schema-lift-anonymous-object-type>
I thought that was where the naming collision occured so no sure here. Thanks for your help so far

Sep 11, 2020, 10:09 PM

The error has the doc I was looking for! https://www.sanity.io/help/schema-lift-anonymous-object-type

Sep 11, 2020, 10:33 PM

I think what you need to do is lift the fields portion into a new object - then reference that in the

type
section so soemthing like
type: logoImageBlock

Sep 11, 2020, 10:34 PM

Usually doesnt throw an error until you try to deploy graphql

Sep 11, 2020, 10:35 PM

So something like this:

Top Level
export default {
  title: "Logo Image",
  type: "logoImageBlock",
  name: "logoImage"
}

Logo Image Block
export default {
  title: "Logo Image Block",
  type: "image",
  name: "logoImageBlock",
  fields: [
    {... your current fields content}
  ]

}

Sep 11, 2020, 10:35 PM

I dont know if type: image would trigger that too, but thats what I would try next, esp if you are getting that error

Sep 11, 2020, 10:44 PM

Or just clean up the original - instead of making it an object at top level, why not just make logoImage an type:image then add your fields in? Dont know the context though

Sep 11, 2020, 10:46 PM

Thanks so much man, that worked

Sep 12, 2020, 1:12 AM

πŸ‘πŸ‘ I just ran into this on a project when i went to deploy the graph so it was pretty fresh 😁 Sweet that your up and running now

Sep 12, 2020, 1:25 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.