wpnuxt / wpnuxt-core

WPNuxt core module: connect Nuxt with a headless WordPress using GraphQL
https://wpnuxt.com
18 stars 1 forks source link

Extending default query with Yoast Seo #17

Closed enricodeleo closed 7 months ago

enricodeleo commented 8 months ago

Hello there and thank you for this great module. It's a great building block for a modern Wordpress stack!

I'm having hard times figuring out how to extend the wp.gql in order to always include

seo {
    metaDesc
    title
    fullHead
}

for pages and posts. I think it would be super useful in order to have full control of the SEO metas. Of course I already extended the graphql thanks to a plugin.

Any ideas?

vernaillen commented 7 months ago

Hi Enrico

Thanks for trying out the module, glad you like it. It's still in an early stage and I thought I was the only one using it so far :D

What you describe would indeed be very useful, but is not possible at the moment.
I did already provide a way to extend the schema with extra Fragments and Queries, which can be used for adding Custom Post Types. But it doesn't allow to modify an already existing fragment, like a Page or Post.

The issue is that the wp.gql provided by the module is always loaded, so if you try to override the Page or Post fragment, it will throw errors like this Error: Not all fragments have an unique name: Page, Post

What I can do, is provide a config setting to disable the original wp.gql. And you can then copy the complete wp.gql into your nuxt app and extend the Fragments with the extra seo fields.

enricodeleo commented 7 months ago

Well I'm quite a connoisseur when it comes to uncovering gems @vernaillen 😊

Yes checking the source code I stumbled upon the possibility to extend the graphql queries with a custom file but I end up with the exact same error you mentioned. I think that the possibility of overriding it could be a good improvement for a first iteration over the problem. I don't see at the moment how to approach this in a more flexible way but I hope I can contribute if I come up with a better suggestion.

Speaking of config settings, I've encountered some challenges in attempting to disable the multiCache function. The only workaround I've managed to come up with was to independently install the multicache module, otherwise I couldn't set cache to false. Even after that the contents from graphql are still cached and that's quite a problem during development.

This module is super promising, thank you for this!

update I tried the last version v0.2.5 and now I got a bunch of errors such as

website-1      | 
website-1      | [nuxt-graphql-middleware]  ERROR  ENOENT: no such file or directory, open '/app/src/queries/fragments/Page.fragment.gql'
website-1      | 
website-1      |   at Object.readFileSync (node:fs:453:20)
website-1      |   at linesWithInlinedImportsOf (node_modules/.pnpm/@graphql-fragment-import+lib@3.0.0/node_modules/@graphql-fragment-import/lib/inline-imports.js:52:33)
website-1      |   at linesWithInlinedImportsOf.next (<anonymous>)
website-1      |   at inlineImportsWithLineToImports (node_modules/.pnpm/@graphql-fragment-import+lib@3.0.0/node_modules/@graphql-fragment-import/lib/inline-imports.js:93:59)
website-1      |   at inlineImports (node_modules/.pnpm/@graphql-fragment-import+lib@3.0.0/node_modules/@graphql-fragment-import/lib/inline-imports.js:131:10)
website-1      |   at inlineFragments (node_modules/.pnpm/nuxt-graphql-middleware@4.0.0_graphql-tag@2.12.6_graphql@16.8.1_nuxt@3.10.2_typescript@5.3.3_vite@5.1.4/node_modules/nuxt-graphql-middleware/dist/module.mjs:283:10)
website-1      |   at node_modules/.pnpm/nuxt-graphql-middleware@4.0.0_graphql-tag@2.12.6_graphql@16.8.1_nuxt@3.10.2_typescript@5.3.3_vite@5.1.4/node_modules/nuxt-graphql-middleware/dist/module.mjs:443:20
website-1      |   at Array.map (<anonymous>)
website-1      |   at node_modules/.pnpm/nuxt-graphql-middleware@4.0.0_graphql-tag@2.12.6_graphql@16.8.1_nuxt@3.10.2_typescript@5.3.3_vite@5.1.4/node_modules/nuxt-graphql-middleware/dist/module.mjs:440:22
website-1      |   at async generate (node_modules/.pnpm/nuxt-graphql-middleware@4.0.0_graphql-tag@2.12.6_graphql@16.8.1_nuxt@3.10.2_typescript@5.3.3_vite@5.1.4/node_modules/nuxt-graphql-middleware/dist/module.mjs:552:21)

What I find out is that now the module automatically merges gql files (that is great) in the root directory, wether it should respect the srcDir property in nuxt.config.ts that in my case is srcDir: 'src/',.

vernaillen commented 7 months ago

v0.2.6 has just been released including your fix for the srcDir.
There's a separate ticket for the multiCache issue, which I will look into later.

I also added an example how to override the existing Page and Post fragments in examples/yoastseo.

Thanks for the feedback on the module and the contribution :)

vernaillen commented 7 months ago

Closing this ticket now. of course new ones are always welcome

enricodeleo commented 7 months ago

I did see the example and already tested it. It works now even with srcDir. Thank a lot!