Lessons Learned Migrating APIs to GraphQL ๐Ÿ“

Carlos Rufo
Open GraphQL
Published in
2 min readDec 5, 2018

--

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

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!

--

--

Carlos Rufo
Open GraphQL
Writer for

๐Ÿฆ„ Engineering @GraphCMS ๐ŸŒˆ Organizer @GraphQLMadrid ๐ŸŒ  Author of http://api.spacex.land ๐ŸŒ Es ๐ŸŒŽ En ๐ŸŒ ไธญ โœŠ๐Ÿฟ #BlackLivesMatter