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

Why $query sends a request to server on component mount? #80

Open
mohesem opened this issue Jan 29, 2021 · 1 comment
Open

Why $query sends a request to server on component mount? #80

mohesem opened this issue Jan 29, 2021 · 1 comment

Comments

@mohesem
Copy link

mohesem commented Jan 29, 2021

I am trying to write a login form.

import { gql } from '@apollo/client';
const LOGIN_ADMIN = gql`
  query LoginAdmin(<STH>) {
    loginAdmin(<STH>) {
      <STH>
    }
  }
`;
const login = query(LOGIN_ADMIN, options);
const onSubmit = () => { 
   login.refetch(<STH>)
}

Until here everything is fine, and refetch query works totally as expected,

$: if ($login) {
   console.log($login.error, $login.loading, $login.data)
}

the problem is $login sends a query to the server when the component is mounting.

Am I missing something or this behavior is normal?

@mohesem mohesem changed the title Why $query sends a request to server on component mount ? Why $query sends a request to server on component mount? Jan 29, 2021
@MrDweebus
Copy link

I think this is why we'd need lazy queries; dev said in this comment that they'd investigate in the future, but I agree that missing the lazy queries makes you have to code in circles to keep from sending lots of random queries from things like search forms.

#53 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants