Generate a full (query+mutation) GraphQL schema from your SQLAlchemy Declarative Model Base.
Project description
sqlalchemy-graphql-schemagen
Generate a full (query/mutation) GraphQL Schema from your defined classes in a declarative_meta() Model.
Example
#!/usr/bin/env python
from flask import Flask
from flask_graphql import GraphQLView
from sqlalchemy import create_engine
from medgraphqlapi import generate_custom_column_docstrings
from sqlalchemy_graphql_schemagen import SQLAlchemyGraphQLSchemaGenerator
from medgraphqlapi.database_schema import Base as sa_base_declarative
################################
# SQLAlchemy Stuff
################################
sa_connection_string = "mssql+pyodbc://XXXXXXXXXXXX"
# Create the Engine
sa_engine = create_engine(sa_connection_string)
# Generate more useful columns' docstrings (ex.: type length, collation, ...)
generate_custom_column_docstrings(sa_base_declarative)
################################
# Build a GraphQL Schema from the SQLAlchemy Schema, using sqlalchemy_graphql_schemagen!
################################
graphql_schema = SQLAlchemyGraphQLSchemaGenerator(
"ApiName",
sa_base_declarative,
sa_connection_string=sa_connection_string,
).get_graphene_schema()
################################
# Instantiate Flask App
################################
app = Flask(__name__)
# Plug GraphQLView
app.add_url_rule("/graphql",
view_func=GraphQLView.as_view("graphql",
schema=graphql_schema,
graphiql=True))
# That's it!
if __name__ == "__main__":
app.run(host="0.0.0.0")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for sqlalchemy-graphql-schemagen-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09972b300e570017110af9ba24053bc6b7368fa20c66a058230fe7e2b622894a |
|
MD5 | 6ac6de5c2f779ad7644d0ee81d8e6e1e |
|
BLAKE2b-256 | 82ea03969261323dc19647e2f692aca827f7da2f1a0bd3aabd4f13626b7ffbca |
Close
Hashes for sqlalchemy_graphql_schemagen-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0b6fccada66bd2bbfb36d2d2410812a7768556a3fdc5915b3c4d0d34d502bfc |
|
MD5 | 370a9bafade2c6357ee64fc6d68f07de |
|
BLAKE2b-256 | 450a6047040baf84692a4721f408e0d17ec490beeca984fc68f6a85364aa9b41 |