Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useQuery only resends the query if options.variables change #60

Closed
bmullan91 opened this issue Feb 26, 2019 · 0 comments
Closed

useQuery only resends the query if options.variables change #60

bmullan91 opened this issue Feb 26, 2019 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@bmullan91
Copy link
Contributor

Environment

  • graphql-hooks version: 3.1.0
  • react version: 16.8.3
  • Browser:

Description

The when calling useQuery(query, options) with different options for example operationName or fetchOptions it does not re-send the query.

How to reproduce

const QUERY = `
  query Operation1 {
    hello
  }

  query Operation2 {
    goodbye
  }
`

// example component that might change operationName based on prop
function MyComponent({ operationName }) {
  const { loading, error, data } = useQuery(QUERY, { options: { operationName } })
}

Suggested solution (optional)

// current
React.useEffect(() => {
    queryReq();
  }, [query, JSON.stringify(opts.variables)]);

// fix
React.useEffect(() => {
    queryReq();
  }, [query, JSON.stringify(opts)]);
@bmullan91 bmullan91 self-assigned this Feb 26, 2019
bmullan91 added a commit that referenced this issue Feb 26, 2019
@bmullan91 bmullan91 added the bug Something isn't working label Feb 26, 2019
bmullan91 added a commit that referenced this issue Feb 26, 2019
bmullan91 added a commit that referenced this issue Feb 27, 2019
* failing test for options change no resending query

* fixes #60

* integration tests

* fixes #37

* re-add react-testing-library as a dev-dep

* testHook -> renderHook

* re-add cleanup afterEach setup

* use beforeEach + jest.fn in integration tests

* add test for SSR cacheHit render count

* use allOpts in useEffect check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant