GraphQL Design Tips
- Design for behaviors or use-cases over data or Think Domain over data
- Be careful with Atomicity vs Granularity
- Stay away from trying to build a “One size fits all” API
- Sometimes we all make mistakes :)… use @Deprecated directives judiciously and provide valid “reason” & “alternative way” while doing so. Understand first: Who is using? How much is used?
- Talk to, (or become) domain experts
- GraphQL Spec doesn’t have any opinion about Auth. That leaves us with 3 options:
- Wrap Resolvers
- Write Custom Directives or
- Delegate to Abstraction Layers (AppSync / Apollo) => github.com/chenkie/graphql-auth
- Fetch data optimally. Just as it is not good to fetch everything at once; it's easy to get burned by over-fetching with "top-heavy" parent-to-child resolvers. Fetching and passing data from parent-to-child should be used sparingly.
- Use libraries like "https://github.com/facebook/dataloader" to de-dupe downstream requests.
- Write resolvers that are readable, maintainable, testable. Not too clever.
- Make your resolvers as thin as possible. Extract out data fetching logic to re-usable async functions.
- Avoid use of GraphQL for purely Fileupload use-cases as it is a big deal for GraphQL in general.
No comments:
Post a Comment