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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f3d94d6b6e6a828340d3aed2c209d34d06312ed77991ea64d70ca470e5654da |
|
MD5 | 25d3d6066d62f04fd34e9e64327481e3 |
|
BLAKE2b-256 | 0aae9a463ef4dd94f8dbba44e85344f67403fd6b6ae5f8bb650da32c6387f5ed |
Close
Hashes for sqlalchemy_graphql_schemagen-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48c0add0e5e2dfdbc7ded99eb3d65be3eea6fe2d6f8f94ef2d75657f9b5b62c0 |
|
MD5 | fe9fd1fe5f063be45cf6ea1b19011945 |
|
BLAKE2b-256 | 611461a16d8198c539435f0fe0571536e9007a16868a347c072e391c45b45f1e |