Add Edit Link to All Post Types

The following snippet shows how to add the “Edit” link as a GraphQL field to all post types:

add_action( 'graphql_register_types', function() {

	register_graphql_field( 'ContentNode', 'editLink', [
		'type' => 'String',
		'description' => __( 'Link to edit the content', 'your-textdomain' ),
		'resolve' => function( \WPGraphQL\Model\Post $post, $args, $context, $info ) {
		   return get_edit_post_link( $post->databaseId );
		}
	]);

} );

This could then be queried like so:

Screenshot of a GraphQL Query for posts with their editLink
Screenshot of a GraphQL Query for posts with their editLink