Hi i am using apollo client 3 and i have set up a store using apollo client as below.
export const appConfig = makeVar<AppConfig>({
__typename: 'AppConfig',
layoutType: LayoutType.LAYOUT_TYPE_FULL,
navStyle: NavStyle.NAV_STYLE_MINI_SIDEBAR,
themeColor: ThemeColor.DARK_BLUE,
themeType: ThemeType.THEME_TYPE_DARK,
});
export const appCommon = makeVar<AppCommon>({
__typename: 'AppCommon',
error: '',
loading: false,
message: '',
navCollapsed: false,
pathname: '',
width: 100,
});
export const yaardlyClient = new InMemoryCache({
typePolicies: {
Query: {
fields: {
appConfig: {
read() {
return appConfig();
},
},
appCommon: {
read() {
return appCommon();
},
},
},
},
},
});
as you can see the fields are populated with default fields and they will never be undefined. so when I query them they will always be available. in the statement below the data is typed properly but typescript infers it might be undefined which is not possible.
const { data: appCommonVariable } = useQuery<GetAppCommon>(GET_APP_COMMON);
any know how to fix this?