How to get pageQuery variable from nested context property
See original GitHub issueIt looks like there is no way to access nested context property values in page query variables. Is that correct?
What I’m doing
Right now I’m duplicating the page context variable intl.language
as language
so I can use it as pageQuery
variable.
gatsby-node.js
exports.onCreatePage = ({ page, actions: { createPage, deletePage } }) => {
if (!page.context.intl || page.context.language) {
return;
}
deletePage(page);
createPage({
...page,
context: {
...page.context,
language: page.context.intl.language },
});
};
src/pages/index.jsx
export const query = graphql`
query MyQuery($language: String!) {
# …
}
`
Ideal scenario
Ideally I could access nested context variables by default.
gatsby-node.js
-exports.onCreatePage = ({ page, actions: { createPage, deletePage } }) => {
- if (!page.context.intl || page.context.language) {
- return;
- }
- deletePage(page);
- createPage({
- ...page,
- context: {
- ...page.context,
- language: page.context.intl.language },
- });
-};
src/pages/index.jsx
export const query = graphql`
- query MyQuery($language: String!) {
+ query MyQuery($intl__language: String!) {
# …
}
`
If this is an acceptable addition I’d love to PR.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:7
Top Results From Across the Web
Spring REST - binding GET parameters to nested objects
Since at least Spring 4 you can pass in nested objects separated with "." in the url. In the OP case it would...
Read more >Resolvers - Apollo GraphQL Docs
We want to define resolvers for the numberSix and numberSeven fields of the root Query type so that they always return 6 and...
Read more >Eager Loading of Related Data - EF Core - Microsoft Learn
You can use the Include method to specify related data to be included in query results. In the following example, the blogs that...
Read more >What to do when “this” loses context - freeCodeCamp
The doSomething() method has two nested functions: doAnotherThing() and log() . When service.doSomething() is called, this loses context in the ...
Read more >Nested query | Elasticsearch Guide [8.5] | Elastic
Top-level parameters for nested edit ... (Required, query object) Query you wish to run on nested objects in the path . If an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hmmm, shame this never got any attention. However, I would like to thank you for sharing your solution nevertheless! Helped me out today
This is not a great experience. I would PR fixes and improvements if I got feedback.
But as it is now I’m not inclined to open another issue again. You’re losing potential contributors this way.