Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error [ValidationError]: "error" must be of type object #214

Closed
nmampersand opened this issue Nov 30, 2022 · 10 comments · Fixed by #218
Closed

Error [ValidationError]: "error" must be of type object #214

nmampersand opened this issue Nov 30, 2022 · 10 comments · Fixed by #218

Comments

@nmampersand
Copy link

Hello! I am working on a project using Gatsby, Cloudinary, and Sanity and am running into the error with this plugin:

Failed to validate error [Error [ValidationError]: "error" must be of type object] {
  _original: {
    context: {
      sourceMessage: '[gatsby-transformer-cloudinary] Could not get metadata for undefined > undefined: undefined'
    },
    error: 'Unknown cloud_name',
    pluginName: 'gatsby-transformer-cloudinary',
    text: '[gatsby-transformer-cloudinary] Could not get metadata for undefined > undefined: undefined',
    level: 'ERROR',
    stack: [],
    docsUrl: 'https://gatsby.dev/issue-how-to'
  },
  details: [
    {
      message: '"error" must be of type object',
      path: [Array],
      type: 'object.base',
      context: [Object]
    }
  ]
}

I am only using images already in Cloudinary but have tried configuring it with and without my Cloudinary credentials and receive the same error.

My gatsby-config looks like:

plugins: [
...,
{
    resolve: 'gatsby-source-filesystem',
    options: {
      name: `images`,
      path: `${__dirname}/src/images/`
    },
  }, {
    resolve: `gatsby-source-cloudinary`,
    options: {
      cloudName: process.env.CLOUDINARY_CLOUD_NAME,
      apiKey: process.env.CLOUDINARY_API_KEY,
      apiSecret: process.env.CLOUDINARY_API_SECRET,
    },
  }, {
    resolve: 'gatsby-transformer-cloudinary',
    options: {
      cloudName: process.env.CLOUDINARY_CLOUD_NAME,
      apiKey: process.env.CLOUDINARY_API_KEY,
      apiSecret: process.env.CLOUDINARY_API_SECRET,
      transformTypes: [
        `CloudinaryMedia`,
        `CloudinaryAsset`,
        `SanityCloudinaryAsset`
      ],
    },
  }]
@nmampersand
Copy link
Author

Note: when I do provide the Cloudinary config options to the plugin and run gatsby develop, it does successfully upload my local images to Cloudinary but still throws the above error.

@raae
Copy link
Collaborator

raae commented Nov 30, 2022

That is not a great error message, so we'll make sure to fix that - ie. a better error message.

However the problem seems to be that your SanityCloudinaryAsset GraphQL type does not have the required fields for the plugin to work. It needs at least the fields: publicId and a cloudName.

Could you go to your GraphiQL UI (typically http://localhost:8000/___graphql) and check the shape of SanityCloudinaryAsset?

@nmampersand
Copy link
Author

Thank you! Hmm, it looks like it doesn't have a cloud name:

    {
          "name": "SanityCloudinaryAsset",
          "fields": [
            {
              "name": "_key"
            },
            {
              "name": "_type"
            },
            {
              "name": "public_id"
            },
            {
              "name": "resource_type"
            },
            {
              "name": "type"
            },
            {
              "name": "format"
            },
            {
              "name": "version"
            },
            {
              "name": "url"
            },
            {
              "name": "secure_url"
            },
            {
              "name": "width"
            },
            {
              "name": "height"
            },
            {
              "name": "bytes"
            },
            {
              "name": "duration"
            },
            {
              "name": "tags"
            },
            {
              "name": "created_at"
            },
            {
              "name": "derived"
            },
            {
              "name": "access_mode"
            },
            {
              "name": "_rawDerived"
            }
          ]
        }

@raae
Copy link
Collaborator

raae commented Nov 30, 2022

And the data is not in the shape required by this plugin (something I hope to make configurable in the future). You'll have to make your own nodes base on these nodes. I can give you an example of how to achieve this tomorrow (CET timezone).

@nmampersand
Copy link
Author

That would be great, thank you!

@raae
Copy link
Collaborator

raae commented Dec 1, 2022

I made a question and answered it here: #215 and keeping this issue to reference when fixing the not optimal error message. Let me know if that works or not.

cloudinary-raae pushed a commit that referenced this issue Dec 20, 2022
)

When sourcing data every sourced item might _not_ be be valid. Instead
of stopping the build an error will be logged.

Make sure to check if `gatsbyImageData` is not null before using in the
`GatsbyImage` component.

Closes #214
github-actions bot pushed a commit that referenced this issue Dec 20, 2022
# [3.1.0](v3.0.1...v3.1.0) (2022-12-20)

### Features

* allow invalid source data by making gatsbyImageData nullable ([#218](#218)) ([acf28f9](acf28f9)), closes [#214](#214)
@github-actions
Copy link

🎉 This issue has been resolved in version 3.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Dec 20, 2022
# [4.2.0](v4.1.0...v4.2.0) (2022-12-20)

### Bug Fixes

* gatsbyImageData generates http urls, not https ([#210](#210)) ([3508cd3](3508cd3)), closes [#209](#209)
* peer dependency (gatsby-plugin-image) ([#212](#212)) ([3f40130](3f40130))

### Features

* allow invalid source data by making gatsbyImageData nullable ([#218](#218)) ([acf28f9](acf28f9)), closes [#214](#214)
@github-actions
Copy link

🎉 This issue has been resolved in version 4.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@raae
Copy link
Collaborator

raae commented Feb 13, 2024

I would be forever grateful if you tested the newest beta nmampersand . It adds support for Sanity sourced Cloudinary assets by letting you configure the mapping of data.

yarn add gatsby-transformer-cloudinary@4.6.0-beta.1

Take a look at the documentation and let me know how it goes so I may improve if needed.

@raae
Copy link
Collaborator

raae commented Jun 6, 2024

@nmampersand, have you been able to test the 4.6.0-beta.1? Looking to make this a current version, but would love an external test before I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants