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

Is it possible to use customized GraphQL fields? #273

Open
2 tasks done
YusukeSano opened this issue Jul 10, 2023 · 0 comments
Open
2 tasks done

Is it possible to use customized GraphQL fields? #273

YusukeSano opened this issue Jul 10, 2023 · 0 comments

Comments

@YusukeSano
Copy link

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?

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

No branches or pull requests

1 participant