Git Product home page Git Product logo

turms's Introduction

turms

codecov PyPI version Maintenance Maintainer PyPI pyversions PyPI status PyPI download month

Goal

Turms is a graphql-codegen inspired code generator for python that generates typed and serializable python code from your graphql schema and documents. Just define your query in standard graphql syntax and let turms create fully typed queries/mutation and subscriptions, that you can use in your favourite IDE.

Turms allows you to easily generate both server-side and client-side code for your GraphQL API.

Schema (Server) Generation:

Can generate the following types from your graphql SDL schema:

  • Enums
  • Inputs
  • Objects
  • Scalars
  • Directives

Sepcific generation supported for:

  • Strawberry
  • Graphene

Documents (Client) Generation

Can generate the following pydantic models from your graphql documents:

  • Enums
  • Inputs
  • Scalars
  • Fragments
  • Operations

Features

  • Fully typed, fully documented code generation
  • Schema and Document based code generation
  • Compatible with popular graphql libraries (strawberry, gql, rath, etc.)
  • Support for custom scalars, custom directives, ...
  • Powerful plugin system (e.g. custom Linting, custom formatting, etc.)
  • Operation functions like query, mutation, subscription (e.g. data= get_capsules())
  • Compliant with graphl-config
  • Code migration support (trying to merge updates into existing code)

Installation

pip install turms

turms is a pure development library and will not introduce any dependency on itself into your code, so we recommend installing turms as a development dependency.

poetry add -D turms

As of now turms only supports python 3.9 and higher (as we rely on ast unparsing)

Configuration

Turms relies on and complies with graphql-config and searches your current working dir for the graphql-config file.

Document based generation

Based on pydantic models

projects:
  default:
    schema: http://api.spacex.land/graphql/
    documents: graphql/**.graphql
    extensions:
      turms: # path for configuration for turms
        out_dir: examples/api
        plugins: # path for plugin configuration
          - type: turms.plugins.enums.EnumsPlugin
          - type: turms.plugins.inputs.InputsPlugin
          - type: turms.plugins.fragments.FragmentsPlugin
          - type: turms.plugins.operation.OperationsPlugin
          - type: turms.plugins.funcs.FuncsPlugin
        processors:
          - type: turms.processor.black.BlackProcessor
          - type: turms.processor.isort.IsortProcessor
        scalar_definitions:
          uuid: str
          timestamptz: str
          Date: str

Schema based generation

Based on strawberry models

projects:
  default:
    schema: beasts.graphql
    extensions:
      turms:
        skip_forwards: true
        out_dir: api
        stylers:
          - type: turms.stylers.capitalize.CapitalizeStyler
          - type: turms.stylers.snake_case.SnakeCaseStyler
        plugins:
          - type: turms.plugins.strawberry.StrawberryPlugin # generates a strawberry schema
        processors:
          - type: turms.processors.disclaimer.DisclaimerProcessor
          - type: turms.processors.black.BlackProcessor
          - type: turms.processors.isort.IsortProcessor
          - type: turms.processors.merge.MergeProcessor # merges the formated schema with already defined functions
        scalar_definitions:
          uuid: str
          _Any: typing.Any

Usage

Once you have configured turms you can generate your code by running

turms gen

Why Turms

In Etruscan religion, Turms (usually written as ๐Œ•๐Œ–๐Œ“๐ŒŒ๐Œ‘ Turmล› in the Etruscan alphabet) was the equivalent of Roman Mercury and Greek Hermes, both gods of trade and the messenger god between people and gods.

Transport Layer

Turms does not come with a default transport layer but if you are searching for an Apollo-like GraphQL Client you can check out rath, that works especially well with turms.

Examples

This github repository also contains some examples on how to use turms with popular libraries in the graphql ecosystem.

turms's People

Contributors

jhnnsrs avatar strue36 avatar imadmoussa1 avatar j-riebe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.