Day 1 - Backend with GraphQL
- Discuss Project Goal (Building a simple e-commerce website)
- Why e-commerce is a good example?
- Setup Apollo Server
- Hello World Server
- GraphQL Overview (see below)
- Defining Types and Queries
- Review Scalar Types
- Create Product Type
- Create Simple Product Query
- Create Product Query with Arguments
- Homework Assignment
- Expand Products to have Categories
- Products can belong to many Categories
- Expand Products to have Review
- Products can have many reviews
- Expand Products to have Categories
-
Quick Review: What is REST?
-
What is GraphQL?
- https://graphql.org
- https://www.graphql.com/guides/
- Just a spec, no single implementation (reference impl https://github.com/graphql/graphql-js)
-
What GraphQL isn't
- A datastore
- A programming language
- SQL
- Coupled to HTTP
-
Developer Experiance
- No need for
curl - No need for https://swagger.io
- Playground (https://developer.github.com/v4/explorer, https://github.com/prisma-labs/graphql-playground)
- Code generators https://graphql-code-generator.com/
- Editor plugins https://marketplace.visualstudio.com/items?itemName=apollographql.vscode-apollo
- No need for
-
Implementing a GraphQL server
-
Experimental
GraphQL is RESTful in many ways (client-server, stateless)
Pros:
- Increased client flexibility and control
- Simplified backend API. No need for many custom API routes that serve similar data.
- Standard for documentation
- Developer tools
Cons:
- Less optimal performance.
- Caching. No obvious key. Doesn't fit well with HTTP caching semantics
- Compatibility with HTTP. Typical to not use stadard HTTP semantics (methods, error handling)