|
| 1 | +Example Nameko+Graphene-SQLAlchemy Project |
| 2 | +================================ |
| 3 | + |
| 4 | +This example is for those who are not using frameworks like Flask | Django which already have a View wrapper implemented to handle graphql request and response accordingly |
| 5 | + |
| 6 | +If you need a [graphiql](https://github.com/graphql/graphiql) interface on your application, kindly look at [flask_sqlalchemy](../flask_sqlalchemy). |
| 7 | + |
| 8 | +Using [nameko](https://github.com/nameko/nameko) as an example, but you can get rid of `service.py` |
| 9 | + |
| 10 | +The project contains two models, one named `Department` and another |
| 11 | +named `Employee`. |
| 12 | + |
| 13 | +Getting started |
| 14 | +--------------- |
| 15 | + |
| 16 | +First you'll need to get the source of the project. Do this by cloning the |
| 17 | +whole Graphene repository: |
| 18 | + |
| 19 | +```bash |
| 20 | +# Get the example project code |
| 21 | +git clone https://github.com/graphql-python/graphene-sqlalchemy.git |
| 22 | +cd graphene-sqlalchemy/examples/nameko_sqlalchemy |
| 23 | +``` |
| 24 | + |
| 25 | +It is good idea (but not required) to create a virtual environment |
| 26 | +for this project. We'll do this using |
| 27 | +[virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/) |
| 28 | +to keep things simple, |
| 29 | +but you may also find something like |
| 30 | +[virtualenvwrapper](https://virtualenvwrapper.readthedocs.org/en/latest/) |
| 31 | +to be useful: |
| 32 | + |
| 33 | +```bash |
| 34 | +# Create a virtualenv in which we can install the dependencies |
| 35 | +virtualenv env |
| 36 | +source env/bin/activate |
| 37 | +``` |
| 38 | + |
| 39 | +Now we can install our dependencies: |
| 40 | + |
| 41 | +```bash |
| 42 | +pip install -r requirements.txt |
| 43 | +``` |
| 44 | + |
| 45 | +Now the following command will setup the database, and start the server: |
| 46 | + |
| 47 | +```bash |
| 48 | +./run.sh |
| 49 | + |
| 50 | +``` |
| 51 | + |
| 52 | +Now head on over to postman and send POST request to: |
| 53 | +[http://127.0.0.1:5000/graphql](http://127.0.0.1:5000/graphql) |
| 54 | +and run some queries! |
0 commit comments