Tomek Poniatowicz
8/27/2020
GraphQL started back in 2012 at Facebook HQ. Before being publicly released in 2015 it was used internally as a cure to the underperformance observed in mobile apps on slower networks. GraphQL is a query language for APIs, its main advantage is allowing clients to define exactly what type of data is required. The centerpiece of any GraphQL project is its schema.
GraphQL schema is a set of rules describing the functionality available to the client, including specification of operations (queries and mutations) that can be executed to execute against your data graph.
If you ever decide to build a GraphQL service at some point you would need to chose which approach you want to affiliate with more:
In either case, we will end up with a fully functional GraphQL service, but this choice will influence your project in terms of the amount of work you will need to put to achieve certain things like scaling your project etc.
Schema-first
Schema-first is an approach that puts schema as your source of truth and forces your code to follow the definitions stored in your schema. In general, prioritizing thinking about the schema. If schema design falls short, you might end up with an API that's ignoring your business needs and needs of your end-users.
Some of the pros:
Some of the cons/difficulties:
Code-first (often called resolver-first) is a process where the schema is defined and implemented programmatically. The design process begins with coding the resolvers and the SDL version of the GraphQL schema is a generated artifact (created with a script, not manually).
Some of the pros:
Some of the cons/difficulties:
When GraphQL was publicly released in the 2015 ecosystem we know haven't existed (quite obvious) and the only things that we could lean on were the official GraphQL specification and graphql-js
(the reference implementation in JavaScript) until 2016 when graphql-tools
repo was founded which firstly promoted schema-first approach by separating two layers of working with schema:
After that, the schema-first become default approach but seeing its limitations people started looking for some workarounds which led to first code-first frameworks being released. The Code-first approach is becoming so popular that almost every GraphQL implementation now has its code-first alternative, or even focusing on only the code-first path.
Language | Schema-first implementation | Code-first implementation |
---|---|---|
JavaScript/TypeScript | Apollo server | Nexus |
PHP (Laravel) | Lighthouse | laravel-graphql |
PHP (WP) | x | WPGraphQL |
Python | Ariadne | Graphene |
.NET | GraphQL for .NET | GraphQL for .NET |
Rust | x | Juniper |
What would 2020 bring? Well, I can't wait to find out :)