Hi,
To pass the variables to query strings, graphql() expects a named query ( name is optional ).
Following is the updated snippet,
<?php
$post_slug = get_post_field( 'post_name', get_post() );
$graphql = graphql([
'query' => '
query GetPost( $post_slug: ID! ) {
post(idType: SLUG, id: $post_slug) {
title
content
date
}
}',
'variables' => [
'post_slug' => 'test-previews',
],
]);
For more details you can refer:
– graphql() ref
– Using variables in graphql queries
Hope this helps,
Thank you,