question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Variable "$id" of type "ID!"

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chmaccommented, Oct 22, 2019

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?

1reaction
chmaccommented, Oct 22, 2019

@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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Variable \"$id\" of required type \"ID!\" was not provided."
I am trying to query by passing the variable id in the query variable window. This results in an error "Variable \"$id\" of...
Read more >
Query collection by id Variable $id of type ID! was provided ...
Hi I want to get the products from a specific collection but I am getting following error bundle.esm.js?74ca:63 Uncaught (in promise) Error: ...
Read more >
Invalid value for type ID, cannot be converted to AST - Help
If I query a user with with an id as the argument directly from service-users (localhost:5001/) in the sandbox everything works fine. query...
Read more >
Vue apollo error: "Variable "$id" of required type "ID!" was not ...
Hi,. I've written apollo queries and mutations in Vue before but I'm running into an error with the following block of code:
Read more >
vscode-apollo-relay/RelayVariablesInAllowedPosition-test.ts ...
objectContaining({ message: 'Variable "$id" of type "ID" used in position expecting type "ID!".' }) ) }) it("Allows valid fragment", () => {.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found