question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What API should I use to access Redux store through graphql query and update the store back

See original GitHub issue

I’m querying Google Analytics and creating a node with data from it like this:

exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => {
    const data = analytics().then((data) => {
        const node = {
            hits: data,
            internal: {
                type: "AnalyticsNode",
            }
            ...
        };
        createNode(node);
    });
};

then I need to transform this data using information from other nodes, say posts, so I can query these nodes and transform the data inside createPages:

exports.createPages = async ({ graphql, actions }) => {
    const { createPage } = actions;

    const result = await graphql(`
        {
            allPost() { ... }
	    analyticsNode() { ... }	
         }
    `);

    const resultingData = mixData();

and now I need to send this resultingData back to the store to make it queryable inside pages. How do I do that?

If the page is static, I could send it through context inside create pages:

    createPage({
        path: 'analytics',
        component: path.resolve(`./src/templates/analytics.js`),
        context: {
            resultingData
        }
    });

but this wouldn’t work for for dynamic pages, i.e. /app pages rendered using a Router.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ascorbiccommented, May 11, 2020

@maxkoretskyi OK, now I understand a bit better what you’re after. A custom resolver is what you need. Attach as a new field on Analytics, and inside the resolver you can access Post and handle mixData. See https://www.gatsbyjs.org/docs/schema-customization/#createresolvers-api

0reactions
ascorbiccommented, Jun 26, 2020

Hi @maxkoretskyi. No, there’s not currently a way to access that data at runtime. It’s something people have requested, but couldn’t be implemented without running a live GraphQL server for each site.

I’m going to close this now. If you have any more questions, let me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux to Apollo: Data Access Patterns - Apollo GraphQL Blog
Redux isn't a very complicated library, it essentially boils down to a single object {} that stores all of your application's state and...
Read more >
Querying your Redux store with GraphQL - madewithlove
We often already use GraphQL so is there a way we can use it to ... This is a detailed guide about how...
Read more >
GraphQL for the React Redux Developer - Cresta
GraphQL is a popular API query language for clients to access data on servers. Cresta uses GraphQL in different ways to act as...
Read more >
How to update the Redux store after Apollo GraphQL query ...
I would listen to changes in componentDidUpdate and when they happened dispatch an action that will set selectedItem in Redux store
Read more >
Redux Essentials, Part 7: RTK Query Basics
Endpoints can be queries, which return data for caching, or mutations, which send an update to the server. The endpoints are defined using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found