I am fetching some data using @apollo/client v3. In Chrome's network tab (http results), I can see it returns data and errors (I am not worried about the error, I know why it is right now.):
{
data: {workItems: [,…]},…},
errors: [{message: "Error trying to resolve position."
}
However in my app, data returns undefined.
Here's my client config:
export const graphqlClient = new ApolloClient({
cache: new InMemoryCache(),
link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.forEach(error =>
console.log(
`[GraphQL error]: ${JSON.stringify(error, null, 2)}`
)
)
}
if (networkError) {
console.log(`[Network error]: ${networkError}`)
}
}),
apolloLink
])
})
And my query:
gql`
query WorkItems($ppm: String) {
workItems(where: { ppm: $ppm }) {
...WorkItemKanban
}
}
${workItemFragment.workItemKanban}
`
const useWorkItemListDataGraphql = (args: {
query: DocumentNode
variables: { parent: string } | { ppm: string }
}) => {
const { variables, query } = args
const { data, error, loading, refetch } = useQuery<
{ workItems: WorkItem[] },
{ parent: string } | { ppm: string }
>(query, {
pollInterval: 180000,
variables
})
// data returns undefined, but error shows the same error as in Chrome's network tab
return { ...data, error, loading, refetch }
}
I am not sure where to start to identify what goes wrong. Loading the data works when there is no error, but I reckon this is not normal behavior, it should always load the same as I can see in Chrome's tab.