Skip to content

Commit 9e596d6

Browse files
vladarLekoArts
andauthored
chore(docs): mention SitePage.context removal in v4 migration guide (#33921)
Co-authored-by: Lennart <[email protected]>
1 parent e1162c6 commit 9e596d6

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/docs/reference/release-notes/migrating-from-v3-to-v4.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,53 @@ You can also learn more about this in the [migration guide for source plugins](/
258258

259259
The built-in type `SitePage` now returns the `pageContext` key as `JSON` and won't infer any other information anymore. The `SitePlugin` type now has two new keys: `pluginOptions: JSON` and `packageJson: JSON`.
260260

261+
#### Field `SitePage.context` is no longer available in GraphQL queries
262+
263+
Before v4 you could query specific fields of the page context object:
264+
265+
```graphql
266+
{
267+
allSitePage {
268+
nodes {
269+
context {
270+
foo
271+
}
272+
}
273+
}
274+
}
275+
```
276+
277+
Starting with v4, `context` field is replaced with `pageContext` of type `JSON`.
278+
It means you can't query individual fields of the context. The new query would look like this:
279+
280+
```graphql
281+
{
282+
allSitePage {
283+
nodes {
284+
pageContext # returns full JS object passed to `page.context` in `createPages`
285+
}
286+
}
287+
}
288+
```
289+
290+
If you still need to query individual `context` fields - you can workaround it by providing
291+
a schema for `SitePage.context` manually:
292+
293+
```js
294+
// Workaround for missing sitePage.context:
295+
exports.createSchemaCustomization = ({ actions }) => {
296+
const { createTypes } = actions
297+
createTypes(`
298+
type SitePage implements Node {
299+
context: SitePageContext
300+
}
301+
type SitePageContext {
302+
foo: String
303+
}
304+
`)
305+
}
306+
```
307+
261308
### Removal of `gatsby-admin`
262309

263310
You can no longer use `gatsby-admin` (activated with environment variable `GATSBY_EXPERIMENTAL_ENABLE_ADMIN`) as we removed this functionality from `gatsby` itself. We didn't see any major usage and don't plan on developing this further in the foreseeable future.

0 commit comments

Comments
 (0)