Migrating SpaceX API to GraphQL 🚀
Tags: graphql, javascript, spacex
Published: 2019-08-09 11:54:28

As another lover of physics, astronomy and rockets, when I found the SpaceX Public API (thanks to [Full Stack Apollo tutorial](http://apollographql.com/docs/tutorial/introduction.html) 👏), I was really intrigued for looking into the available data.

I immediately accessed to the [SpaceX API GitHub](https://github.com/r-spacex/SpaceX-API) and …

![](https://cdn-images-1.medium.com/max/3396/1*frgOjBqsIBs4f8t6gBSECA.png)

* 🐵s would be the future Animoji’s Hand Tracking UX tests

REST? External docs? Postman?? 😅 The SpaceX API journey didn’t start well but I was still excited for digging into the resources that make up the API, I continued my way to [the Docs](https://documenter.getpostman.com/view/2025350/RWaEzAiG) 😬

As always I’ve skipped the introduction and went straight to the resources in search of the **holy grail**, *the data and their respective type definitions*, let’s review what there is inside of it 👇

![](https://cdn-images-1.medium.com/max/2300/1*6Bz0dZavgjWvbqisAWSJCg.png)

✅ **Endpoint**, 😒 v3?, is there a v2? where’re the docs? 😕

✅ **Types**, I dunno what QueryStrings is but we have some type definitions 😍

🔲 **Data**, no data, no 😭. Let’s keep looking, the data model should be around!

As a accustomed GraphQL user, the experience wasn’t being great but it deserved a chance 🤞

![](https://cdn-images-1.medium.com/max/2296/1*3EIsYZy7ht0BJXsZ32NUJQ.png)

Eureka, I’ve found it 🎉

✋ a sec, original_launch_unix doesn’t look like familiar, let’s check the “type definitions” again,
🤔 it’s not there and the description always says “Filter…”
😓 that wasn’t the data type definitions,
😫 where could they be then?

**scrolling trying to find the type definitions… **

**My brain:
**Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it

**Me: **“Keep calm, let’s see if we can find them over the API collection provided”

**running [Postman collection](https://app.getpostman.com/run-collection/3aeac01a548a87943749)…**

![](https://cdn-images-1.medium.com/max/2000/1*ri-tQl6i7oUMuDjAl6vblA.png)

**installing, signing up, setting up…**

**My brain:
**Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it
Don’t say it

**Me: **“What are you waiting to use GraphQL?”

Yep, I gave up 😓, right after that I started the API migration…

## Why?

Because,
> # I just want to explore data & their types

without the need of setting anything up, and because of…

👉 **Overfetching**: 90% of the responses exceeds the app’s data need, I just wanna ask for what I want!

👉 **Underfetching**: Multiple requests are a bad performance solution, I’d love to request all the data in one

👉 **Typing**, **documentation**, **versioning**, **ecosystem, **…♾, are always tricky

## How?

![](https://cdn-images-1.medium.com/max/4408/1*01W2XwVEpRyg-3Ayt4FN5g.png)

## What?

*It’s not a framework, neither a library*, is a **Query Language **for APIs and as specification itself, it’s compatible with any programming language 💫

[GraphQL: A query language for APIs](https://graphql.org/)

Master it 👩‍🎓👨‍🎓 with “[Learning GraphQL](http://shop.oreilly.com/product/0636920137269.do)” by Eve Porcello & Alex Banks

![](https://cdn-images-1.medium.com/max/2000/1*u8MDB0zH-dDLCB82SSRwCQ.png)

## 🌒🌔 The Migration 🌖🌘

What could I say about the *GraphQL techs & tooling*? Simply that I had deployed an API being able to interactively, fetch real data & explore full-updated docs (and much more)*, **within a couple hours**, just fast & fun!

## Steps

1️⃣ Setup server & modular schema ⚙️
2️⃣ Include DB & builders into the context
3️⃣ Create domain’s typeDefs & resolvers 💪
4️⃣ Implement [trivial resolvers](https://graphql.org/learn/execution/#trivial-resolvers)
5️⃣ Apply lessons learned 💡
6️⃣ Deploy 🚀 it

Doesn’t look like difficult right?, actually it’s not thanks to the brilliant GraphQL Community 🙌, [don’t miss the changes made](https://github.com/r-spacex/SpaceX-API/compare/master...swcarlosrj:graphql)!

## Conclusions

Draw them yourself… (fork it, break it, improve it but especially, enjoy it 😄)
> # [👉 The Repo & The API & The Docs & The Everything👇](https://codesandbox.io/s/yv004pqnq9)

{% codesandbox yv004pqnq9 %}


<iframe src="https://medium.com/media/4e448beb907df749084b3a5ae1d27213" frameborder=0></iframe>

![](https://cdn-images-1.medium.com/max/3840/1*f6IMUipNmjSrEp9iEAX4sw.jpeg)

### Don’t miss the GraphQL best practices & conclusions based on SpaceX GraphQL API
> # **👉 [Lessons Learned Migrating APIs to GraphQL 📝](https://medium.com/@swcarlosrj/lessons-learned-migrating-apis-to-graphql-8a015d08b163) 👈**

Please, consider🙏🏻ing, contribut♻️ing and shar💜ing it!