-
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
defaultOptions errorPolicy: 'all' does not take effect in useQuery #6561
Comments
hey @sushruth the repo link you shared is not accessible. |
@abdullahtariq1171 sorry about that! it is public now. Thank you. edit: here is the code snippet anyway - // client.ts
import { SchemaLink } from "@apollo/link-schema";
import { gql } from "@apollo/client";
import { makeExecutableSchema } from "@graphql-tools/schema";
import { InMemoryCache, ApolloClient } from "@apollo/client/core";
const typeDefs = gql`
type Query {
dogs: String
cats: String
}
`;
const schema = makeExecutableSchema({
typeDefs,
resolvers: {
Query: {
dogs: () => {
return "bark";
},
cats: () => {
throw Error('Hail Satan')
}
}
}
});
const apolloCache = new InMemoryCache();
export const graphqlClient = new ApolloClient({
cache: apolloCache,
link: new SchemaLink({ schema })
}); // App.tsx
import { ApolloProvider, gql, useQuery } from "@apollo/client";
import React from "react";
import { graphqlClient } from "./client";
import "./styles.css";
const GET_DOGS = gql`
query GetDogs {
dogs
cats
}
`;
const Compo1: React.FC = () => {
const { data, error } = useQuery(GET_DOGS);
console.log("[Compo1] This is the data - ", data, error);
return null;
};
const Compo2: React.FC = () => {
const { data, error } = useQuery(GET_DOGS, {
errorPolicy: "all"
});
console.log("[Compo2] This is the data - ", data, error);
return null;
};
export default function App() {
return (
<ApolloProvider client={graphqlClient}>
<div className="App">
<Compo1 />
<Compo2 />
<h1>Check console</h1>
</div>
</ApolloProvider>
);
} |
hey, I ran the attached repo locally, looks like the
Further dug into it and it has test which is passing
If you think I'm misunderstanding the issue, please guide me as I haven't used |
@abdullahtariq1171 - The current issue is about using On the same note, it looks like the issue is not present as described in the original description when using Although, the component I updated the repo with a little more cleanup. Please use it to repro once again - https://github.com/sushruth/apollo-client-erorrpolicy-issue Updated component descriptions -const Compo1: React.FC = () => {
const { data, error, loading, called } = useQuery(GET_DOGS);
if(!loading && called) {
console.log("[Compo1] Without explicit errorPolicy - ", data, error?.message);
}
return null;
};
const Compo2: React.FC = () => {
const { data, error, loading, called } = useQuery(GET_DOGS, {
errorPolicy: "all"
});
if(!loading && called) {
console.log("[Compo2] With explicit errorPolicy - ", data, error?.message);
}
return null;
}; |
Related to #6677 |
Looks like default Options are not working properly 😢 |
This was fixed in #6715 - thanks! |
errorPolicy when specified in defaultOptions does not seem to take effect for useQuery when the query has multiple queries within.
Intended outcome:
useQuery must populate
data
anderror
together if one of the multiple queries fails to resolve, when default error policy is'all'
Actual outcome:
only error is populated.
How to reproduce the issue:
A repo that can repro this issue - https://github.com/sushruth/apollo-client-erorrpolicy-issue
Versions
The text was updated successfully, but these errors were encountered: