Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(examples) - Add willAuthError to with-refresh-token example (#1608)

authored by

Yanko Valera and committed by
GitHub
277e8694 f6979d5b

+25 -4
+23 -2
examples/with-refresh-auth/src/client/index.js
··· 78 78 return error.graphQLErrors.some(e => e.extensions?.code === 'UNAUTHORIZED'); 79 79 }; 80 80 81 + const willAuthError = ({ operation, authState }) => { 82 + if (!authState) { 83 + // Detect our login mutation and let this operation through: 84 + return ( 85 + operation.kind !== 'mutation' || 86 + // Here we find any mutation definition with the "signin" field 87 + !operation.query.definitions.some(definition => { 88 + return ( 89 + definition.kind === 'OperationDefinition' && 90 + definition.selectionSet.selections.some(node => { 91 + // The field name is just an example, since register may also be an exception 92 + return node.kind === 'Field' && node.name.value === 'signin'; 93 + }) 94 + ); 95 + }) 96 + ); 97 + } 98 + 99 + return true; 100 + }; 101 + 81 102 const client = createClient({ 82 103 url: 'https://trygql.dev/graphql/web-collections', 83 104 exchanges: [ 84 105 dedupExchange, 85 - cacheExchange({}), 86 - authExchange({ getAuth, addAuthToOperation, didAuthError }), 106 + cacheExchange, 107 + authExchange({ getAuth, addAuthToOperation, didAuthError, willAuthError }), 87 108 fetchExchange, 88 109 ], 89 110 });
+1 -1
examples/with-refresh-auth/src/pages/Home.js
··· 8 8 const [isLoggedIn, setIsLoggedIn] = useState(false); 9 9 10 10 const onLoginSuccess = auth => { 11 - setIsLoggedIn(true); 12 11 saveAuthData(auth); 12 + setIsLoggedIn(true); 13 13 }; 14 14 15 15 useEffect(() => {
+1 -1
examples/with-refresh-auth/src/pages/Profile.js
··· 22 22 23 23 {error && <p>Oh no... {error.message}</p>} 24 24 25 - {data && ( 25 + {data?.me && ( 26 26 <> 27 27 <p>profile data</p> 28 28 <p>id: {data.me.id}</p>