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

11 replies
Last updated: Jan 28, 2026
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, // <-- make this field easily accessible
          },
        },
      ],
    },
  ],
};

AI Update

I can see the issue! You're getting this error because you have a nested image type inside your logoImage object, and the image type itself has fields (the alt text). This creates what GraphQL sees as an "anonymous inline" structure that's too deeply nested.

The problem is in your logoImage.js schema - you have an object type that contains an image field with additional fields. GraphQL needs flatter structures.

Here's how to fix it:

Option 1: Simplify by using the image type directly (Recommended)

Instead of wrapping the image in an object, just use the image type with its fields directly in your homepage.js:

// In homepage.js
{
  name: "logoImageWhite",
  type: "image",
  title: "Logo White Image",
  fields: [
    {
      name: "alt",
      type: "string",
      title: "Alt Tag",
      options: {
        isHighlighted: true,
      },
    },
  ],
},
{
  name: "logoImageColor",
  type: "image",
  title: "Logo Color Image",
  fields: [
    {
      name: "alt",
      type: "string",
      title: "Alt Tag",
      options: {
        isHighlighted: true,
      },
    },
  ],
}

Option 2: Flatten your logoImage object

If you need the object wrapper for other reasons, flatten it by removing the nested image and putting the fields at the object level:

// logoImage.js
export default {
  title: "Logo Image",
  type: "object",
  name: "logoImage",
  fields: [
    {
      name: "asset",
      type: "reference",
      to: [{type: "sanity.imageAsset"}],
      title: "Image Asset",
    },
    {
      name: "alt",
      type: "string",
      title: "Alt Tag",
    },
  ],
};

The core issue is that GraphQL can't handle the nesting pattern of object β†’ image β†’ fields. As explained in the Sanity documentation on object types and this answer about GraphQL inline images, you need to avoid deeply nested anonymous structures when using GraphQL.

After making these changes, redeploy your GraphQL schema and the error should be resolved!

Show original thread
11 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?