{"id":15818706,"url":"https://github.com/avanov/graphql-dsl","last_synced_at":"2025-09-02T04:05:45.575Z","repository":{"id":50238671,"uuid":"256550537","full_name":"avanov/graphql-dsl","owner":"avanov","description":"Compose GraphQL queries by composing Python types!","archived":false,"fork":false,"pushed_at":"2021-05-31T23:10:51.000Z","size":52,"stargazers_count":5,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2024-10-06T06:04:26.502Z","etag":null,"topics":["dsl","edsl","graphql","python","query-builder","type-hints","typing"],"latest_commit_sha":null,"homepage":"https://graphql-dsl.rtfd.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avanov.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["avanov"]}},"created_at":"2020-04-17T16:09:55.000Z","updated_at":"2024-03-17T20:26:38.000Z","dependencies_parsed_at":"2022-09-19T17:11:47.870Z","dependency_job_id":null,"html_url":"https://github.com/avanov/graphql-dsl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avanov%2Fgraphql-dsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avanov%2Fgraphql-dsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avanov%2Fgraphql-dsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avanov%2Fgraphql-dsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avanov","download_url":"https://codeload.github.com/avanov/graphql-dsl/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246635946,"owners_count":20809330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsl","edsl","graphql","python","query-builder","type-hints","typing"],"created_at":"2024-10-05T06:04:36.377Z","updated_at":"2025-04-01T17:32:56.548Z","avatar_url":"https://github.com/avanov.png","language":"Python","funding_links":["https://github.com/sponsors/avanov"],"categories":[],"sub_categories":[],"readme":".. _badges:\n\n.. image:: https://github.com/avanov/graphql-dsl/workflows/GitHub%20CI/badge.svg?branch=develop\n    :target: https://github.com/avanov/graphql-dsl/actions?query=workflow%3A%22GitHub+CI%22\n\n.. image:: https://travis-ci.org/avanov/graphql-dsl.svg?branch=develop\n    :target: https://travis-ci.org/avanov/graphql-dsl\n\n.. image:: https://circleci.com/gh/avanov/graphql-dsl/tree/develop.svg?style=svg\n    :target: https://circleci.com/gh/avanov/graphql-dsl/tree/develop\n\n.. image:: https://coveralls.io/repos/github/avanov/graphql-dsl/badge.svg?branch=develop\n    :target: https://coveralls.io/github/avanov/graphql-dsl?branch=develop\n\n.. image:: https://requires.io/github/avanov/graphql-dsl/requirements.svg?branch=develop\n    :target: https://requires.io/github/avanov/graphql-dsl/requirements/?branch=develop\n    :alt: Requirements Status\n\n.. image:: https://readthedocs.org/projects/graphql-dsl/badge/?version=develop\n    :target: http://graphql-dsl.readthedocs.org/en/develop/\n    :alt: Documentation Status\n\n.. image:: http://img.shields.io/pypi/v/graphql-dsl.svg\n    :target: https://pypi.python.org/pypi/graphql-dsl\n    :alt: Latest PyPI Release\n\nCompose GraphQL queries by composing Python types\n=================================================\n\n.. code-block:: bash\n\n    pip install graphql-dsl\n\nLet's take a manually written `GraphQL query from the official docs \u003chttps://graphql.org/learn/schema/#the-query-and-mutation-types\u003e`_:\n\n.. code-block::\n\n    query {\n        hero {\n            name\n        }\n        droid(id: \"2000\") {\n            name\n        }\n    }\n\n\nWith ``graphql-dsl`` you can construct a similar query with the following Python snippet:\n\n.. code-block:: python\n\n    from typing import NamedTuple\n    from graphql_dsl import *\n\n    class Hero(NamedTuple):\n        name: str\n\n    class Droid(NamedTuple):\n        name: str\n\n    class HeroAndDroid(NamedTuple):\n        hero: Hero\n        droid: Droid\n\n    class Input(NamedTuple):\n        droid_id: ID\n\n    q = GQL( QUERY | HeroAndDroid\n           | WITH  | Input\n           | PASS  | Input.droid_id * TO * HeroAndDroid.droid * AS * 'id'\n           )\n\n    print(q.query)\n\nand the output will be::\n\n    query HeroAndDroid($droidId:ID!){hero{name}droid(id:$droidId){name}}\n\nThe value of ``q.query`` is a GraphQL query template that should be used with instances of ``Input`` to call\nservers with GraphQL API\n\n.. code-block:: python\n\n    import requests\n\n    q = GQL(...)\n\n    def call_server(droid_id: ID) -\u003e HeroAndDroid:\n        response = requests.post(\n            url='https://\u003cgraphql-server-url\u003e/',\n            json=q.request_payload(Input(droid_id=droid_id)),\n            headers={ 'Content-Type': 'application/json'\n                    , 'Accept': 'application/json'\n                    }\n        )\n        response.raise_for_status()\n        return q.get_result(response.json())\n\nNote that the query `q` resides at the top-level module scope, as the query constructor doesn't depend on the\nquery's input values, it only needs to know about the shapes of input and output data.\n\nThe query builder supports both ``NamedTuple`` and ``@dataclass`` types, yet the latter has a slightly different\nfield reference syntax (because dataclasses don't define class-level field getters):\n\n.. code-block:: python\n\n    from dataclasses import dataclass\n    from graphql_dsl import *\n\n    @dataclass\n    class Hero:\n        name: str\n\n    @dataclass\n    class Droid:\n        name: str\n\n    @dataclass\n    class HeroAndDroid:\n        hero: Hero\n        droid: Droid\n\n    @dataclass\n    class Input:\n        droid_id: ID\n\n    q = GQL( QUERY | HeroAndDroid\n           | WITH  | Input\n           | PASS  | (Input, 'droid_id') * TO * (HeroAndDroid, 'droid') * AS * 'id'\n           )\n\nFind out more from `Official Documentation \u003chttps://graphql-dsl.readthedocs.io/en/develop/\u003e`_.\n\n\nTest Suite\n----------\n\nTest environment is based on `Nix \u003chttps://nixos.org/nix/\u003e`_.\n\n.. code-block:: bash\n\n    nix-shell\n    pytest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favanov%2Fgraphql-dsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favanov%2Fgraphql-dsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favanov%2Fgraphql-dsl/lists"}