This post shows best practices 💫 of migrating APIs to GraphQL. Add your thoughts, collabore asking/resolving concerns 🤗, show them your folks, but 🙏🏻, share knowledge 💜
“Break your schema by concern, not by types“ — Martijn Walraven 👇
You'd 😄 to be able to have access to certain methods inside of your resolvers right?, that's why 👉 context 👈 exits. It is useful for passing things, like authentication scope, DB connections, and custom fetch functions. Thanks to @JakeDawkins for the tip 🤗19:15 PM - 27 Nov 2018
On large #GraphQL schemas you'll notice that each domain contains tons of types, prioritize 👉 WHAT MATTERS FIRST. Knowing that the 'extends' keyword stands for links between types, put them to the 🔝 of the file, then add the domain type and finally the field types07:45 AM - 29 Nov 2018
Use async/await to fetch data from the DB/API, array destructuring to get individual elements and object destructuring to join/remove elements. ⚠️ Don't forget handle possible errors!21:41 PM - 01 Dec 2018
Don't forget sometimes a plain old fetch request is all you need to query your #graphql API.
Don't immediately reach for all the npm dependencies if your requests are minimal.
#graphql-request/urql are a good next step until you need all the complexity Apollo Client brings imo.21:30 PM - 10 Dec 2018
Ben Awad@benawad97If you're not using #graphql fragments, here's an example of where I like to use them.15:30 PM - 12 Dec 2018
Ben Awad@benawad97When you have #graphql input types, you can pass in the variables individually or create a single one14:55 PM - 13 Dec 2018
👉 Modularize 👌 **your typeDefs & resolvers
👉 “Break your schema by concern, not by types“ — Martijn Walraven
👉 DRY ♻️, use context!
👉 Evaluate whether your schema is feature or domain based
👉 Show what’s **important 👀 **first
👉 Decouple global typeDefs!
👉 Take advantage 🚀 of **ESNext
👉 Return several types using **Union Types!
👉 Use Aliases 🔥 to rename the result of a field
👉 Don’t over-engineer, you can query with **fetch
👉 DRY ♻️, use fragments!
👉 Get rid off your variables using Input Types
Already waiting to add yours 🤗, contribute adding more lessons learned 👇
I’ll be following this post up 🔜 with more lessons learned, stay tuned!
Please, consider🙏🏻ing, contribut♻️ing and shar💜ing it!