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
CommentAuthor should have RootQuery entry points in the Graph #1757
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue. |
Decided to give this a shot. I'm making some progress but need some clarification. Currently when querying comment authors on a comment, if the commenter wasn't a logged in user, the |
@moonmeister great question!
edit: nope. Users and comments both have their own unique numbering. Would suggest a more specific |
ok, so we have a few things to consider here.
So, querying a We should be able to query like so: {
commentAuthor( id: 123 idType: DATABASE_ID ) { ... }
commentAuthor( id: "comment_author:123 ) { ... } # would be base_64_encoded Id, of course
} And under the hood that should query for the comment with databaseId Now, if we wanted to be able to query for a so, querying for Querying for {
commenter( id: "user:123" ) { ... }
commenter( id: "comment_author:123" ) { ... }
commenter( id: 123 idType: USER_DATABASE_ID ) { ... }
commenter( id: 123 idType: COMMENT_AUTHOR_DATABASE_ID { ... }
} |
In theory yes, returning As far as |
yes. Sounds like a bug. The |
@moonmeister WordPress core functionality lets you show different data depending on whether the Author is a user or not. And being a "graph" we expose that to users to consume as well. If the If the For example, I can do something like:
If the Author of the comment is a All sorts of use cases here! |
Right, that makes sense. I guess the question is this top level entry point only include |
If I wanted to procedurally generate a list of commenters...I'd use this but would probably want |
I think we have room to add both. An entry point to get Another entry point to get The original ask was for the And we can work on Think of it like the different entry points for posts. You could do:
Multiple ways to enter the graph! |
Sure! What if i had a list of comments that showed the author, and when I click the author a Modal or Drawer opens with information about the author. If the Author is a If the Author is a psuedo code: const UserCommentorBio = ( { databaseId } ) => {
const { data } = useQuery( `
query GetUserBio( $id: ID! ) {
user( id: $id idType: DATABASE_ID ) {
id
name
recentPosts: posts { nodes { id, title, date } }
}
}
`, { variables: { id: databaseId } } )
return (
<div>
<pre>{JSON.stringify( data, null, 2 )</pre>
</div>
)
}
const CommentAuthorBio = ( { databaseId } ) => {
const { data } = useQuery( `
query GetCommentAuthorBio( $id: ID! ) {
commentAuthor( id: $id idType: DATABASE_ID ) {
id
name
}
}
` , { variables: { id: databaseId } } )
return (
<div>
<pre>{JSON.stringify( data, null, 2 )</pre>
</div>
)
}
const Comment = ({ databaseId }) => {
const { data } = useQuery( `
query GetComment( $id: ID! ) {
comment( id: $id ) {
content
author {
node {
__typename
databaseId
}
}
}
}
`, { variables: { id: databaseId } } );
const type = data?.comment?.author?.node?.__typename;
if ( type === 'CommentAuthor ) {
return <CommentAuthorBio databaseId={ data?.comment?.author?.node?.databaseId } />
}
if ( type === 'User ) {
return <UserCommentorBio databaseId={ data?.comment?.author?.node?.databaseId } />
}
return null;
} |
^ very contrived, pseudo code, but hope it conveys roughly a use case 🤷🏻♂️ |
The
CommentAuthor
is a Type in the graph that is used to represent authors of comments that are not users.When querying comments and their authors, you can query like so:
Currently, the only access point to get to an object of the
CommentAuthor
type is to fetch it as a relationship of a comment. There's no direct Root entry points in the Graph to get aCommentAuthor
.But, since the
CommentAuthor
implements theNode
Interface, it should have Root entry points into the Graph.I propose adding a
commentAuthors { ... }
Root entry point as well as a singularcommentAuthor( id: $id ) { ... }
entry point to the graph.Related: gatsbyjs/gatsby#29998
The text was updated successfully, but these errors were encountered: