I am relatively new to using Craft Headlessly and am trying to query matrix fields with Nuxt JS and it's Apollo module.
I have discovered, that although the graphQL queries work in the GraphiQl interface, they do not work with Apollo due to Apollo not knowing the schema for unknown fragments. I've stumbled apon a few others who have had this issue such as this guy but their solution confused me and seemed more complicated than I would expect. I'm sure there must be a simple solution considering this is a widely used system for working with Craft Headlessly.
I also saw this response from someone (see the response from Mylesthe.dev) who gave some instruction but I still didn't quite understand how to apply this. The post above this also mentions that Apollo-client 3.0 should be able to handle unknown fragment types but I'm on @nuxtjs/apollo ^v4 and still experiencing it.
Does anyone have a simple clear fix for this that I can apply to my set up, so that I can query matrix fields with multiple fragment types in Craft CMS?
My Package.json file is:
{
"name": "nuxtjs-test",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"@nuxtjs/apollo": "^4.0.1-rc.5",
"core-js": "^3.6.5",
"dotenv": "^8.2.0",
"flickity": "^2.2.2",
"headroom.js": "^0.12.0",
"node-fetch": "^2.3.0",
"nuxt": "^2.14.6",
"vue-rellax": "^0.2.0"
},
"devDependencies": {
"@nuxtjs/dotenv": "^1.4.1",
"@nuxtjs/style-resources": "^1.0.0",
"fibers": "^5.0.0",
"sass": "^1.32.0",
"sass-loader": "^10.1.0"
}
}
My apollo GQL query is (const GET_HOMEPAGE):
{
entry(section: "homepage") {
... on homepage_homepage_Entry {
homepageBuilder {
... on homepageBuilder_sectionHeadline_BlockType {
typeHandle
headline
}
... on homepageBuilder_showcase_BlockType {
typeHandle
limit
}
... on homepageBuilder_articles_BlockType {
typeHandle
}
}
}
}
}
my apollo smart query is:
apollo: {
entry: {
query: GET_HOMEPAGE,
error (error) {
this.error = JSON.stringify(error.message);
console.log(error);
},
result ({ data, loading, networkStatus }) {
console.log("[networkStatus]",networkStatus);
console.log(data);
},
},
},
my apollo settings in Nuxt.config file is:
apollo: {
clientConfigs: {
default: {
httpEndpoint: process.env.APOLLO_DEFAULT_ENDPOINT,
}
},
defaultOptions: {
$query: {
fetchPolicy:'no-cache'
}
}
},