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

Empty SEO fields when asPreview is true #135

Open
paolospag opened this issue May 13, 2022 · 0 comments
Open

Empty SEO fields when asPreview is true #135

paolospag opened this issue May 13, 2022 · 0 comments
Labels
Needs investigation Needs more investigation

Comments

@paolospag
Copy link

Hello,
I'm new to this plugin and WPGraphQL and I would like to know if it's correct that the fields are empty with asPreview or if I rather need to change something.

This is my query:

const GET_POST_BY_ID = gql`
	query PostBySlug($id: ID!, $idType: PostIdType = URI, $asPreview: Boolean = false) {
		post(id: $id, idType: $idType, asPreview: $asPreview) {
			id
			slug
			isPreview
			title(format: RENDERED)
			content(format: RENDERED)
			featuredImage {
				node {
					uri
					altText
				}
			}
		seo {
			title
			metaDesc
			metaKeywords
			breadcrumbs {
				text
				url
			}
		}
		}
	}
`

And this is the method I use to run the query:

async function getSinglePost(id, asPreview = false) {
	const idType = asPreview ? 'DATABASE_ID' : 'URI';
	const { data } = await client.query({
		query: GET_POST_BY_ID,
		variables: {
			id,
			idType,
			asPreview,
		},
	});
	return data?.post || {};
}

When the variable asPreview is set to true, some fields related to Yoast SEO are empty. In particular:

seo {
	title
	metaDesc
	metaKeywords
	breadcrumbs {
		text
		url
	}
}

Am I wrong something or is it correct that it behaves like this?

@ashhitch ashhitch added the Needs investigation Needs more investigation label Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs investigation Needs more investigation
Projects
None yet
Development

No branches or pull requests

2 participants