This example project demos integration between:
It is an adaption of this example.
See the LogicBank Wiki for an overview of the payment_allocation application.
GraphQL (as I understand it) moves API definition from the server team (company, or org in company) to the consumers, who clearly better understand their requirements. Clear specifications can reduce traffic, in either size and or number of messages. The focus is on efficient retrieval.
Logic Base can reduce update logic coding (a significant part of any database app) by 40X, by using spreadsheet-like rules plus Python for extensibility. The focus is on update agility.
Both are based on SQLAlchemy. This project explores using Graphene for retrieval, and Logic Base for mutation logic.
First you'll need to get the source of the project. Do this by cloning the whole Graphene-SQLAlchemy repository:
# Get the example project code
git clone https://github.com/valhuber/payment_allocation_graphene.gitIt is good idea (but not required) to create a virtual environment for this project. We'll do this using virtualenv to keep things simple, but you may also find something like virtualenvwrapper to be useful:
# Create a virtualenv in which we can install the dependencies
cd payment_allocation_graphene
virtualenv venv
source venv/bin/activateNow we can install our dependencies:
pip install -r requirements.txtcd payment_allocation/tests
python add_payment.pyNow the following command will setup the database, and start the server:
chmod +x app.py
./app.pyPatterning the code after this example,
gets fail with Request' object has no attribute 'get'.
Mentioned in this stack overflow, which links to this.
Also tried this (see app.py), but still fails.
But, the suggestion here
worked, using @yoursdearboy's lambda (thank you! See app.py):
app.add_url_rule(
'/graphql',
view_func=GraphQLView.as_view(
'graphql',
schema=schema,
graphiql=True,
get_context=lambda: {'session': db.session}
)
)
Open your browser to http://127.0.0.1:5000/graphql and paste in the request below:
{
allCustomers(sort: [ID_ASC]) {
edges {
node {
Id
Balance
}
}
}
}
Using your command line:
cd tests
python test_get.py
Or, open your browser to http://127.0.0.1:5000/graphql and paste in the request below:
{
allCustomers {
edges {
node {
Id
Balance
OrderList {
edges {
node {
CustomerId
AmountTotal
}
}
}
}
}
}
}
This fails: Schema is not configured for mutations.
Such configuration appears to be quite code intensive, but possibly create from model. There appears to be some promising work in this area.
mutation {
customerCreate
( input:
{
Id: "ADDED",
CompanyName: "Added, Inc",
Balance: 0,
CreditLimit: 0
}
)
{ customer {
id
}
}
}
