{"id":13565996,"url":"https://github.com/kensho-technologies/graphql-compiler","last_synced_at":"2025-10-28T16:31:14.188Z","repository":{"id":50145192,"uuid":"97647864","full_name":"kensho-technologies/graphql-compiler","owner":"kensho-technologies","description":"Turn complex GraphQL queries into optimized database queries.","archived":false,"fork":false,"pushed_at":"2022-12-09T05:19:28.000Z","size":6652,"stargazers_count":551,"open_issues_count":111,"forks_count":50,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-02-05T22:15:39.116Z","etag":null,"topics":["compiler","database","graphql","graphql-query","orientdb","python","sql"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kensho-technologies.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.rst","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-18T22:03:41.000Z","updated_at":"2025-01-02T13:36:24.000Z","dependencies_parsed_at":"2023-01-25T11:00:33.162Z","dependency_job_id":null,"html_url":"https://github.com/kensho-technologies/graphql-compiler","commit_stats":null,"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kensho-technologies%2Fgraphql-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kensho-technologies%2Fgraphql-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kensho-technologies%2Fgraphql-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kensho-technologies%2Fgraphql-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kensho-technologies","download_url":"https://codeload.github.com/kensho-technologies/graphql-compiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238677022,"owners_count":19511928,"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":["compiler","database","graphql","graphql-query","orientdb","python","sql"],"created_at":"2024-08-01T13:01:59.729Z","updated_at":"2025-10-28T16:31:13.492Z","avatar_url":"https://github.com/kensho-technologies.png","language":"Python","readme":"graphql-compiler\n================\n\n|Build Status| |Coverage Status| |License| |PyPI Python| |PyPI Version|\n|PyPI Status| |PyPI Wheel| |Code Style|\n\nTurn complex GraphQL queries into optimized database queries.\n\n::\n\n    pip install graphql-compiler\n\nQuick Overview\n--------------\n\nGraphQL compiler is a library that simplifies data querying and exploration by exposing one\nsimple query language written using GraphQL syntax to target multiple database backends. It\ncurrently supports `OrientDB \u003chttps://graphql-compiler.readthedocs.io/en/latest/supported_databases/orientdb.html\u003e`__.\nand multiple `SQL \u003chttps://graphql-compiler.readthedocs.io/en/latest/supported_databases/sql.html\u003e`__\ndatabase management systems, such as PostgreSQL, MSSQL and MySQL.\n\nFor a detailed overview, see `our blog post \u003chttps://blog.kensho.com/compiled-graphql-as-a-database-query-language-72e106844282\u003e`__.\nTo get started, see `our Read the Docs documentation \u003chttps://graphql-compiler.readthedocs.io/en/latest/\u003e`__.\nTo contribute, please see `our contributing guide \u003chttps://graphql-compiler.readthedocs.io/en/latest/about/contributing.html\u003e`__.\n\nExamples\n~~~~~~~~\n\n.. HACK: To avoid duplicating the end-to-end examples, we use the `include` restructured text\n         directive. We add the comments below to mark the start and end of the text that the\n         `include` directive has to copy. An alternative here would be to add an examples directory\n         and \"include\" the examples from there in both the README and Read the Docs. However, github\n         does not support the `include` directive: https://github.com/github/markup/issues/172\n\nOrientDB\n^^^^^^^^\n\n.. end-to-end-orientdb-example-start\n\n.. code:: python\n\n    from graphql.utils.schema_printer import print_schema\n    from graphql_compiler import (\n        get_graphql_schema_from_orientdb_schema_data, graphql_to_match\n    )\n    from graphql_compiler.schema.schema_info import CommonSchemaInfo\n    from graphql_compiler.schema_generation.orientdb.utils import ORIENTDB_SCHEMA_RECORDS_QUERY\n\n    # Step 1: Get schema metadata from hypothetical Animals database.\n    client = your_function_that_returns_an_orientdb_client()\n    schema_records = client.command(ORIENTDB_SCHEMA_RECORDS_QUERY)\n    schema_data = [record.oRecordData for record in schema_records]\n\n    # Step 2: Generate GraphQL schema from metadata.\n    schema, type_equivalence_hints = get_graphql_schema_from_orientdb_schema_data(schema_data)\n\n    print(print_schema(schema))\n    # schema {\n    #    query: RootSchemaQuery\n    # }\n    #\n    # directive @filter(op_name: String!, value: [String!]!) on FIELD | INLINE_FRAGMENT\n    #\n    # directive @tag(tag_name: String!) on FIELD\n    #\n    # directive @output(out_name: String!) on FIELD\n    #\n    # directive @output_source on FIELD\n    #\n    # directive @optional on FIELD\n    #\n    # directive @recurse(depth: Int!) on FIELD\n    #\n    # directive @fold on FIELD\n    #\n    # type Animal {\n    #     name: String\n    #     net_worth: Int\n    #     limbs: Int\n    # }\n    #\n    # type RootSchemaQuery{\n    #     Animal: [Animal]\n    # }\n\n    # Step 3: Write GraphQL query that returns the names of all animals with a certain net worth.\n    # Note that we prefix net_worth with '$' and surround it with quotes to indicate it's a parameter.\n    graphql_query = '''\n    {\n        Animal {\n            name @output(out_name: \"animal_name\")\n            net_worth @filter(op_name: \"=\", value: [\"$net_worth\"])\n        }\n    }\n    '''\n    parameters = {\n        'net_worth': '100',\n    }\n\n    # Step 4: Use autogenerated GraphQL schema to compile query into the target database language.\n    common_schema_info = CommonSchemaInfo(schema, type_equivalence_hints)\n    compilation_result = graphql_to_match(common_schema_info, graphql_query, parameters)\n    print(compilation_result.query)\n    # SELECT Animal___1.name AS `animal_name`\n    # FROM  ( MATCH  { class: Animal, where: ((net_worth = decimal(\"100\"))), as: Animal___1 }\n    # RETURN $matches)\n\n.. end-to-end-orientdb-example-end\n\nSQL\n^^^\n\n.. end-to-end-sql-example-start\n\n.. code:: python\n\n    from graphql_compiler import get_sqlalchemy_schema_info, graphql_to_sql\n    from sqlalchemy import MetaData, create_engine\n\n    engine = create_engine('\u003cconnection string\u003e')\n\n    # Reflect the default database schema. Each table must have a primary key. Otherwise see:\n    # https://graphql-compiler.readthedocs.io/en/latest/supported_databases/sql.html#including-tables-without-explicitly-enforced-primary-keys\n    metadata = MetaData(bind=engine)\n    metadata.reflect()\n\n    # Wrap the schema information into a SQLAlchemySchemaInfo object.\n    sql_schema_info = get_sqlalchemy_schema_info(metadata.tables, {}, engine.dialect)\n\n    # Write GraphQL query.\n    graphql_query = '''\n    {\n        Animal {\n            name @output(out_name: \"animal_name\")\n        }\n    }\n    '''\n    parameters = {}\n\n    # Compile and execute query.\n    compilation_result = graphql_to_sql(sql_schema_info, graphql_query, parameters)\n    query_results = [dict(row) for row in engine.execute(compilation_result.query)]\n\n.. end-to-end-sql-example-end\n\nLicense\n-------\n\nLicensed under the Apache 2.0 License. Unless required by applicable law\nor agreed to in writing, software distributed under the License is\ndistributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied. See the License for the specific\nlanguage governing permissions and limitations under the License.\n\nCopyright 2017-present Kensho Technologies, LLC. The present date is\ndetermined by the timestamp of the most recent commit in the repository.\n\n.. |Build Status| image:: https://github.com/kensho-technologies/graphql-compiler/workflows/Tests%20and%20lint/badge.svg\n   :target: https://github.com/kensho-technologies/graphql-compiler/actions?query=workflow%3A%22Tests+and+lint%22\n.. |Coverage Status| image:: https://codecov.io/gh/kensho-technologies/graphql-compiler/branch/main/graph/badge.svg\n   :target: https://codecov.io/gh/kensho-technologies/graphql-compiler\n.. |License| image:: https://img.shields.io/badge/License-Apache%202.0-blue.svg\n   :target: https://opensource.org/licenses/Apache-2.0\n.. |PyPI Python| image:: https://img.shields.io/pypi/pyversions/graphql-compiler.svg\n   :target: https://pypi.python.org/pypi/graphql-compiler\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/graphql-compiler.svg\n   :target: https://pypi.python.org/pypi/graphql-compiler\n.. |PyPI Status| image:: https://img.shields.io/pypi/status/graphql-compiler.svg\n   :target: https://pypi.python.org/pypi/graphql-compiler\n.. |PyPI Wheel| image:: https://img.shields.io/pypi/wheel/graphql-compiler.svg\n   :target: https://pypi.python.org/pypi/graphql-compiler\n.. |Code Style| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :target: https://github.com/psf/black\n   :alt: Code style: black\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkensho-technologies%2Fgraphql-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkensho-technologies%2Fgraphql-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkensho-technologies%2Fgraphql-compiler/lists"}