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

GraphQL Error Unknown argument slug #2069

Closed
3CordGuy opened this issue Sep 10, 2017 · 3 comments
Closed

GraphQL Error Unknown argument slug #2069

3CordGuy opened this issue Sep 10, 2017 · 3 comments

Comments

@3CordGuy
Copy link
Contributor

3CordGuy commented Sep 10, 2017

Hey everyone. Trying to wire up contentful to a blog using the advanced starter. I've pulled out the filesystem plugins from the mix and am trying to just get a sample post pulled over. However, I'm currently getting an error GraphQL Error Unknown argument slug on starting develop server.

exports.createPages = ({ graphql, boundActionCreators }) => {
  const { createPage } = boundActionCreators
  return new Promise((resolve, reject) => {
    graphql(
      `
      {
        allContentfulBlogPost(limit: 1000) {
          edges {
            node {
              id
              slug
            }
          }
        }
      }
    `
    )
      .then(result => {
        if (result.errors) {
          reject(result.errors)
        }
        const postPage = path.resolve("src/templates/post.jsx");
        _.each(result.data.allContentfulBlogPost.edges, edge => {
          console.log(edge.node);

          createPage({
            path: `/post/${edge.node.slug}`,
            component: postPage,
            context: {
              id: edge.node.id,
              slug: edge.node.slug
            },
          })
        })
      })
      .then(resolve)
  })
}

I have context set to include "slug" which, if I understand correctly, is where it becomes available to the actual post component graphQL query... but it's throwing the error.
Here's some of my console output where this happens

Fetch Contentful data: 404.350ms
success source and transform nodes — 0.552 s
success building schema — 0.548 s
success createLayouts — 0.055 s
⠁ /xxxxxxx/src/templates/post.jsx
{ id: 'c7juaTIcg6cW2wAGKCQuios', slug: 'test-post' }
success createPages — 0.061 s
success createPagesStatefully — 0.023 s
GraphQL Error Unknown argument `slug`

  file: /Users/joshuaweaver/Documents/JoyfulNoise/joyfulnoiseliving/src/templates/post.jsx

   1 |
   2 |   query BlogPostBySlug($slug: String!) {
>  3 |     allContentfulBlogPost(slug: { eq: $slug }) {
     |                           ^
   4 |       title
   5 |       slug
...

I'm pretty new to GraphQL so i could be missing something obvious here. Anything out of the ordinary from what you can see here? Thanks for looking!

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Sep 10, 2017 via email

@3CordGuy
Copy link
Contributor Author

Well, i only had one node/post in Contentful.

Hmm.. I ended up changing the query while it was running from allContentfulBlogPost to contentfulBlogPost and it works now... But, being so new to GraphQL, I'm not sure I understand the difference.

@KyleAMathews
Copy link
Contributor

Oh right, yeah, that query wouldn't have worked. Make sure to try out your queries in GraphiQL before adding them to your components.

"all" is for querying all nodes of a type. Without all is for querying a single item.

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

2 participants