Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Include page version in Page graphql query

default discord avatar
lioloclast year

Hi everyone,



Payload version: 2.1.1



I'm using the Payload Website demo project, I'm trying to figure out how to add the page's current version along with the Page's details.



Currently the function fetchDoc in the api is run to get the page's fields, this query doesn't include the version. The auto generated type "Page" also doesn't include this. I noticed there is another autogenerated "PageVersion" type that contains what I want but I think you need to be authenticated to query this table because when I constructed a query it says: "Error: You are not allowed to perform this action."



What I tried was creating a fetchPageVersion function, mimicking the fetchDoc function but just using this query:



query PageVersion {


versionsPages {


docs {


id


version {


title


publishedDate


createdAt


}


}


}


}



Notice I'm not even specifying the page I want here, just because I'm trying to just get some results returned back to me.



Anyway this wouldn't be the ideal solution if it worked as it's forcing me to do two queries instead of just one, which would give me the Page + the version.



Is there a way to either modify the Page collection so that the version is available?



I solved my own question but I thought I'd add anyways in case it can help someone in the future.



I added a endpoint to solve this issue (using the seed endpoint as an example), and I queried for the version using the payload.findVersions api:

https://payloadcms.com/docs/versions/overview#find
    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team..