0

I am working on a React application and I am facing an issue with Apollo client (@apollo/client 3.3.6). I am not sure if I am missing some configurations or what.

For a query, Apollo client somehow transforms my response i.e., the response that useLazyQuery returns is different that what I can see in Chrome's Network tab.

Network tab is showing the following response: Network tab

However when I print response, it is:

{
    "getProjectSetById": {
        "data": {
            "id": "3d8f3b49-5764-4da6-a9c4-5db0f2904242",
            "name": "New Project Set Name",
            "description": "Kashif's project set",
            "projectSetType": {
                "id": "STF",
                "__typename": "ProjectSetType"
            },
            "companyStandardSet": false,
            "filters": {
                "generalFilters": {
                    "endEquipmentClassification": [
                        false //==========================> This should be "SNE" as in Network tab.
                    ],
                    "projectScope": [],
                    "__typename": "GeneralFilter"
                },
                "companySpecificFilters": {
                    "certificationStatus": [],
                    "projectStatus": [],
                    "organizationUnits": [],
                    "__typename": "CompanySpecificFilter"
                },
                "tagFilters": {
                    "companyTags": [],
                    "userTags": [],
                    "__typename": "TagsFilter"
                },
                "advancedFilters": [],
                "__typename": "ProjectSetFilter"
            },
            "__typename": "ProjectSetWithProjects"
        },
        "__typename": "ProjectSetResult"
    }
}

The code is:

const [fetch, { data, loading }] = useLazyQuery<
            ApolloResponse<QueryResult>
        >(query, {
            variables: { ...queryVariables },
            fetchPolicy: 'no-cache'
        })

useEffect(() => {
     console.log('response', data)
},[queryData])

The configuration I am using with ApolloProvider is:

const httpLink = createHttpLink({
    uri: `${Config.API_SERVER}/graphql`
})


export const client = new ApolloClient({
    link: httpLink
    cache
})

What might be the reason that I am getting a transformed response? Please note that we have an ample codebase and we don't have such issues in any other query calls.

Kashif Nazar
  • 20,775
  • 5
  • 29
  • 46
  • did you ever figure this out? i'm seeing the exact same thing. network inspector shows data, Apollo client seems to remove it. puzzled... – Jared Henderson Sep 15 '22 at 20:47
  • For some reason, it took care of itself. – Kashif Nazar Sep 17 '22 at 09:34
  • 1
    ok, thanks. after much trouble, i figured out my issue had to do with having nested fragments on a union type, which apparently requires you to give apollo some hints to understand the `possibleTypes`, see https://github.com/apollographql/apollo-client/issues/7050 – Jared Henderson Sep 20 '22 at 13:02

0 Answers0