ashhitch / wp-graphql-yoast-seo

This is an extension to the WPGraphQL plugin for Yoast SEO
GNU General Public License v3.0
221 stars 49 forks source link

Suggestion for possible Typing Improvements #119

Open moonmeister opened 2 years ago

moonmeister commented 2 years ago

I was trying to abstract my SEO information into my layout so I didn't have to repeat myself in each post/page/tag/category/etc template. The query I started writing looks like this:

query SEO_QUERY($path: ID!) {
      nodeByUri(uri: "/blog/post-1") {
        ... on Page {
          seo {
            ...SeoData
          }
        }
        ... on Post {
          seo {
            ...SeoData
          }
        }
        ... on Tag {
          seo {
            ...SeoData
          }
        }
      }
    }
  `;

This seems extremely verbose given the same fields are available on all (or so I suppose). WPGraphQL already has types that solve this issue for things like Title/Author/etc:

{
  nodeByUri(uri: "/blog/post-1/") {
    ... on NodeWithTitle {
      title
    }
  }
}

What I'm recommending is we create type like NodeWithSeo for yoast:

{
  nodeByUri(uri: "/blog/post-1/") {
    ... on NodeWithSeo {
      seo {
        ...SeoData
      }
    }
  }
}

Thoughts?

moonmeister commented 2 years ago

Based on the Readme it looks like not all seo fields are created with the same data. But even if we combined post/pages, tag/categories, etc... that could still be helpful. e.g.

{
  nodeByUri(uri: "/blog/post-1/") {
    ... on TermNodeWithSeo {
      seo {
        ...SeoData
      }
    }
    ... on ContentNodeWithSeo {
      seo {
        ...SeoData
      }
    }
  }
}
moonmeister commented 2 years ago

Looks like the ContentNode or TermNode types might be valuable here.

ashhitch commented 2 years ago

@moonmeister This seems like a really good idea!

moonmeister commented 2 years ago

Thanks, I unfortunately don't have much for PHP skills...so can't help with implementation. I also had the though that NodeWithFullHead or NodeWithCommonSeo could be other helpful types.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

moonmeister commented 2 years ago

Not stale

justlevine commented 2 years ago

@ashhitch would love to help with this, PMing you on the wp-graphql slack

ashhitch commented 2 years ago

Not stale

Sorry really need to remove this action