GatsbyCentral / gatsby-awesome-pagination

An opinionated, more awesome approach to pagination in Gatsby
MIT License
109 stars 27 forks source link

Variable "$id" of type "ID!" #24

Closed brycewray closed 4 years ago

brycewray commented 5 years ago

Have been able to get this plugin to work for a blog index, but am having trouble with the instructions for a single post. After several unsuccessful tries working with my existing single-post template, I decided to experiment and replace it with just the code from the example:

import React from "react"
import { graphql } from "gatsby"

export const pageQuery = graphql`
  query($id: ID!, $previousPageId: ID!, $nextPageId: ID!) {
    post: markdownRemark(id: { eq: $id }) {
      html
      frontmatter {
        title
      }
    }
  }
`;
const BlogPost = props => {
  const { pageContext, data } = props;
  const { previousPagePath, nextPagePath, previousPageItem, nextPageItem } = pageContext;
  const { post } = data;

  return (
    <div>
      <h1>{post.frontmatter.title}</h1>
      <div dangerouslySetInnerHTML={{ __html: post.html }} />
      <div>
        {previousPagePath ? (
          <Link to={pageContext.previousPagePath}>
            {previousPageItem.frontmatter.title}
          </Link>
        ) : null}
        {nextPagePath ? (
          <Link to={pageContext.nextPagePath}>
            {nextPageItem.frontmatter.title}
          </Link>
        ) : null}
      </div>
    </div>
  );
}

export default BlogPost

. . . but when I did, I get a failure to compile and this error message:

GraphQL Error Variable "$id" of type "ID!" used in position expecting type "String".

Is there something else I should import? Will greatly appreciate any help anyone's willing to offer.

chmac commented 5 years ago

@brycewray The error suggests that the type of markdownRemark's eq field should be a string and not an ID. What do you see in the /___graphql interface if you look at that field in the docs? Maybe Gatsby has changed the field type...

brycewray commented 5 years ago

@chmac I didn’t use the __graphql UI for this part of the query because I assumed it wouldn’t work, much as when you have to enter the ... rest indicator. If indeed it’s no longer usable in Gatsby, could you suggest an alternative?

brycewray commented 5 years ago

Looking at https://gatsbyjs.org/docs/schema-customization, it seems that “ID!” should still be valid. Or is “$id” the problem?

chmac commented 5 years ago

Is your code copied from the examples folder? Just merged #23 which updates the examples, they had the wrong API. Maybe that's the issue?

brycewray commented 5 years ago

Yes, it was copied from there . I’ll recheck later (currently away from my computer). Thanks!