Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Serverless GraphQL with Netlify Dev

Serverless GraphQL with Netlify Dev

GraphQL is often synonymous with the return of Monolithic architecture. Does this mean the benefits of Serverless are irrelevant? In this talk we explore how Serverless and GraphQL work together, explore ways to stitch individual function schemas, and get hard numbers to fight performance concerns.

Apollo GraphQL

May 14, 2019
Tweet

More Decks by Apollo GraphQL

Other Decks in Technology

Transcript

  1. Serverless GraphQL Apollo Day, May 2019 @swyx netlify Double Declaration

    (Frontend) https://youtu.be/30wOsJOluA4?t=507 https://babel-blade.netlify.com/
  2. Serverless GraphQL Apollo Day, May 2019 @swyx netlify DB Generated

    Schemas • !DX (DD Problem solved!) • !Speed/Optimization • !Aggregation Queries
  3. Serverless GraphQL Apollo Day, May 2019 @swyx netlify DB Generated

    Schemas • !DX (DD Problem solved!) • !Speed/Optimization • !Aggregation Queries PROS • "Resolver Spam • "Security/Auth • C, R !== U, D • "Vendor specific • Pluralizing • Parent-Child relationships • @directives • Standardize? • " Limits to Business Logic CONS?
  4. Serverless GraphQL Apollo Day, May 2019 @swyx netlify SERVERLESS GRAPHQL’S

    PROBLEM GRAPHQL NATIVE API’S DON’T SOLVE ANYTHING* *except standardization/learning curve
  5. Serverless GraphQL Apollo Day, May 2019 @swyx netlify Why Serverless

    • Fully Managed • “Just write Business Logic” • Pay Per Execution • Scalability • Immutable Deploys • Incremental Adoption
  6. Serverless GraphQL Apollo Day, May 2019 @swyx netlify SERVERLESS GRAPHQL’S

    OPPORTUNITY YOU DON’T NEED A SERVER TO USE GRAPHQL
  7. Serverless GraphQL Apollo Day, May 2019 @swyx netlify SERVERLESS GRAPHQL’S

    OPPORTUNITY ITERATE AT THE SPEED OF PRODUCT NOT PERMISSION
  8. Serverless GraphQL Apollo Day, May 2019 @swyx netlify Why Serverless

    • Fully Managed • “Just write Business Logic” • Pay Per Execution • Scalability (not SPOF) • Immutable Deploys • Incremental Adoption • Composability
  9. Serverless GraphQL Apollo Day, May 2019 @swyx netlify Gateways &

    Miniliths Pattern • Mix REST and GraphQL • Principle of Least Power • Merge & expose GraphQL-native APIs • DataLoader works at each level • Simpler Auth Model? *
  10. Serverless GraphQL Apollo Day, May 2019 @swyx netlify exports.handler =

    async function(event, context) { const schema1 = await getSchema(“/graphql-1") const schema2 = await getSchema(“/graphql-2") const schemas = [schema1, schema2] const linkTypeDefs = ` extend type Book { author: Author } ` schemas.push(linkTypeDefs) const resolvers = { Book: { author: { fragment: `... on Book { authorName }`, resolve(book, args, context, info) { return info.mergeInfo.delegateToSchema({ schema: schema1, operation: "query", fieldName: "authorByName", args: { name: book.authorName, }, context, info, }) }, }, }, } const schema = mergeSchemas({ schemas, resolvers }) const server = new ApolloServer({ schema }) return new Promise((yay, nay) => { const cb = (err, args) => (err ? nay(err) : yay(args)) server.createHandler()(event, context, cb) }) }
  11. Serverless GraphQL Apollo Day, May 2019 @swyx netlify const schema1

    = await getSchema(“/graphql-1") const schema2 = await getSchema(“/graphql-2") const extendedSchema1 = ( <schema1 author={schema2.authorByName}> {({Book}) => Book.extend("author", schema2.Author)} </schema1> ) const schemas = [extendedSchema1, schema2] “JSX” for Stitching?
  12. Serverless GraphQL Apollo Day, May 2019 @swyx netlify More R&D

    in hard problems • “Minilith” approach • Persisted Queries?? • Caching across multiple hierarchical GraphQL endpoints • graphql-compose • Compiler approach • Split schema from resolver • Modularizing Schemas • graphql-modules • graphql-import • End to End Typing • typegraphql • graphql-nexus • “Triple Declaration Problem" • Make it easier to write Fat Gateways