Watch a live product demo πŸ‘€ See how Sanity powers richer commerce 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– build remarkable experiences at scale

The Sanity Composable Content Cloud is the 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.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing