I want to get the data on the dynamic type. For that, I am using fragment in graphql query. Api is working fine in graphql playground but when I am trying to integrate it with react-apollo client it gives me an empty object as well WARNING!heuristic fragment matching going on in console.
It is also working when I am using npm install and npm run start but when I switched to yarn install and yarn run start it gives me an error.
I used IntrospectionFragmentMatcher and set the fetchPolicy as 'cache-and-policy'.
I also shared code for IntrospectionFragmentMatcher for client configuration.
query GetContentSections($contentPageId: Int) {
contentSection {
searchContentSections(contentPageId: $contentPageId, status: [ACTIVE]) {
id
contentLayoutId
sort
sectionContainers {
id
sort
snippets {
id
sort
type: __typename
...quote
...text
...image
...video
...audio
...button
...popup
...map
...code
...app
}
}
}
}
}
fragment text on ContentSnippetTextType{
text
}
fragment image on ContentSnippetImageType{
assetId
}
fragment video on ContentSnippetVideoType{
assetId
}
fragment audio on ContentSnippetAudioType{
assetId
}
fragment button on ContentSnippetButtonType{
hyperlink
innerText
foregroundColor
fontColor
backgroundColor
}
fragment popup on ContentSnippetPopupType{
text
link
}
fragment quote on ContentSnippetQuoteType {
text
author
}
fragment map on ContentSnippetMapType {
longitude
latitude
zoom
}
fragment code on ContentSnippetCodeType {
cssFileLocation
htmlFileLocation
javascriptFileLocation
}
fragment app on ContentSnippetAppType {
appId
}
const fm = new IntrospectionFragmentMatcher({
introspectionQueryResultData:{
"__schema": {
"types": [
{
"kind": "INTERFACE",
"name": "ContentSnippetInterface",
"possibleTypes": [
{ "name": "ContentSnippetAppType" },
{ "name": "ContentSnippetAudioType" },
{ "name": "ContentSnippetButtonType" },
{ "name": "ContentSnippetCodeType" },
{ "name": "ContentSnippetImageType" },
{ "name": "ContentSnippetMapType" },
{ "name": "ContentSnippetPopupType" },
{ "name": "ContentSnippetQuestionType" },
{ "name": "ContentSnippetQuoteType" },
{ "name": "ContentSnippetTextType" },
{ "name": "ContentSnippetVideoType" },
{ "name": "ContentSnippetSpacerType" }
]
},
]
}
}
});
export default new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache({ fm }),
});
I expect all fields depend on the type. It can be dynamic so it is decided at run time only. But it gives me an empty object.