Skip to content

Is it possible to use customized GraphQL fields? #273

@YusukeSano

Description

@YusukeSano

Before you submit:

Question
I have added a field for image URL using Gatsby createResolvers API.

// gatsby-node.js
exports.createResolvers = ({ createResolvers }) => {
  createResolvers({
    Post: {
      imageUrl: {
        type: 'String!',
        resolve(source) {
          const getImageUrl = (text) => {
            // The process of extracting the image URL from text
          }
          return getImageUrl(source.text)
        },
      },
    },
  })
}

I can retrieve the value of the field using the following query:

export const query = graphql`
  {
    allPost {
      nodes {
        text # Text containing the image URL
        imageUrl # https://...
      }
    }
  }
`

I have configured the field, but when I execute the query, an error occurs.

// gatsby-config.js
module.exports = {
  //...
  plugins: [
    //... other plugins
    {
      resolve: `@imgix/gatsby`,
      options: {
        defaultImgixParams: { auto: ['compress', 'format'] },
        fields: [
          {
            nodeType: 'Post',
            fieldName: 'imgixImage',
            rawURLKey: 'imageUrl',
          },
        ],
      },
    },
  ],
};

Error:

Error when resolving URL value for node type Post. This probably means that the rawURLKey function in gatsby-config.js is incorrectly set. Please read this project's README for detailed instructions on how to set this correctly.

Is it possible to use customized GraphQL fields?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions