📜 ⬆️ ⬇️

Introducing Tartiflette: an open source implementation of GraphQL for Python 3.6+

Friends, on the eve of the May holidays, we decided not to overwhelm you with complex technical articles, so we found quite interesting, and most importantly, easy-to-read material, which we gladly share with you. This material we want to coincide with the launch of the course "Web-developer in Python" .

The original can be found here .


')
The acquisition of Vivendi dailymotion three years ago was a turning point for our organization. This allowed us to rethink the vector of our work, to rethink our work from beginning to end. We used the opportunity to assess dailymotion as a whole, rethink our infrastructure and, more importantly, the architecture of our products.

In the end, the conducted self-analysis confirmed what we already knew: we wanted to territorially distribute our platform and develop API-interfaces , mobile and TV applications. This marked the rejection of the current monolithic structure and the adoption of an API-based approach. This article describes the path we took.

Criteria and concept checks

We started the project with the definition of API criteria, which ultimately narrowed to four points:


Next, we selected several API models and tested several concepts in order to understand their feasibility:




After rigorous testing, we found that GraphQL and its implementations of Graphene best fit our criteria in comparison with other models. This allowed our front-end developers to more easily use our API, and at the same time simplify its use in client applications (for example, React JS and Apollo Client). In our architecture, GraphQL also turned out to be simpler and more efficient as a pattern gateway. As a result, we finally decided to move on with GraphQL and Graphene.

Production path

In April 2017, after intensive semi-annual development, we went into production with our API. By the summer, we transplanted all the dailymotion products (web, mobile and TV) to our GraphQL API.



When we chose GraphQL three years ago, it was still in beta and did not reach the popularity it has today. We were the first major players in this arena and this made our internal reconstruction even more pleasant.

Birth Tartiflette

In the first months of 2018, after more than half a year of using Graphene, we decided to go a step further and write our own GraphQL engine. This allowed us to implement some requirements that were not met by Graphene. We developed criteria for our own engine. He must:


After nearly a year of development and many weeks of testing our infrastructure (an average of over 100 million calls per day were processed), we proudly offer our own open source Tartiflette engine to the GraphQL community.

DNA tartiflette

Tartiflette is a implementation of GraphQL Server built on Python 3.6+
The GraphQL scheme is described using the new SDL (Schema Definition Language) ;
Productivity is a key element of our work and this is reflected in Tartiflette ;
Built to reflect Zen of Python . Not overly complicated.

Hello world on Tartiflette



import asyncio from tartiflette import Engine, Resolver @Resolver("Query.hello") async def resolver_hello(parent, args, ctx, info): return "hello " + args["name"] async def run(): ttftt = Engine(""" type Query { hello(name: String): String } """) result = await ttftt.execute( query='query { hello(name: "Chuck") }' ) print(result) # {'data': {'hello': 'hello Chuck'}} if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(run()) 

You can learn about the new functionality in the tartiflette.io manual .

What happens next with Tartiflette?

Open source Tartiflette is only the first step. Here are some ideas and future plans for the development of Tartiflette:


And we also need you!



You can use our project for almost any purpose and help us develop Tartiflette! Please check it for strength, feel free to look for errors or inconsistencies in the code and provide feedback to improve the product. We truly believe that Tartiflette will be better in close collaboration with the community.

How to contribute to the project?

Tartiflette on Github ;
Read the tartiflette.io documentation;
Send feedback and suggestions to Slack ;
Join the Twitter community.

Source: https://habr.com/ru/post/449526/


All Articles