Cms: [FR] GraphQL: Allow for Element query modification

Created on 6 Oct 2019  路  7Comments  路  Source: craftcms/cms

One nice feature of the CraftQL plugin is that you could modify the query schemas to add your own fields to Element query schemas, for instance.

Right now I can do this with GraphQL & CraftQL:

{
  seomatic (uri: "/") {
      metaTitleContainer
      metaTagContainer
      metaLinkContainer
      metaScriptContainer
      metaJsonLdContainer
  }
}

However, I can only do this with CraftQL (unless I'm missing something):

{
  entry(section: homepage) {
    id
    title
    ... on Homepage {
      seomatic {
        metaTitleContainer
        metaTagContainer
        metaLinkContainer
        metaScriptContainer
        metaJsonLdContainer
      }
    }
  }
}

...which effectively lets you piggyback on an entries query, to return all of your data for an entry as well as the SEOmatic metadata in one request. It has access to the parent, and so can grab the uri automatically.

In order for this to be possible in the native GraphQL, you'd probably need to throw some events from ElementType::generateTypes()

https://nystudio107.com/docs/seomatic/Advanced.html#headless-spa-api

enhancement extensibility graphql

Most helpful comment

Added in https://github.com/nystudio107/craft-seomatic/commit/b58e60ca94b159b160a20f9b014d19dc7b27c0bb

You can set your semver to dev-develop and then do composer update to give it a whirl now.

All 7 comments

Working on this at the moment.

This is addressed in https://github.com/craftcms/cms/commit/a5dd6f2eef8f1a8a5f81edd13ea123340b5cde69 and will be a part of Craft 3.4

This is now available as part of Craft 3.4 beta.

Maybe I am missing something here but I am running 3.4.20 and I am not able to get the seomatic field values.

@bzin Craft 3.4 just added the ability for SEOmatic to modify element queries. It鈥檚 still up to SEOmatic to take advantage of it (see nystudio107/craft-seomatic#483).

@brandonkelly SEOmatic is just waiting on this to be documented, so I don't have to (probably poorly) reverse engineer how to do it.

Added in https://github.com/nystudio107/craft-seomatic/commit/b58e60ca94b159b160a20f9b014d19dc7b27c0bb

You can set your semver to dev-develop and then do composer update to give it a whirl now.

Was this page helpful?
0 / 5 - 0 ratings