Introducing CMSutil, GraphQL backups
By John
At work I selected GraphCMS to be our preferred headless CMS. It is already leveraged on multiple projects and has been working out well for us. The beauty of a good headless CMS is you can use in many scenarios. Case in point, of the 3 instances we have, 2 are web apps; only one is marketing site.
If you are not familiar with GraphCMS, it is a flexible headless CMS with native GraphQL support. It is not a REST API with GraphQL slapped on top, it is a true GraphQL service. This combined with their excellent schema editor and content tools makes it an excellent choice for headless content management.
As I said earlier, we love it, even despite some of the growing pains it had last year. In the end, we did find one drawback however. We missed having an easy way to make backups of our information. Of course the vendor backs up all of our information for us, but we don’t have a good mechanism to backup all the raw metadata and media files ourselves. We had no resources or time budgeted for something like this so we did without.
So what is CMSutil already?
I decided to do something about it and whip up a simple tool that will backup our GraphQL content data with a simple and easy to do use CLI. Since I did this on my own time I went ahead and made this tool open source. Today marks the launch of a stable release of this new tool called CMSutil.
Download the code now on GitHub at https://github.com/arroyo/cmsutil
CMSutil will download all content into a json file and download all assets. It will capture all enumerations (lists), nodes and relations.
This is done by a set of logic created around dynamic introspection GraphQL queries. GraphQL (and GraphCMS) has no generic way to pull schema structures, content, and other meta data. With a carefully selected set of introspections you can generate GraphQL queries to pull both content and schema structures. If you need to make backups of your data I hope this tool can be of use to you. Hopefully it saves you some time as creating this tool ended up being more work than I anticipated.
The output format of CMSutil was originally based on the GraphCMS API V1 export services structure. This was a useful enterprise feature of V1, V2 does not have this APIs as V2 was a major rewrite of their platform. This utility will work with community (free), self service & enterprise plans (however it has only been tested on community and enterprise).
I wrote the tool in Go and used the popular Cobra library for a clean CLI interface.
Let me know what you think. If you run into any problems create a GitHub issue. Feedback, feature requests and pull requests are all welcome!