DEV Community

Cover image for Sanity.io to Builder.io Data Transfer
Alex Patterson for CodingCatDev

Posted on Edited on Originally published at codingcat.dev

Sanity.io to Builder.io Data Transfer

Original: https://codingcat.dev/post/sanity-io-to-builder-io-data-transfer

I am hoping to make a Sanity.io plugin for builder. In doing so I thought I would write a little conversion tool before hand to figure out all the ins and outs of Builder.io and Sanity.io, so I thought I would share some of my findings. I will keep this tutorial updated as the plugin progresses.

The repo example has three things that you might find useful.

  • Deleting All Data
  • Creating all new types
  • Adding all new Data

Repo for conversion example https://github.com/CodingCatDev/sanity-to-builder.git

Deleting All Data

https://github.com/CodingCatDev/sanity-to-builder/blob/84d8b5d436b2d674f916670317cb48de916c8a68/src/index.ts#L175

In order to delete all the data you need to first find all the models you want to delete

Get all Models from Builder (even unpublished)

In sanity you deal with things like draft. in documents. In Builder these items are just known to be unpublished version. So you need to have includeUnpublished=true in your API call. I looked for a while in the sdk and have not found this option so far.

You can handle this by using the fetch command instead of the sdk.

https://github.com/CodingCatDev/sanity-to-builder/blob/84d8b5d436b2d674f916670317cb48de916c8a68/src/config.ts#L134

Creating all new types

First you need to find all the types in your sanity.io database. I find it best to use Groq. So we can find all the types in Sanity and then create those in Builder as new Models.

Adding all new Data

Long Term goal

The End goal is to build a plugin for syncing your data...

Builder content link https://github.com/BuilderIO/builder/tree/main/plugins/contentful

Resources, Links & Official Documentation

Related CodingCat.dev Tutorials & Podcast Episodes

Frequently Asked Questions (FAQ)

What are the main takeaways from Sanity.io to Builder.io Data Transfer?

In this example I will walk you through what data looks like in Sanity.io and how to get that data over to your Builder.io instance while creating models. Sanity.io to Builder.io Data Transfer explores practical patterns for Sanity, Builder.io, GitHub in modern software engineering. Throughout this post, Alex Patterson breaks down real-world implementation details for Sanity, Builder.io, GitHub so developers can apply these patterns directly in production.

How do you implement Sanity best practices in production?

When adopting Sanity and Builder.io in a production stack, start by validating your configuration against the Sanity.io Content Operating System Docs (GROQ queries, Portable Text, Content Lake, and Agent Context). Focus on incremental adoption, automated testing, and observability so your team can measure performance and developer velocity improvements at each stage.

Where can I watch the full Sanity.io to Builder.io Data Transfer walkthrough and find related code resources?

You can explore the complete write-up and code examples right here on CodingCat.dev, and subscribe to the CodingCat.dev YouTube channel for weekly video tutorials. For a deeper dive into Sanity, check out our related guide: Sanity Knowledge Bases.

Top comments (0)