graphql-hooks
Advanced tools
Comparing version 2.0.4 to 3.0.0
{ | ||
"name": "graphql-hooks", | ||
"version": "2.0.4", | ||
"version": "3.0.0", | ||
"description": "Graphql Hooks", | ||
@@ -36,4 +36,4 @@ "main": "src/index.js", | ||
"pretty-quick": "1.10.0", | ||
"react": "16.8.2", | ||
"react-dom": "16.8.2", | ||
"react": "16.8.3", | ||
"react-dom": "16.8.3", | ||
"react-testing-library": "5.9.0" | ||
@@ -40,0 +40,0 @@ }, |
@@ -14,3 +14,4 @@ const ClientContext = require('./ClientContext'); | ||
// alias | ||
useMutation: useClientRequest | ||
useMutation: (query, options) => | ||
useClientRequest(query, { isMutation: true, ...options }) | ||
}; |
@@ -13,2 +13,5 @@ const React = require('react'); | ||
case actionTypes.LOADING: | ||
if (state.loading) { | ||
return state; // saves a render cycle as state is the same | ||
} | ||
return { | ||
@@ -52,8 +55,8 @@ ...state, | ||
const cacheKey = client.getCacheKey(operation, initialOpts); | ||
const intialCacheHit = | ||
const initialCacheHit = | ||
initialOpts.skipCache || !client.cache ? null : client.cache.get(cacheKey); | ||
const [state, dispatch] = React.useReducer(reducer, { | ||
...intialCacheHit, | ||
cacheHit: !!intialCacheHit, | ||
loading: !intialCacheHit | ||
...initialCacheHit, | ||
cacheHit: !!initialCacheHit, | ||
loading: initialOpts.isMutation ? false : !initialCacheHit | ||
}); | ||
@@ -60,0 +63,0 @@ |
@@ -72,2 +72,17 @@ import React from 'react'; | ||
}); | ||
it('sets loading to false if isMutation is passed in', () => { | ||
let fetchData, state; | ||
testHook( | ||
() => | ||
([fetchData, state] = useClientRequest(TEST_QUERY, { | ||
isMutation: true | ||
})), | ||
{ | ||
wrapper: Wrapper | ||
} | ||
); | ||
expect(fetchData).toEqual(expect.any(Function)); | ||
expect(state).toEqual({ cacheHit: false, loading: false }); | ||
}); | ||
}); | ||
@@ -74,0 +89,0 @@ |
@@ -12,5 +12,6 @@ import { useMutation, useClientRequest } from '../../src'; | ||
describe('useMutation', () => { | ||
it('calls useClientRequest with options', () => { | ||
it('calls useClientRequest with options and isMutation set to true', () => { | ||
useMutation(TEST_QUERY, { option: 'option' }); | ||
expect(useClientRequest).toHaveBeenCalledWith(TEST_QUERY, { | ||
isMutation: true, | ||
option: 'option' | ||
@@ -17,0 +18,0 @@ }); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
49450
927