{"record":{"id":"417be05cae696602","repo":"gatsbyjs/gatsby","slug":"invalid-plugin-options-for-gatsby-plugin-sitemap","errorCode":null,"errorMessage":"Invalid plugin options for \"gatsby-plugin-sitemap\":\n        \"query\" must be a valid GraphQL query. Received the error \"${e.message}\"","messagePattern":"Invalid plugin options for \"gatsby-plugin-sitemap\":\n        \"query\" must be a valid GraphQL query\\. Received the error \"(.+?)\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sitemap/src/options-validation.js","lineNumber":50,"sourceCode":"            siteMetadata {\n              siteUrl\n            }\n          }\n\n          allSitePage {\n            nodes {\n              path\n            }\n          }\n        }`\n      )\n      .external(pluginOptions => {\n        const query = pluginOptions?.query\n        if (query) {\n          try {\n            parseGraphql(query)\n          } catch (e) {\n            throw new Error(\n              stripIndent`\n        Invalid plugin options for \"gatsby-plugin-sitemap\":\n        \"query\" must be a valid GraphQL query. Received the error \"${e.message}\"`\n            )\n          }\n        }\n      })\n      .description(\n        stripIndent`\n        (GraphQL Query) The query for the data you need to generate the sitemap.\n        It's required to get the site's URL, if you are not fetching it from \\`site.siteMetadata.siteUrl\\`,\n        you will need to set a custom \\`resolveSiteUrl\\` function.\n        If you override the query, you may need to pass in a custom \\`resolvePagePath\\` or\n        \\`resolvePages\\` to keep everything working.\n        If you fetch pages without using \\`allSitePage.nodes\\` query structure\n        you will definately need to customize the \\`resolvePages\\` function.`\n      ),\n    excludes: Joi.array()","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sitemap/src/options-validation.js#L32-L68","documentation":"Thrown during plugin options validation (via pluginOptionsSchema's .external() check) when the `query` option provided to gatsby-plugin-sitemap fails GraphQL parsing. The plugin uses graphql's parseGraphql to validate that the user-supplied query is syntactically valid GraphQL before runtime.","triggerScenarios":"The .external() validator runs parseGraphql(pluginOptions.query); a syntax error, missing closing brace, invalid field name, or non-GraphQL string causes parse to throw, and the catch wraps e.message into this error.","commonSituations":"User copies a partial or malformed GraphQL query into gatsby-config, forgets a closing brace, uses a fragment without defining it, or pastes plain SQL/REST text by mistake.","solutions":["Validate the query string in a GraphQL IDE (GraphiQL) against your schema to find the syntax error.","Ensure the query contains valid GraphQL structure: query { ... } or { ... } with balanced braces.","Start from the default query in the plugin docs and add fields incrementally.","Check for stray template literal interpolation or unescaped quotes inside the query string."],"exampleFix":"// before\noptions: { query: '{ site { siteMetadata { siteUrl } allSitePage { nodes { path ' } } }' }\n// after\noptions: { query: '{ site { siteMetadata { siteUrl } } allSitePage { nodes { path } } }' }","handlingStrategy":"validation","validationCode":"// Validate the GraphQL query before passing to plugin config\nconst { parse } = require('graphql')\ntry {\n  parse(sitemapOptions.query)\n} catch (e) {\n  throw new Error(`Sitemap query is invalid GraphQL: ${e.message}`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  parseGraphql(pluginOptions.query)\n} catch (e) {\n  // handle before build: fix query or remove the option to use default\n}","preventionTips":["Test your GraphQL query in GraphiQL before adding it to gatsby-config.","Start from the plugin's default query and modify incrementally.","Use a linter or pre-build script to validate GraphQL query strings."],"tags":["gatsby","sitemap","graphql","validation","configuration"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}