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

Paving a New Path for GraphQL Schemas

Paving a New Path for GraphQL Schemas

GraphQL Conf Asia 2019

Fb5d018725ccbe7c4359e29edddb201d?s=128

Tim Griesser

April 13, 2019
Tweet

Transcript

  1. Paving a New Path for GraphQL Schemas @tgriesser

  2. “Fast, Reliable testing for anything that runs in a browser”

    Free, Open Source
  3. ❤ A Brief Timeline

  4. 2015: graphql-js

  5. None
  6. None
  7. Later 2015 graph.ql 2015: graphql-js

  8. Original “SDL First” Library: Released November 2015

  9. None
  10. None
  11. "

  12. Later 2015 - 2016: graph.ql graphql-tools 2015: graphql-js

  13. 2015: graphql-js Later 2015 - 2016: graph.ql graphql-tools 2017: Graphene

    (Python)
  14. None
  15. – Me, when beginning to use Graphene “Oh no, this

    library doesn’t develop the SDL first”
  16. …a few months pass

  17. – Me, after spending a few more months in Graphene

    “Hey, this is actually pretty nice… scales really well to multiple teams”
  18. Stats from Generated SDL: 307 object types 129 input types

    89 enum types 10 interfaces 5 custom scalars 1 union type 0 custom directives 2542 output fields 581 input fields 717 enum members 35 deprecations ~ 18 developers contributing to the same schema
  19. GitHub Public API SDL: 326 object types 90 input types

    70 enum types 25 interfaces 8 custom scalars 20 union types 0 custom directives 2085 output fields 307 input fields 299 enum members 6 deprecations https://github.com/octokit/graphql-schema
  20. 2015: graphql-js Later 2015 - 2016: graph.ql graphql-tools 2017: Graphene

    (Python) 2018: GraphQL Ruby
  21. None
  22. 2015: graphql-js Later 2015 - 2016: graph.ql graphql-tools 2017: Graphene

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

    not sure - SDL first seems to be unique to the JavaScript community”
  24. – Again, still just quoting my own thoughts here… “The

    JavaScript ecosystem is really missing out”
  25. Figuratively speaking, when you pave the way for someone, you

    make it easier for them to do something
  26. A better experience building code-first schemas in JavaScript & TypeScript

  27. Why not SDL first?

  28. GraphQL Nexus Why not SDL first?

  29. Related Tooling in the Ecosystem GraphQL Nexus Why not SDL

    first?
  30. Why not SDL first? Related Tooling in the Ecosystem GraphQL

    Nexus How SDL is Still Incredibly Useful
  31. Why not SDL first?

  32. Code Duplication

  33. None
  34. “Double Declaration Problem”

  35. 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
  36. Code Duplication Documentation / Type Ordering

  37. Code Duplication Documentation / Type Ordering Building For Larger Teams

  38. Code Duplication Documentation / Type Ordering Building For Larger Teams

    Tooling Complexity
  39. Code Duplication Documentation / Type Ordering Building For Larger Teams

    Tooling Complexity Microservices??
  40. None
  41. https://nexus.js.org

  42. Code First

  43. Code First Declarative

  44. None
  45. None
  46. Code First Declarative Type-Safe

  47. Code First Declarative Type-Safe JavaScript Friendly

  48. Code First Declarative Type-Safe JavaScript Friendly Opinionated

  49. Code First Declarative Type-Safe JavaScript Friendly Opinionated** **but only slightly,

    configurable, and hopefully not too controversial
  50. What makes it different??

  51. Development Feedback Loop

  52. “makeSchema”
 Generates Types

  53. “makeSchema”
 Generates Types Generated types are 
 Inferred by
 TypeScript

    Outputs SDL Schema Artifact Creates GraphQL schema Outputs TypeScript Types Imported type “registry” wired up
  54. “makeSchema”
 Generates Types Generated types are 
 Inferred by
 TypeScript

    Changes to
 Schema, Restart 
 the Server IDE Auto-Completion & Type Checking Optional for JS development
  55. “makeSchema”
 Generates Types Generated types are 
 Inferred by
 TypeScript

    Changes to
 Schema, Restart 
 the Server Regenerates SDL & Types files
  56. Type-Safety

  57. None
  58. None
  59. None
  60. Type Factories

  61. None
  62. None
  63. Opinions: Nullability

  64. – GraphQL Documentation “... in a GraphQL type system, every

    field is nullable by default. This is because there are many things which can go awry in a networked service backed by databases and other services. A database could go down, an asynchronous action could fail, an exception could be thrown. Beyond simply system failures, authorization can often be granular, where individual fields within a request can have different authorization rules.”
  65. Exceptional States Should be Exceptional: “null” to indicate network failure

    should be declared & documented
  66. – GraphQL Documentation “... in a GraphQL type system, every

    field is nullable by default. This is because there are many things which can go awry in a networked service backed by databases and other services. A database could go down, an asynchronous action could fail, an exception could be thrown. Beyond simply system failures, authorization can often be granular, where individual fields within a request can have different authorization rules.”
  67. email: String! email: "N/A" email: ""

  68. None
  69. Configurable, schema level or type level

  70. Opinions: Authorize

  71. None
  72. The SDL Converter

  73. None
  74. Paste your SDL endpoint Thanks @swcarlosrj

  75. nexus-prisma

  76. None
  77. Allows user to “override / configure” default Prisma types Allows

    you to “eject” from the Prisma DB conventions Just a thin wrapper over Nexus generated layer Similar approach could be used elsewhere, dynamic - similar to Gatsby’s approach
  78. The Bad Parts Rough Edges

  79. “makeSchema”
 Generates Types 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
  80. Other Code-First Tooling

  81. None
  82. None
  83. None
  84. What’s Next?

  85. Middleware Pipeline Progammatic Directives Better interop with SDL snippets “Missing

    field” generation hooks Input Args/Type Validation ???
  86. None
  87. SDL is Still Incredibly Useful

  88. Prototyping New Features

  89. None
  90. Users don’t see our code, they just want a good

    experience on the web
  91. Pick whichever tools help you solve problems

  92. Thanks! https://nexus.js.org @tgriesser