{"id":14976145,"url":"https://github.com/denisart/graphql-query","last_synced_at":"2025-08-22T10:39:45.142Z","repository":{"id":64735255,"uuid":"577846305","full_name":"denisart/graphql-query","owner":"denisart","description":"Complete Domain Specific Language (DSL) for GraphQL query in Python.","archived":false,"fork":false,"pushed_at":"2024-11-26T13:08:10.000Z","size":127,"stargazers_count":64,"open_issues_count":5,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T00:43:51.721Z","etag":null,"topics":["code-generation","codegen","dsl","graphql","graphql-query","graphql-query-builder","pydantic","python","query-builder","query-generation","query-generator"],"latest_commit_sha":null,"homepage":"https://denisart.github.io/graphql-query/","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/denisart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-13T16:55:21.000Z","updated_at":"2025-03-03T05:27:14.000Z","dependencies_parsed_at":"2024-09-23T19:30:30.461Z","dependency_job_id":"d53899e6-f2ba-42ab-b696-95ad8053dd7a","html_url":"https://github.com/denisart/graphql-query","commit_stats":{"total_commits":57,"total_committers":5,"mean_commits":11.4,"dds":0.07017543859649122,"last_synced_commit":"22ec204a47e6b62b72d11ef0b61a05df5fb4b0a8"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisart%2Fgraphql-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisart%2Fgraphql-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisart%2Fgraphql-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisart%2Fgraphql-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denisart","download_url":"https://codeload.github.com/denisart/graphql-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650419,"owners_count":21139672,"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":["code-generation","codegen","dsl","graphql","graphql-query","graphql-query-builder","pydantic","python","query-builder","query-generation","query-generator"],"created_at":"2024-09-24T13:53:23.223Z","updated_at":"2025-04-13T00:43:54.686Z","avatar_url":"https://github.com/denisart.png","language":"Python","funding_links":[],"categories":["Web"],"sub_categories":[],"readme":"# graphql-query\n\n[![tag](https://img.shields.io/github/v/tag/denisart/graphql-query)](https://github.com/denisart/graphql-query)\n[![downloads](https://img.shields.io/pypi/dm/graphql-query)](https://pypi.org/project/graphql-query/)\n[![last-commit](https://img.shields.io/github/last-commit/denisart/graphql-query/master)](https://github.com/denisart/graphql-query/commits/master)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/graphql-query)](https://pypi.python.org/pypi/graphql-query)\n[![license](https://img.shields.io/github/license/denisart/graphql-query)](https://github.com/denisart/graphql-query/blob/master/LICENSE)\n\n---\n\n**graphql_query** is a complete Domain Specific Language (DSL) for GraphQL query in Python. With this package\nyou can to\n\n- generate a correct GraphQL query string from a python classes;\n- use and share similar Arguments, Variables and e.t.c between different queries;\n- easily add new fields to your query;\n- add Fragments and Directives to queries;\n- generate **graphql_query** classes from pydantic data-model;\n\nThe documentation for **graphql_query** can be found at [https://denisart.github.io/graphql-query/](https://denisart.github.io/graphql-query/).\n\n## Quickstart\n\nInstall with pip\n\n```bash\npip install graphql_query\n```\n\n### Simple query\n\nCode for the simple query\n\n```graphql\n{\n  hero {\n    name\n  }\n}\n```\n\nit is\n\n```python\nfrom graphql_query import Operation, Query\n\nhero = Query(name=\"hero\", fields=[\"name\"])\noperation = Operation(type=\"query\", queries=[hero])\n\nprint(operation.render())\n\"\"\"\nquery {\n  hero {\n    name\n  }\n}\n\"\"\"\n```\n\nThe `render` method for the `graphql_query.Operation` object\njust returns the final string with a query. Inside the `fields` array of the `graphql_query.Query` object\nyou can use\n\n- `str` (a field name);\n- object of `graphql_query.Field` type;\n- `graphql_query.Fragment` and `graphql_query.InlineFragment`.\n\n### Arguments, Variables and Directives\n\nFor generation of the following query\n\n```graphql\nquery Hero($episode: Episode, $withFriends: Boolean!) {\n  hero(episode: $episode) {\n    name\n    friends @include(if: $withFriends) {\n      name\n    }\n  }\n}\n```\n\nwe can use the following python code\n\n```python\nfrom graphql_query import Argument, Directive, Field, Operation, Query, Variable\n\nepisode = Variable(name=\"episode\", type=\"Episode\")\nwithFriends = Variable(name=\"withFriends\", type=\"Boolean!\")\n\narg_episode = Argument(name=\"episode\", value=episode)\narg_if = Argument(name=\"if\", value=withFriends)\n\nhero = Query(\n    name=\"hero\",\n    arguments=[arg_episode],\n    fields=[\n        \"name\",\n        Field(\n            name=\"friends\",\n            fields=[\"name\"],\n            directives=[Directive(name=\"include\", arguments=[arg_if])]\n        )\n    ]\n)\noperation = Operation(\n    type=\"query\",\n    name=\"Hero\",\n    variables=[episode, withFriends],\n    queries=[hero]\n)\nprint(operation.render())\n\"\"\"\nquery Hero(\n  $episode: Episode\n  $withFriends: Boolean!\n) {\n  hero(\n    episode: $episode\n  ) {\n    name\n    friends @include(\n      if: $withFriends\n    ) {\n      name\n    }\n  }\n}\n\"\"\"\n```\n\nYou can find other examples in the documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenisart%2Fgraphql-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenisart%2Fgraphql-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenisart%2Fgraphql-query/lists"}