Take a dive into the future of API's with GraphQL, and it's most popular framework: Apollo! What is GraphQL? Why would you use it? Why is it the future? Let's jump in and find out!
/ dependencies / config 3. Set up server 4. How to GraphQL a. Schema b. Resolvers c. Query / Mutate i. Graphiql ii. Query / Mutation patterns 5. Refactor for scale 6. GraphQL over REST 7. Why Apollo? 8. Resources TL;DR / FYI This will be a high level overview with some code examples (API heavy)! If you want more info or want to talk specifics - feel free to email me! [email protected]
by Facebook • Great for mobile / slower networks • Replacement for REST • GraphQL is BOTH a declarative query language for getting data AND a specification for an API service that will handle GraphQL requests. • Faster iteration during development (no API versioning) • Can use with the increasing variety of front ends • No overfetching or underfetching data • Once schema is set, backend and frontend can work independently • Transport layer agnostic (TCP/IP, Web Sockets, ect) • BONUS: Apollo has a caching layer (can replace Redux!)
define how (what shape) you want your data to be exposed to your client or whatever other service will be consuming it. Types • Object Type • Arrays • Scalar Types ◦ String ◦ Int ◦ Float ◦ Boolean • Enum Types ◦ Set Values • Queries ◦ Arguments • Mutations ◦ Complex inputs • Subscriptions** • Interfaces** • Unions**
define how (what shape) you want your data to be exposed to your client or whatever other service will be consuming it. Step 2 Define your Resolvers Define all your data endpoints, API’s, Databases, Services, ect where your data will come from and let GraphQL know how to get it. Resolvers fieldName(obj, args, context, info) { result } 1. obj: The object that contains the result returned from the resolver on the parent field, or, in the case of a top-level Query field, the rootValue passed from the server configuration. 2. args: An object with the arguments passed into the field in the query. 3. context: This is an object shared by all resolvers in a particular query, and is used to contain per-request state. 4. info: This argument should only be used in advanced cases, but it contains information about the execution state of the query.
define how (what shape) you want your data to be exposed to your client or whatever other service will be consuming it. Step 2 Define your Resolvers Define all your data endpoints, API’s, Databases, Services, ect where your data will come from and let GraphQL know how to get it. Step 3 Use the data in your app! Use queries to grab whatever data you want from your single GraphQL endpoint. Use it throughout your application easily Resolvers Query
queries: Put the consumer of the API in full control over what data they receive. Parse on Server, not Client: Server does it automatically! No custom code for parsing from source! Query consolidation: Single query, multiple data types! Executed in parallel on the server. No more API endpoint sprawl: Write the code for accessing a data type, and you won’t have to re-implement it. Type-safe, self-documenting: GRAPHIQL!!! Server-side Data Caching: Reduce network traffic by caching common queries on server
Native • Vue • Angular • Android • iOS • Meteor (created Apollo) With React: can use HOC or Render props for Apollo Client Intelligent caching: Persistent caching for PWA’s Can actually use Apollo without Graphql Apollo dev tools tab Apollo Servers: • Express • Connect • Hapi • Koa • Restify • Lambda • Micro • Azure-functions • Adonis • Support HTTP query batching • Support Apollo Tracing to get performance information about your server • Support Apollo Cache Control to inform caching gateways such as Apollo Engine