drupal-graphql / graphql-metatag

6 stars 13 forks source link

Add support for schema metatags #7

Open mtodor opened 6 years ago

mtodor commented 6 years ago

Fixes #6

Here is proposal for exposing schema metatags. I split base metatags and schema metatags into two fields, because it's easier to manage that on frontend part too.

To query schema metatags, I just add field for entity:

schema_metatags: entitySchemaMetatags {
        key
        content
}

and after that map values to object like this:

<script type="application/ld+json">
  {JSON.stringify({
    '@context': 'https://schema.org',
    '@graph': [
      schema_metatags.reduce((res, entry) => {
        res[entry.key] = JSON.parse(entry.content);
        return res;
      }, {}),
    ],
  })}
</script>

And that's it.

Bad part is, that content is encoded json, but I would like to avoid too much nesting.

codecov[bot] commented 6 years ago

Codecov Report

Merging #7 into 8.x-1.x will not change coverage. The diff coverage is 0%.

Impacted file tree graph

@@          Coverage Diff          @@
##           8.x-1.x    #7   +/-   ##
=====================================
  Coverage        0%    0%           
=====================================
  Files            7    13    +6     
  Lines           67   110   +43     
=====================================
- Misses          67   110   +43
Impacted Files Coverage Δ
src/Plugin/GraphQL/Types/SchemaMeta.php 0% <0%> (ø)
src/Plugin/GraphQL/Types/MetaValue.php 0% <0%> (ø) :arrow_up:
src/Plugin/GraphQL/Fields/Metatag/Content.php 0% <0%> (ø)
src/Plugin/GraphQL/Fields/Metatag/Key.php 0% <0%> (ø) :arrow_up:
...gin/GraphQL/Fields/Entity/EntitySchemaMetatags.php 0% <0%> (ø)
src/Plugin/GraphQL/Types/MetaItemProp.php 0% <0%> (ø)
...rc/Plugin/GraphQL/Fields/Entity/EntityMetatags.php 0% <0%> (ø) :arrow_up:
src/Plugin/GraphQL/Fields/InternalUrl/Metatags.php 0% <0%> (ø) :arrow_up:
src/Plugin/GraphQL/Types/MetaHttpEquiv.php 0% <0%> (ø)
...ugin/GraphQL/Fields/InternalUrl/SchemaMetatags.php 0% <0%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 48140c3...c9eec6f. Read the comment docs.

Luigisa commented 3 years ago

Hello,

i have joined as maintainer of this module and have already applied this fix in the official drupal repository.

https://www.drupal.org/project/graphql_metatag

Regards