{"id":16654408,"url":"https://github.com/somada141/demo-graphql-sqlalchemy-falcon","last_synced_at":"2025-04-09T18:12:37.190Z","repository":{"id":87116676,"uuid":"134661912","full_name":"somada141/demo-graphql-sqlalchemy-falcon","owner":"somada141","description":"Basic demo using GraphQL (via Graphene), SQLAlchemy, and Falcon.","archived":false,"fork":false,"pushed_at":"2018-07-27T06:31:30.000Z","size":214,"stargazers_count":21,"open_issues_count":0,"forks_count":6,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-09T18:12:32.135Z","etag":null,"topics":["falcon","graphene","graphene-sqlalchemy","graphiql","graphql","gunicorn","python","sqlalchemy"],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/somada141.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-24T04:43:21.000Z","updated_at":"2024-05-22T14:44:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"3bd6bc77-b381-483a-b281-40ab72495e5a","html_url":"https://github.com/somada141/demo-graphql-sqlalchemy-falcon","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/somada141%2Fdemo-graphql-sqlalchemy-falcon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somada141%2Fdemo-graphql-sqlalchemy-falcon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somada141%2Fdemo-graphql-sqlalchemy-falcon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somada141%2Fdemo-graphql-sqlalchemy-falcon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/somada141","download_url":"https://codeload.github.com/somada141/demo-graphql-sqlalchemy-falcon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085326,"owners_count":21045139,"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":["falcon","graphene","graphene-sqlalchemy","graphiql","graphql","gunicorn","python","sqlalchemy"],"created_at":"2024-10-12T09:49:42.299Z","updated_at":"2025-04-09T18:12:37.185Z","avatar_url":"https://github.com/somada141.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# demo-graphql-sqlalchemy-falcon\n\n## Overview\n\nThis is a simple project demonstrating the implementation of a GraphQL server in Python using:\n\n- [SQLAlchemy](https://github.com/zzzeek/sqlalchemy).\n- [Falcon](https://github.com/falconry/falcon).\n- [Graphene](https://github.com/graphql-python/graphene).\n- [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy).\n- [Gunicorn](https://github.com/benoitc/gunicorn).\n\nThe objective is to demonstrate how these different libraries can be integrated.\n\n## Features\n\nThe primary feature offered by this demo are:\n\n- [SQLAlchemy](https://github.com/zzzeek/sqlalchemy) ORM against a local SQLite database. The ORM is super simple but showcases a many-to-many relationship between `authors` and `books` via an `author_books` association table.\n- [Falcon](https://github.com/falconry/falcon) resources to serve both [GraphQL](https://github.com/facebook/graphql) and [GraphiQL](https://github.com/graphql/graphiql).\n\n\u003e The [Falcon](https://github.com/falconry/falcon) resources are slightly modified versions of the ones under [https://github.com/alecrasmussen/falcon-graphql-server](https://github.com/alecrasmussen/falcon-graphql-server) so all credits to [Alec Rasmussen](https://github.com/alecrasmussen).\n\n- Basic [GraphQL](https://github.com/facebook/graphql) schema automatically derived from the [SQLAlchemy](https://github.com/zzzeek/sqlalchemy) ORM via [Graphene](https://github.com/graphql-python/graphene) and [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy).\n- API setup via [Falcon](https://github.com/falconry/falcon) with the whole thing served via [Gunicorn](https://github.com/benoitc/gunicorn).\n\n## Usage\n\nAll instructions and commands below are meant to be run from the root dir of this repo.\n\n### Prerequisites\n\nYou are strongly encouraged to use a virtualenv here but I can be assed writing down the instructions for that.\n\nInstall all requirements through:\n\n```\npip install -r requirements.txt\n```\n\n### Sample Database\n\nThe sample SQLite database has been committed in this repo but can easily be rebuilt through:\n\n```\npython -m demo.orm\n```\n\nat which point it will create a `demo.db` in the root of this repo.\n\n\u003e The sample data are defined under `data.py` while they're ingested with the code under the `main` sentinel in `orm.py`. Feel free to tinker.\n\n### Running Server\n\nThe [Gunicorn](https://github.com/benoitc/gunicorn) is configured via the `gunicorn_config.py` module and binds by default to `localhost:5432/`. You can change all gunicorn configuration options under the aforementioned module.\n\nThe server can be run through:\n\n```\ngunicorn -c gunicorn_config.py \"demo.demo:main()\"\n```\n\nThe server exposes two endpoints:\n\n- `/graphql`: The standard GraphQL endpoint which can receive the queries directly (accessible by default under [http://localhost:5432/graphql](http://localhost:5432/graphql)).\n- `/graphiql`: The [GraphiQL](https://github.com/graphql/graphiql) interface (accessible by default under [http://localhost:5432/graphiql](http://localhost:5432/graphiql)).\n\n### Queries\n\nHere's a couple example queries you can either run directly in [GraphiQL](https://github.com/graphql/graphiql) or by performing POST requests against the [GraphQL](https://github.com/facebook/graphql) server.\n\n#### Get an author by ID\n\nQuery:\n\n```\nquery getAuthor{\n  author(authorId: 1) {\n    nameFirst,\n    nameLast\n  }\n}\n```\n\nResponse:\n\n```\n{\n  \"data\": {\n    \"author\": {\n      \"nameFirst\": \"Robert\",\n      \"nameLast\": \"Jordan\"\n    }\n  }\n}\n```\n\n#### Get an author by first name\n\n```\nquery getAuthor{\n  author(nameFirst: \"Robert\") {\n    nameFirst,\n    nameLast\n  }\n}\n```\n\nResponse:\n\n```\n{\n  \"data\": {\n    \"author\": {\n      \"nameFirst\": \"Robert\",\n      \"nameLast\": \"Jordan\"\n    }\n  }\n}\n```\n\n### Get an author and their books\n\nQuery:\n\n```\nquery getAuthor{\n  author(nameFirst: \"Brandon\") {\n    nameFirst,\n    nameLast,\n    books {\n      title,\n      year\n    }\n  }\n}\n```\n\nResponse:\n\n```\n{\n  \"data\": {\n    \"author\": {\n      \"nameFirst\": \"Brandon\",\n      \"nameLast\": \"Sanderson\",\n      \"books\": [\n        {\n          \"title\": \"The Gathering Storm\",\n          \"year\": 2009\n        },\n        {\n          \"title\": \"Towers of Midnight\",\n          \"year\": 2010\n        },\n        {\n          \"title\": \"A Memory of Light\",\n          \"year\": 2013\n        }\n      ]\n    }\n  }\n}\n```\n\n#### Get books by year\n\nQuery:\n\n```\nquery getBooks{\n  books(year: 1990) {\n    title,\n    year\n  }\n}\n```\n\nResponse:\n\n```\n{\n  \"data\": {\n    \"books\": [\n      {\n        \"title\": \"The Eye of the World\",\n        \"year\": 1990\n      },\n      {\n        \"title\": \"The Great Hunt\",\n        \"year\": 1990\n      }\n    ]\n  }\n}\n```\n\n#### Get books and their authors by their title\n\nQuery:\n\n```\nquery getBooks{\n  books(title: \"A Memory of Light\") {\n    title,\n    year,\n    authors {\n      nameFirst,\n      nameLast\n    }\n  }\n}\n```\n\nResponse:\n\n```\n{\n  \"data\": {\n    \"books\": [\n      {\n        \"title\": \"A Memory of Light\",\n        \"year\": 2013,\n        \"authors\": [\n          {\n            \"nameFirst\": \"Robert\",\n            \"nameLast\": \"Jordan\"\n          },\n          {\n            \"nameFirst\": \"Brandon\",\n            \"nameLast\": \"Sanderson\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n#### Get number of books by cover-artist\n\nQuery:\n\n```\nquery getCountBooksByCoverArtist{\n  stats {\n    countBooksByCoverArtist {\n      coverArtist,\n      countBooks\n    }\n  }\n}\n```\n\nResponse:\n\n```\n{\n  \"data\": {\n    \"stats\": {\n      \"countBooksByCoverArtist\": [\n        {\n          \"coverArtist\": null,\n          \"countBooks\": 1\n        },\n        {\n          \"coverArtist\": \"Darrell K. Sweet\",\n          \"countBooks\": 12\n        },\n        {\n          \"coverArtist\": \"Michael Whelan\",\n          \"countBooks\": 1\n        }\n      ]\n    }\n  }\n}\n```\n\n#### Add new author\n\nQuery:\n\n```\nmutation createAuthor{\n  createAuthor(author: {\n    nameFirst: \"First Name\",\n    nameLast: \"Last Name\"\n  }) {\n    author {\n      authorId\n      nameFirst\n      nameLast\n    }\n  }\n}\n```\n\nResponse:\n\n```\n{\n  \"data\": {\n    \"createAuthor\": {\n      \"author\": {\n        \"authorId\": \"3\",\n        \"nameFirst\": \"First Name\",\n        \"nameLast\": \"Last Name\"\n      }\n    }\n  }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomada141%2Fdemo-graphql-sqlalchemy-falcon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsomada141%2Fdemo-graphql-sqlalchemy-falcon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomada141%2Fdemo-graphql-sqlalchemy-falcon/lists"}