malpaux / apollo-offline Goto Github PK
View Code? Open in Web Editor NEWAn offline toolkit for the Apollo client
Home Page: https://www.npmjs.com/package/apollo-offline
License: BSD 3-Clause "New" or "Revised" License
An offline toolkit for the Apollo client
Home Page: https://www.npmjs.com/package/apollo-offline
License: BSD 3-Clause "New" or "Revised" License
In many cases (e.g. blogs, news, etc.) query results should be updated immediately after a user regains internet access.
Using a __refetch__
flag in a query could indicate that it should be executed again once the detectNetwork
method passed in with the redux-offline config detects a network connection. Additionally, retries of pending queries/mutations could be watched and used to determine the current network status.
I am wondering whether there is a way of preventing the offline behaviour on mutations. It seems to just to not resolve/reject when calling them.
@MLPXBrachmann I'm still cutting my teeth on the React ecosystem, and am getting the above mentioned error when doing the following:
Rehyrdated.js
import React from 'react';
import { connect } from 'react-redux';
export const Rehydrated = connect(({ rehydrated }) => ({ rehydrated }))
((props) => props.rehydrate ? props.children : props.loading);
app.js
import Rehydrated from './components/Rehydrated';
<ApolloProvider store={store} client={client}>
<Rehydrated>
<App>
</Rehydrated>
</ApolloProvider>
Can you tell me what exactly I'm doing incorrectly in Rehyrdated.js and what specifically { rehydrated }
is supposed to reference if any?
Many thanks in advance
Thank you for making this great lib!
In the redux-persist
docs, there's an option to blacklist certain keys in the persistStore(store, [config, callback])
function.
How can this be achieved with this library? Overriding something in redux-offline/lib/defaults
?
Thanks in advance !
Could you please provide an example?
So I updated my ApolloClient.js to use createBatchingNetworkInterface instead of createNetworkInterface, and my app now hangs with the following responses:
Retrying action APOLLO_OFFLINE_QUEUE with delay 1000
middleware.js:50 Retrying action APOLLO_OFFLINE_QUEUE with delay 5000
middleware.js:50 Retrying action APOLLO_OFFLINE_QUEUE with delay 15000
middleware.js:50 Retrying action APOLLO_OFFLINE_QUEUE with delay 30000
middleware.js:50 Retrying action APOLLO_OFFLINE_QUEUE with delay 60000
middleware.js:50 Retrying action APOLLO_OFFLINE_QUEUE with delay 180000
My code is as follows:
const logErrors = {
applyBatchAfterware({ response }, next) {
if (!response) {
response.clone().text().then((bodyText) => {
console.log('...', `Network Error: ${response.status} (${response.statusText}) - ${bodyText}`);
next();
});
} else {
response.clone().json().then(({ errors }) => {
if (errors) {
console.log('...', 'GraphQL Errors:', errors.map(e => e.message));
}
next();
});
}
},
};
const authMiddleware = {
applyBatchMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {}; // Create the header object if needed.
}
getStoredState({ storage: localForage }, (err, state = {}) => {
req.options.headers['authorization'] = state.auth ? `Bearer ${state.auth.token}` : null;
next();
});
}
}
// Create WebSocket client
const wsClient = new SubscriptionClient(SubscriptionClient_URL, {
reconnect: true,
});
export const { enhancer, networkInterface } = offline(
createBatchingNetworkInterface({
uri: networkInterface_URL,
batchInterval: 10,
opts: {
credentials: 'include',
}
}),
);
export const enhancer2 = enhancer(config);
networkInterface.use([authMiddleware]);
if (process.env.NODE_ENV !== 'production') {
networkInterface.useAfter([logErrors]);
}
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient
);
const client = new ApolloClient({
networkInterface: networkInterfaceWithSubscriptions,
dataIdFromObject: (o) => o.id,
addTypeName: true,
shouldBatch: true,
});
networkInterface.setClient(client);
export default client;
What is the issue here?
For whatever reason, redux-offline
isn't installed when I added this to my project...
(Truncated) yarn list
output:
...
├─ [email protected]
│ ├─ graphql-tag@^2.4.2
│ ├─ graphql@^0.10.3
│ └─ zen-observable-ts@^0.4.0
├─ [email protected]
├─ [email protected]
│ └─ default-require-extensions@^1.0.0
├─ [email protected]
├─ [email protected]
│ ├─ delegates@^1.0.0
│ └─ readable-stream@^2.0.6
...
Will this framework do retry during 401?
@MLPXBrachmann So I'm attempting to access the following item (token) in localStorage:
{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHA...","__typename":"SigninPayload"}}
localStorage.getItem('reduxPersist:apollo');
gives me the entire localStocrage state, but when I do
localStorage.getItem('token');
I get a null value back.
What am I overlooking here?
Many thanks in advance
Does this have support for React-Native's AsyncStorage
?
Apollo 2.0 has moved from Redux. Thus the current solution using redux-offline
won't work with Apollo versions from 2.0 onwards.
Has anybody got this working with dev tools?
https://github.com/zalmoxisus/redux-devtools-extension
There are a few workarounds for redux-offline: zalmoxisus/remote-redux-devtools#87
But I'm getting errors back whenever I have any dev tool enhancer involved at the moment.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.