I'm having a issue with deploying graphql query something about top level schema error.
11 replies
Last updated: Sep 12, 2020
S
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
homepage.js
logoImage.js
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>
{ name: "logoImageWhite", type: "logoImage", title: "Logo White Image", }, { name: "logoImageColor", type: "logoImage", title: "Logo Color Image", },
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 }, }, ], }, ], };
Sep 11, 2020, 7:40 PM
H
I know why your getting the error, im trying to find the sanity doc that references this.
Sep 11, 2020, 9:13 PM
H
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
S
hmm I tried
and got the error
I thought that was where the naming collision occured so no sure here. Thanks for your help so far
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, // <-- make this field easily accessible }, }, ], }, ], };
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>
Sep 11, 2020, 10:09 PM
H
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
H
I think what you need to do is lift the fields portion into a new object - then reference that in the
typesection so soemthing like
type: logoImageBlock
Sep 11, 2020, 10:34 PM
H
Usually doesnt throw an error until you try to deploy graphql
Sep 11, 2020, 10:35 PM
H
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
H
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
H
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
S
Thanks so much man, that worked
Sep 12, 2020, 1:12 AM
H
šš 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
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.