Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On AllWpPost, it's not possible to get a comment author's name #30311

Closed
tharsheblows opened this issue Nov 11, 2020 · 5 comments · Fixed by #30358
Closed

On AllWpPost, it's not possible to get a comment author's name #30311

tharsheblows opened this issue Nov 11, 2020 · 5 comments · Fixed by #30358
Assignees
Labels
topic: source-wordpress Related to Gatsby's integration with WordPress

Comments

@tharsheblows
Copy link

I'm trying this query on my localhost's graphiql instance using:
v2.1.3 of this
v0.15.0 of the wp-graphql plugin
v0.5.4 of wp-gatsby plugin

with the starter theme here (but with an updated version of this 😊) https://github.com/TylerBarnes/using-gatsby-source-wordpress-experimental

I can't get to the author's name for the comments. This is an example of the type of query I'm running:

query MyQuery {
  allWpPost {
    nodes {
      date
      content
      comments {
        nodes {
          content
          author {
            node {
              name
            }
}}}}}}

which is returning this error for comments.author.node.name (the rest is correct):

"message": "Abstract type WpCommenter must resolve to an Object type at runtime for field WpCommentToCommenterConnectionEdge.node with value { id: \"Y29tbWVudF9hdXRob3I6Mjc=\", __typename: \"CommentAuthor\" }, received \"undefined\". Either the WpCommenter type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
      "locations": [
        {
          "line": 10,
          "column": 13
        }
      ],
      "path": [
        "allWpPost",
        "nodes",
        0,
        "comments",
        "nodes",
        0,
        "author",
        "node"
      ],
      "stack": [
        "GraphQLError: Abstract type WpCommenter must resolve to an Object type at runtime for field WpCommentToCommenterConnectionEdge.node with value { id: \"Y29tbWVudF9hdXRob3I6Mjc=\", __typename: \"CommentAuthor\" }, received \"undefined\". Either the WpCommenter type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
        "    at ensureValidRuntimeType ([path to theme]/node_modules/graphql/execution/execute.js:667:11)",
        "    at completeAbstractValue ([path to theme]/node_modules/graphql/execution/execute.js:660:42)",
        "    at completeValue ([path to theme]/node_modules/graphql/execution/execute.js:585:12)",
        "    at [path to theme]/node_modules/graphql/execution/execute.js:492:16",
        "    at runMicrotasks (<anonymous>)",
        "    at processTicksAndRejections (internal/process/task_queues.js:93:5)",
        "    at async Promise.all (index 0)",
        "    at async Promise.all (index 1)",
        "    at async Promise.all (index 0)",
        "    at async Promise.all (index 0)",
        "    at async Promise.all (index 2)",
        "    at async Promise.all (index 0)",
        "    at async Promise.all (index 0)",
        "    at async Promise.all (index 0)"
      ]

If I pick up a comment id and use that in the following, it also gives the same error:

query MyQuery {
  wpComment(id: {eq: "[comment id]"}) {
    author {
      node {
        name
      }
    }
  }
}
@TylerBarnes TylerBarnes self-assigned this Nov 12, 2020
@TylerBarnes
Copy link
Contributor

Hi @tharsheblows ! Thanks for reporting this. I have an idea what the problem is but I'll have to try to reproduce first. Are you able to share a reproduction /graphql endpoint I can use to confirm?

@tharsheblows
Copy link
Author

tharsheblows commented Nov 12, 2020

@TylerBarnes Apologies if I'm misunderstanding what you're asking for! If you use your starter theme (using updated version of gatsby-source-wordpress-experimental: "^2.1.1") and then the following as the query in src/templates/single/Post.js with a url of https://idontthink.wpenine.com/graphql you'll see it in the wild so to speak and you can use that for testing also. Did you want that url? I have it set up with wp-gatsby at the moment but usually use gatsby-source-graphql so will have to switch it back (?? do I? [edit: yes, I do, I can't use gatsby-source-graphql with wp-gatsby activated on the site]) if I actually write a blog post. Unlikely, admittedly. You can also see it on any install of WP with a comment (the out of the box install has one! :) )

export const query = graphql`
  query post($id: String!, $nextPage: String, $previousPage: String) {
    page: wpPost(id: { eq: $id }) {
      title
      content
      featuredImage {
        node {
          remoteFile {
            ...HeroImage
          }
        }
	  }
	  comments{
		  nodes{
			content
			author{
				node{
					name
				}
			}
		  }
	  }
    }

    nextPage: wpPost(id: { eq: $nextPage }) {
      title
      uri
    }

    previousPage: wpPost(id: { eq: $previousPage }) {
      title
      uri
    }
  }

@TylerBarnes TylerBarnes transferred this issue from gatsbyjs/gatsby-source-wordpress-experimental Mar 17, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 17, 2021
@TylerBarnes TylerBarnes added topic: source-wordpress Related to Gatsby's integration with WordPress and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Mar 17, 2021
@amooreTO
Copy link

@tharsheblows - were you able to resolve this issue? I am facing the same the error.

@TylerBarnes
Copy link
Contributor

@amooreTO I'm working on a fix this very moment :)

@TylerBarnes
Copy link
Contributor

I have a canary with a possible solution here [email protected]+e45fa4b460. The only problem is that issue I linked above ☝️

To get it to work you need to exclude Commenter.databaseId to prevent WPGraphQL errors that cause the author to return null.

In your gatsby-config.js plugin options for gatsby-source-wordpress add this:

        type: {
          Commenter: {
            excludeFieldNames: [`databaseId`],
          },
        }

Once that linked issue is fixed in WPGraphQL and this PR is merged/released #30358 it will work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: source-wordpress Related to Gatsby's integration with WordPress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants