{"record":{"id":"1bb6a8bbc7540932","repo":"gatsbyjs/gatsby","slug":"error-executing-the-graphql-query-inside-gatsby-pl","errorCode":null,"errorMessage":"Error executing the GraphQL query inside gatsby-plugin-sitemap:\\n","messagePattern":"Error executing the GraphQL query inside gatsby-plugin-sitemap:\\\\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sitemap/src/gatsby-node.js","lineNumber":30,"sourceCode":"    entryLimit,\n    query,\n    excludes,\n    resolveSiteUrl,\n    resolvePagePath,\n    resolvePages,\n    filterPages,\n    serialize,\n  }\n) => {\n  const { data: queryRecords, errors } = await graphql(query)\n\n  // resolvePages and resolveSiteUrl are allowed to be sync or async. The Promise.resolve handles each possibility\n  const siteUrl = await Promise.resolve(resolveSiteUrl(queryRecords)).catch(\n    err => reporter.panic(`${REPORTER_PREFIX} Error resolving Site URL`, err)\n  )\n\n  if (errors) {\n    reporter.panic(\n      `Error executing the GraphQL query inside gatsby-plugin-sitemap:\\n`,\n      errors\n    )\n  }\n\n  const allPages = await Promise.resolve(resolvePages(queryRecords)).catch(\n    err => reporter.panic(`${REPORTER_PREFIX} Error resolving Pages`, err)\n  )\n\n  if (!Array.isArray(allPages)) {\n    reporter.panic(\n      `${REPORTER_PREFIX} The \\`resolvePages\\` function did not return an array.`\n    )\n  }\n\n  reporter.verbose(\n    `${REPORTER_PREFIX} Filtering ${allPages.length} pages based on ${excludes.length} excludes`\n  )","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sitemap/src/gatsby-node.js#L12-L48","documentation":"In gatsby-plugin-sitemap's onPostBuild (gatsby-node.js:29-34), after attempting to resolve the site URL, the plugin checks if the graphql(query) call returned errors. If the GraphQL query has syntax errors, schema errors, or returns partial data with errors, reporter.panic fires with the errors array. The default query selects site URL and all page paths; a custom query option could also introduce errors.","triggerScenarios":"The site GraphQL query fails: schema not built correctly, a custom 'query' option has a syntax error, or a referenced type/field doesn't exist. The Gatsby build has schema issues that cause GraphQL resolution errors.","commonSituations":"Custom query option referencing fields that don't exist in the schema. Gatsby schema customization conflicts. Plugin ordering issues where schema isn't ready. Broken GraphQL fragments in the custom query.","solutions":["Read the errors array in the panic output — it contains the specific GraphQL validation/resolution errors","If using a custom query option, test it in the GraphiQL playground at http://localhost:8000/__graphql","Remove the custom query to use the default and see if the error persists","Fix any schema issues reported by other plugins earlier in the build"],"exampleFix":"// before: custom query with a non-existent field\n{\n  resolve: `gatsby-plugin-sitemap`,\n  options: {\n    query: `\n      {\n        site {\n          siteMetadata {\n            siteUrl\n            nonExistentField // causes GraphQL error\n          }\n        }\n      }\n    `,\n  },\n},\n\n// after: remove the invalid field or use the default query\n{\n  resolve: `gatsby-plugin-sitemap`,\n  // uses default query automatically\n},","handlingStrategy":"validation","validationCode":"// Test the sitemap GraphQL query before building\n// Run this in the GraphiQL playground or via a script:\nasync function validateSitemapQuery(graphql) {\n  const { errors, data } = await graphql(sitemapQuery)\n  if (errors) {\n    throw new Error(`Sitemap query failed: ${errors.map(e => e.message).join(', ')}`)\n  }\n  if (!data) {\n    throw new Error('Sitemap query returned no data')\n  }\n}","typeGuard":null,"tryCatchPattern":"// The plugin catches GraphQL errors at the top level.\n// As a consumer, validate the query shape beforehand:\nconst result = await graphql(query)\nif (result.errors) {\n  console.error('Query errors:', result.errors)\n  // fix before building\n}","preventionTips":["Test custom sitemap queries in GraphiQL before deploying","Keep the default query unless you have a specific need to customize","Ensure no other plugin is breaking the GraphQL schema"],"tags":["sitemap","graphql","configuration","validation"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}