I'm trying to build the post pages imported from WordPress, I run "gatsby develop" and I head to the URL.
The front page flashes up and then I get this error:
Unhandled Rejection (Error): Expected undefined to be a GraphQL schema.
invariant
C:/Users/Phil/Repositories/Zym/node_modules/graphql/jsutils/invariant.mjs:12
assertSchema
C:/Users/Phil/Repositories/Zym/node_modules/graphql/type/schema.mjs:25
validateSchema
C:/Users/Phil/Repositories/Zym/node_modules/graphql/type/validate.mjs:31
graphqlImpl
C:/Users/Phil/Repositories/Zym/node_modules/graphql/graphql.mjs:44
(anonymous function)
C:/Users/Phil/Repositories/Zym/node_modules/graphql/graphql.mjs:20
graphql
C:/Users/Phil/Repositories/Zym/node_modules/graphql/graphql.mjs:18
The query which is highlighted in my 'PostTemplate.js':
export const query = graphql`
query($id: String!) {
wordpressPost(id: { eq: $id }) {
date
title
slug
content
categories {
name
}
}
}
`;
I run the same query through the GraphiQL interface and it sends me data...
Really unsure as to what I'm doing wrong here, see code bellow from gatsby-node.js
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions
return graphql(`
{
allWordpressPost {
edges {
node {
id
slug
status
}
}
}
}
`)
.then(result => {
if (result.errors) {
result.errors.forEach(e => console.error(e.toString()))
return Promise.reject(result.errors)
}
const postTemplate = path.resolve(`./src/templates/PostTemplate.js`)
const posts = result.data.allWordpressPost.edges
_.each(posts, ({ node: post }) => {
createPage({
path: `/${post.slug}/`,
component: postTemplate,
context: {
id: post.id,
slug: post.slug
},
})
})
})
})
I've tried updating gatsby-cli -g, and uninstalled node_modules.
Hi @pcollins089!
Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it. I wonder if you could create it using example project and (if possible) give us access to your wordpress API so that we can experiment with it.
If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.
Thanks for using Gatsby! :purple_heart:
Hey @freiksenet,
Thanks for getting back to me on this! really appreciate it. I've stripped back the project and posted it in this Repo: https://github.com/pcollins089/zym
@pcollins089 Thanks for the reproduction! At line 2 of PostTemplate.js you should change.
import { graphql } from "graphql"
to
import { graphql } from "gatsby"
You are importing a function that runs graphql queries from graphql-js library, while what you want is graphql template tag from Gatsby.
Waow.... Thank you so much for helping me out with this!! Feeling rather silly that it was that simple haha!
It seems like the issue got resolved :)
I'll close the issue, feel free to re open if it's not the case.
Most helpful comment
@pcollins089 Thanks for the reproduction! At line 2 of
PostTemplate.jsyou should change.to
You are importing a function that runs graphql queries from graphql-js library, while what you want is graphql template tag from Gatsby.