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 – build remarkable experiences at scale

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