Next.js OpenGraph query error - "Ouch! The query has some errors!"

I have some strange error with OpenGraph query in Next.js! While this query works perfectly:

export const BLOG_CATEGORY_QUERY = `
  query CategoryQuery($slug: String) {
    blogCategory(filter: {slug: {eq: $slug}}) {
      id
      name
    }  
  }
`;

this one does not:

export const BLOG_POSTS_CATEGORY_QUERY = `
  query PostsCategoryQuery($category: String) {
    allPosts(first: "10", filter: {category: {eq: $category}}) {
      dateCreated
      excerpt
      slug
      title
      author
      cover {
        responsiveImage(imgixParams: {fm: webp, w: 500}) {
          ...responsiveImageFragment
        }
      }
      category {
        name
        slug
      }
    }
  }

  ${responsiveImageFragment}
`;

If I use it like this (remove the $category param), then it works:

export const BLOG_POSTS_CATEGORY_QUERY = `
  query PostsCategoryQuery {
    allPosts(first: "10", filter: {category: {eq: "91069418"}}) {
      dateCreated
      excerpt
      slug
      title
      author
      cover {
        responsiveImage(imgixParams: {fm: webp, w: 500}) {
          ...responsiveImageFragment
        }
      }
      category {
        name
        slug
      }
    }
  }

  ${responsiveImageFragment}
`;

Additional information:

  • $category param is sent correctly to the query
  • As soon as I define ($param) in the GraphQL query itself I get error “Ouch! The query has some errors!”

Out of ideas…

This is my graphqlrequest, I really don’t know whats wrong with the query here:

{
  preview: false,
  query: '\n' +
    '  query PostsCategoryQuery($id: Number) {\n' +
    '    allPosts(orderBy: dateCreated_DESC, first: "10", filter: {category: {eq: $id}}) {\n' +
    '      dateCreated\n' +
    '      excerpt\n' +
    '      slug\n' +
    '      title\n' +
    '      author\n' +
    '      cover {\n' +
    '        responsiveImage(imgixParams: {fm: webp, w: 500}) {\n' +
    '          ...responsiveImageFragment\n' +
    '        }\n' +
    '      }\n' +
    '      category {\n' +
    '        name\n' +
    '        slug\n' +
    '      }\n' +
    '    }\n' +
    '  }\n' +
    '\n' +
    '  \n' +
    '  fragment responsiveImageFragment on ResponsiveImage {\n' +
    '    srcSet\n' +
    '    webpSrcSet\n' +
    '    sizes\n' +
    '    src\n' +
    '    width\n' +
    '    height\n' +
    '    aspectRatio\n' +
    '    alt\n' +
    '    title\n' +
    '    base64\n' +
    '  }\n' +
    '\n',
  variables: { id: 91069417 }
}

Solved it. I was using the wrong parameter type. It was supposed to be ItemId insted of String or Number.

This can be closed.

1 Like

Glad to know its working!

I’ll leave the thread open in case anyone has similar problems :slight_smile:

1 Like