DEV Community

Carlos Rufo
Carlos Rufo

Posted on

Lessons Learned Migrating APIs to GraphQL ๐Ÿ“

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 ๐Ÿ‘‡

โ€œ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 ๐Ÿ‘‡

Extra ๐ŸŒŸ

Donโ€™t miss the 1st part of a series resuming PayPalโ€™s best practices for building GraphQL APIs ๐Ÿ‘‡

GraphQL Resolvers: Best Practices
*GraphQL resolvers can be easy to build, but difficult to get right. Hereโ€™s a look at PayPalโ€™s best practices forโ€ฆ*medium.com

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 ๐Ÿ‘‡

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)