Gatsby: GraphQL Error Unknown argument `slug`

Created on 10 Sep 2017  ·  3Comments  ·  Source: gatsbyjs/gatsby

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!

Most helpful comment

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.

All 3 comments

It's possible a node doesn't have a slug perhaps?

On Sun, Sep 10, 2017, 7:17 AM Josh Weaver notifications@github.com wrote:

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.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/gatsbyjs/gatsby/issues/2069, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEVh7fahni3VfI4tz_PphtJPctw2jV5ks5sg2LWgaJpZM4PSM2E
.

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandonmp picture brandonmp  ·  3Comments

dustinhorton picture dustinhorton  ·  3Comments

KyleAMathews picture KyleAMathews  ·  3Comments

totsteps picture totsteps  ·  3Comments

theduke picture theduke  ·  3Comments