This post shows best practices π« of migrating APIs to GraphQL. Add your thoughts, collabore asking/resolving concerns π€, show them your folks, but ππ», share knowledge π
Lessons Learned
Modularize π your typeDefs & resolvers π
Create different files per each typeDefs & resolvers domain, then import and properly merge them. As you #GraphQL schema grows, you'll π to have a modular design!05:27 AM - 27 Nov 2018
βBreak your schema by concern, not by typesββββMartijn Walraven π
"Break your #GraphQL schema by concern, not by types" by @martijnwalraven @graphqlsummit. Extend your typeDefs as much you can, it'll allow you to define clearly your typeDefs & β»οΈ the logic functions within their respective resolvers π05:34 AM - 27 Nov 2018
DRY β»οΈ, use context! π
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
Evaluate whether your schema is feature or domain based π
Structure your #GraphQL modular schema depending on your features, having only typeDefs & resolvers, you'd π to structure it by feature, although if the number of features grow, do it by domain!10:31 AM - 28 Nov 2018
Show whatβs important π first π
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
Decouple global typeDefs! π
Scalars, interfaces, enums, inputsβ¦ π±, you'll have βΎ global typeDefs inside of your #GraphQL schema, don't miss the opportunity of identifying & decoupling them when you're creating your schema structure09:10 AM - 30 Nov 2018
Take advantage π of ESNext π
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
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!
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
Get rid off your variables using Input Types π
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
Extra π
Donβt miss the 1st part of a series resuming PayPalβs best practices for building GraphQL APIs π
Recapping
π 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
βοΈ GraphQL Resolvers: Best Practices
Already waiting to add yours π€, contribute adding more lessons learned π
Lessons Learned Migrating APIs to #GraphQL π
β³ Share yours π
β³ Open π£
β³ Be π€
β π€
[Thread]
ππ½ ππ½ ππ½
π ππ½ππ½ π
ππ½γππ½
γππ½γ ππ½
γ π’ π’05:27 AM - 27 Nov 2018
Or even betterβ¦
Create posts π, courses π, meetups π, anything!, just be π€ and curious for teaching & learning π
Iβll be following this post up π with more lessons learned, stay tuned!
Please, considerππ»ing, contributβ»οΈing and sharπing it!
Top comments (0)