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

SDL as an Artifact: Code-First Schemas in TS & JS

SDL as an Artifact: Code-First Schemas in TS & JS

Tim Griesser

October 31, 2019
Tweet

More Decks by Tim Griesser

Other Decks in Programming

Transcript

  1. vs

  2. – Me, when beginning to use Graphene “Oh no, this

    library doesn’t develop the SDL first”
  3. “Hey, this approach is actually very nice… scales really well

    to multiple teams working on the same schema”
  4. Stats from Graphene Generated SDL: ~ 600 types ~ 3000

    fields ~ 35 deprecations ~ 0 custom directives ~ 18 developers, 4 teams contributing to the same schema
  5. GitHub Public API SDL: ~ 500 types ~ 3000 fields

    ~ 6 deprecations ~ 0 custom directives Source: https://github.com/octokit/graphql-schema
  6. 2015: graphql-js Later 2015 - 2016: graph.ql graphql-tools 2017: Graphene

    (Python) 2018: GraphQL Ruby Also 2018: graphql-tools + graphql-code-generator
  7. – Marc-André Giroux during Q&A after at GraphQL NYC “…I’m

    not sure - SDL first seems to be unique to the JavaScript community”
  8. Why not SDL first? Related Tooling in the Ecosystem GraphQL

    Nexus How SDL is Still Incredibly Useful
  9. Implemented 16 times in GitHub’s Public API… Adding a new

    field with SDL first would mean finding all 16 locations and adding the new field
  10. Keeps your generated SDL consistent, no need to worry about

    merge conflicts or making sure fields & types you add are in the right place in a handwritten SDL file
  11. Generated types are 
 Inferred by
 TypeScript Outputs SDL Schema

    Artifact Creates GraphQL schema Outputs TypeScript Types Imported type “registry” wired up makeSchema({ types })
  12. Generated types are 
 Inferred by
 TypeScript Changes to
 Schema,

    Restart 
 the Server IDE Auto-Completion & Type Checking Optional for JS development makeSchema({ types })
  13. Generated types are 
 Inferred by
 TypeScript Changes to
 Schema,

    Restart 
 the Server Regenerates SDL & Types files makeSchema({ types })
  14. Abstracts CRUD boilerplate based on what they know about your

    database and how it interacts with the Prisma platform Allows users to override the pieces they care about as they need to evolve, rather than locking you into a certain schema up-front nexus-prisma
  15. Generated types are 
 Inferred by
 TypeScript Changes to
 Code,

    Restarts
 the Server Requires Some Configuration Chicken / Egg Problem TypeScript errors are sometimes cryptic Dynamic Types & Jump To Code The Rough Edges: makeSchema({ types })