wp-graphql-yoast-seo icon indicating copy to clipboard operation
wp-graphql-yoast-seo copied to clipboard

Suggestion for possible Typing Improvements

Open moonmeister opened this issue 4 years ago • 8 comments

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 avatar Dec 10 '21 20:12 moonmeister

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 avatar Dec 10 '21 21:12 moonmeister

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

moonmeister avatar Dec 10 '21 21:12 moonmeister

@moonmeister This seems like a really good idea!

ashhitch avatar Dec 11 '21 19:12 ashhitch

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.

moonmeister avatar Dec 14 '21 00:12 moonmeister

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

github-actions[bot] avatar Feb 12 '22 09:02 github-actions[bot]

Not stale

moonmeister avatar Feb 12 '22 15:02 moonmeister

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

justlevine avatar Feb 13 '22 13:02 justlevine

Not stale

Sorry really need to remove this action

ashhitch avatar Feb 13 '22 14:02 ashhitch