Apollo-client: Accessing apollo store and passing initialState on client side

Created on 2 Feb 2017  路  4Comments  路  Source: apollographql/apollo-client

I am very much interested to know when this will be available. I have couple of scenarios where I would like to use setting/getting data directly from "apollo" part of redux store.

  1. I have multiple container level components which connects to redux store. Since I cant access the "apollo" specific data directly, i have to use "qraphql(query)" to get the data from the store and pass it as props into my component.

  2. If I use the "props" option for "qraphql" config, when the react renders the first time , it throws error when it tries to get data from a nested object since it doesnt exist in the "apollo" part of the store.

Example,

qraphql(query , {
    props: ({data}) => {
        sampleProps: data.a.b.c
    }
})

If i had the option to set the denormalized data into "apollo" store on the app startup, i can populate the store with default data and then i dont have to worry about my data being null|undefined anywhere in my code!

I also tried setting the 'initialState' inside 'ApolloClient' like below, but it didnt work. I dont do Server-side rendering but would have expected it to set the data into "apollo" part of redux store.

const client = new ApolloClient({
initialState: {...}
})

Or do you have any alternative suggestions for the above two problem i have?

Most helpful comment

@yash0087 we're doing some refactoring on the store logic which this is currently blocked on. I expect that we'll have a basic version running next week, and maybe a full example in two weeks or so. Does that answer your question? 馃檪

All 4 comments

@yash0087 we're doing some refactoring on the store logic which this is currently blocked on. I expect that we'll have a basic version running next week, and maybe a full example in two weeks or so. Does that answer your question? 馃檪

Would be great to see it soon as I would be using it straight away!

@helfer Do we have any updates on this functionality?

@yash0087 you can use initialState like you would expect! You just have to put the apollo key in yourself 馃槈

See this test for an example: https://github.com/apollographql/apollo-client/blob/a7ca533c98345bace74a9f18711826ddd233b77c/test/ApolloClient.ts#L9-L21

Was this page helpful?
0 / 5 - 0 ratings