algolia / gatsby-plugin-algolia

A plugin to push to Algolia based on graphQl queries
https://yarn.pm/gatsby-plugin-algolia
Apache License 2.0
177 stars 45 forks source link

Cannot return null for non-nullable field SitePage.component. #92

Closed Tanguy-Plf closed 4 years ago

Tanguy-Plf commented 4 years ago

Hello,

I'm having a problem with the plugin running gatsby build.

here is my query :

const pageQuery = `
{
    allSitePage {
        edges {
            node {
               objectID: id
               component
               componentChunkName
               internal {
                   contentDigest
                   type
                   owner
               }
               path
            }
        }
    }
}
`

const queries = [
  {
    query: pageQuery,
    transformer: ({ data }) => data.allSitePage.edges.map(({ node }) => node),
    indexName,
  },
]

module.exports = queries

my gatsby config file :


    {
      resolve: `gatsby-plugin-algolia`,
      options: {
        appId: process.env.GATSBY_ALGOLIA_APP_ID,
        apiKey: process.env.ALGOLIA_ADMIN_KEY,
        queries: require("./src/helper/algoliaQueries")
      },
    },

and the error :


Algolia: query #1: executing query
⠙ onPostBuild

  Error: Cannot return null for non-nullable field SitePage.component.

  - task_queues.js:97 processTicksAndRejections
    internal/process/task_queues.js:97:5

  - async Promise.all

  - async Promise.all

  - async Promise.all

  - async Promise.all

  - gatsby-node.js:97 doQuery
    [Bickeap]/[gatsby-plugin-algolia]/gatsby-node.js:97:20

  - async Promise.all

  - gatsby-node.js:188 Object.exports.onPostBuild
    [Bickeap]/[gatsby-plugin-algolia]/gatsby-node.js:188:5

  - api-runner-node.js:330 runAPI
    [Bickeap]/[gatsby]/src/utils/api-runner-node.js:330:16

not finished onPostBuild - 0.219s

I tried multiple things, but I always goes right to this error. Does someone have a workaround on that ?

Thanks !

Haroenv commented 4 years ago

Looks like your data is causing allSitePage to not have a component for some reason. Do you have this in a reproducible repository?

Tanguy-Plf commented 4 years ago

Hi, thanks for replying that fast,

Unfortunately I can't share the repository since it's for a client and the project is well started now, but here is some information that may be important for this issue :

When I try the query in the localhost:8000/__graphiql/ interface, I have absolutely no errors, it only happens on build time (which makes sense for the plugin but not for the query since it is exactly the same)

I hope these informations will help, ask if I can do anything else,

Haroenv commented 4 years ago

Well, this is hard to debug without me having the exact reproduction that can be inspected. Have you tried removing the component part from the query? You likely don't need that in the search indes

Tanguy-Plf commented 4 years ago

I did remove component and componentChunk and it built fine. If it is not important then it's fine, I copied that from the doc without thinking more about it.

Sorry for wasting your time !

Haroenv commented 4 years ago

No problem at all! I think it's a bug somewhere, but it's more likely to be in Gatsby than here (since we just proxy to their query function). If you see this again, you should open a GitHub issue in Gatsby itself with reproduction. Glad your problem is solved for now!