-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
useLazyQuery doesn't allow to populate query in lazy way #9118
Comments
Hey @adduss 👋 I realize its been quite a while since you opened this issue so I appreciate your patience! I'm hoping you've been able to find a solution for this in the mean time. You could get around this limitation (though I'm a bit hesitant to call it that), by passing const DUMMY_QUERY = gql`
query {
dummyQueryDoNotUse
}
`
const [generatedGqlQuery, setGqlQuery] = useState(DUMMY_QUERY);
// ... The execute function returned from getData({
query: generatedGqlQuery,
variables: { type: type }
}) Just as a side note, we wouldn't typically recommend the approach in this issue. Instead we'd encourage you to instead conditionally render your component. The data flow is much clearer that way and you can avoid the need for the function Parent() {
return options && type
? <Child options={options} type={type} />
: <PlaceholderUI />;
}
function Child({ options, type }) {
// No need for useLazyQuery. You can just use `useQuery` instead!
const { data } = useQuery(GenerateQuery(options, type), { variables: { type: type } });
// No more need for useEffect! Your component has all the data it needs for useQuery
} I'm going to go ahead and close this as I don't see anything else actionable here. Again, appreciate the patience on a response! |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hello Apollo Team!
Intended outcome:
I use react and I try to call useLazyQuery, but pass query in lazy way, not in the moment of initialization, but when query will be calculated:
it is happening because useQuery now verify type
verifyDocumentType(query, DocumentType.Query);
(line 31 in src/react/hooks/useQuery.ts), is there any way to overcome this scenario?Actual outcome:
Error: Argument of null passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert your operation into a document
How to reproduce the issue:
Call useLazyQuery with null as query parameter
Versions
It is not working in 3.5.5
It was working in 3.4.16
The text was updated successfully, but these errors were encountered: