Issue with schema type "imageArray" causing deployment error.

8 replies
Last updated: Aug 14, 2020
Hi,
Schema problem. I’m trying to do a ‘graphql deploy’ but get a “Encountered anonymous inline object “image” for field/type “imageArray”. I’ve already defined other fields as a global schema type, but I can’t get this image array to work.

Main file

...
        {
            title: "Other Images",
            name: "imageArray",
            type: "imageArray",
        },
...
imageArray.js

export default {
    name: 'imageArray',
    type: 'array',
    title: 'More Images',
    of: [
        {
            type: 'image',
            options: {
                metadata: ['lqip', 'palette']
            },
            fields: [
                {
                    title: 'Caption',
                    name: 'caption',
                    type: 'string',
                    options: {
                        isHighlighted: true
                    }
                },
                {
                    title: 'Alternative text',
                    name: 'alt',
                    type: 'string',
                    options: {
                        isHighlighted: true
                    }
                },
            ]

        },
    ]
}
Can anyone see what I’m doing wrong, please?
Aug 14, 2020, 7:02 AM
Is your imageArray added to your schema.js file?
Aug 14, 2020, 7:11 AM
Hi User,
Yes,

import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'
import siteSettings from './siteSettings'
import product from './product'
import mainImage from './mainImage'
import imageArray from './imageArray'
import review from './review'
import globalVariables from './globalVariables'

export default createSchema({
    name: 'mySchema',
    types: schemaTypes.concat([
        siteSettings,
        product,
        mainImage,
        imageArray,
        review,
        globalVariables
    ])
})

Aug 14, 2020, 7:15 AM
user T
Any idea, please?
Aug 14, 2020, 7:55 AM
I think what’s causing a problem is the type “array”. Try this instead:
export default {
  name: 'mainImage',
  type: 'image',
  title: 'Image',
  fields: [
    { ... }
  ],
}
And in your document you can do a reference, something like this

    {
      name: 'imagesRef',
      title: 'Images Ref',
      type: 'array',
      of: [ { type: 'mainImage' } ]
    }
Aug 14, 2020, 8:23 AM
You can also use a document for your imageArray if you have more fields
Aug 14, 2020, 8:24 AM
It should give you something like this
Aug 14, 2020, 8:25 AM
Thank you - it looked like the “array” was causing the problem. I’ll try this now
Aug 14, 2020, 8:26 AM
user T
Worked like a charm. Sincere thanks for your help! 👍👍
Aug 14, 2020, 8:38 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.

Was this answer helpful?