Why SDL First Might Win the Battle of GraphQL Design Methodologies

During his presentation at GraphQL Conference 2019 in Berlin Germany, Stan Chollet (Lead at Tartiflette.io) announced after two years of work that the company has released Tartiflette for Python 3.6+. Tartiflette is an implementation of the GraphQL specification.

The framework is targetted for use by Python developers who want to take an “SDL First” when creating a GraphQL API under Python.

Unlike the “Code First” school of GraphQL API development in which a developer creates a representation of a GraphQL API in a strong-typed language such as TypeScript first, which is then converted into a schema definition in GraphQL’s Schema Definition Language (SDL), Tartiflette allows the developer to define the schema in pure SDL first, hence the “SDL First” approach. Then, those pure SDL type definitions are copied into corresponding .graphql files according to the Tartiflette file and directory structure. The developer writes resolver code in Python that provides the behavior for the GraphQL Queries, Mutations, and Subscriptions represented in the type definitions. Once the SDL types are defined and the resolvers are written, the API is launched using Tartiflette register_graphql_handlers in conjunction Python’s aiohttp web server engine.

Chollet shared that taking an SDL First approach to GraphQL API development gives developers the flexibility to program as they want using the tools that best suit their needs.

Chollet also mentioned that in order to make creating GraphQL APIs an easier, faster undertaking Tartiflette maintains a plugin ecosystem that allows developers to write and share Tartiflette plugin code that is reusable among a variety of Tartiflette applications. According to Chollet plugin development is particularly useful for supporting GraphQL directives, scalars, and types that lend themselves to a high degree of reuse among projects.

For example, Tartiflette publishes a plugin for a custom GraphQL FIELD_DEFINITION directive, @timeIt. @timeIt logs execution time when added to a field in a GraphQL type definition, like so:

type Example {
    aField: String @timeIt
}

The company hopes that a thriving marketplace of third-party plugins will encourage GraphQL API development using Tartiflette.

Tartiflette source code and plugin development samples are available on GitHub, here.

Be sure to read the next API Design article: GraphQL Nexus Enhances Code First Capabilities for GraphQL API Development

 

Comments (0)