Skip to content

Commit 0434899

Browse files
committed
Isolated Graphene Django in a new package
0 parents  commit 0434899

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3891
-0
lines changed

.gitignore

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Created by https://www.gitignore.io
2+
3+
### Python ###
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
env/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*,cover
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
56+
# Sphinx documentation
57+
docs/_build/
58+
59+
# PyBuilder
60+
target/
61+
62+
63+
/tests/django.sqlite
64+
65+
/graphene/index.json
66+
/graphene/meta.json
67+
68+
/meta.json
69+
/index.json
70+
71+
/docs/playground/graphene-js/pypyjs-release-nojit/
72+
/docs/static/playground/lib
73+
74+
/docs/static/playground
75+
76+
# PyCharm
77+
.idea
78+
79+
# Databases
80+
*.sqlite3
81+
.vscode

.travis.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
language: python
2+
sudo: false
3+
python:
4+
- 2.7
5+
- 3.4
6+
- 3.5
7+
- pypy
8+
before_install:
9+
- |
10+
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
11+
export PYENV_ROOT="$HOME/.pyenv"
12+
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
13+
cd "$PYENV_ROOT" && git pull
14+
else
15+
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
16+
fi
17+
export PYPY_VERSION="4.0.1"
18+
"$PYENV_ROOT/bin/pyenv" install "pypy-$PYPY_VERSION"
19+
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
20+
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
21+
fi
22+
install:
23+
- |
24+
if [ "$TEST_TYPE" = build ]; then
25+
pip install pytest pytest-cov pytest-benchmark coveralls six pytest-django mock django-filter
26+
pip install -e .
27+
python setup.py develop
28+
elif [ "$TEST_TYPE" = lint ]; then
29+
pip install flake8
30+
fi
31+
script:
32+
- |
33+
if [ "$TEST_TYPE" = lint ]; then
34+
echo "Checking Python code lint."
35+
flake8 graphene_django
36+
exit
37+
elif [ "$TEST_TYPE" = build ]; then
38+
py.test --cov=graphene_django graphene_django examples
39+
fi
40+
after_success:
41+
- |
42+
if [ "$TEST_TYPE" = build ]; then
43+
coveralls
44+
fi
45+
matrix:
46+
fast_finish: true
47+
include:
48+
- python: '2.7'
49+
env: TEST_TYPE=lint

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
You are in the `next` unreleased version of Graphene-Django (`1.0.dev`).
2+
Please read [UPGRADE-v1.0.md](https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md) to learn how to upgrade.
3+
4+
---
5+
6+
# ![Graphene Logo](http://graphene-python.org/favicon.png) [Graphene-Django](http://graphene-python.org) [![Build Status](https://travis-ci.org/graphql-python/graphene-django.svg?branch=master)](https://travis-ci.org/graphql-python/graphene-django) [![PyPI version](https://badge.fury.io/py/graphene-django.svg)](https://badge.fury.io/py/graphene-django) [![Coverage Status](https://coveralls.io/repos/graphql-python/graphene-django/badge.svg?branch=master&service=github)](https://coveralls.io/github/graphql-python/graphene-django?branch=master)
7+
8+
9+
[Graphene](http://graphene-python.org) is a Python library for building GraphQL schemas/types fast and easily.
10+
11+
- **Easy to use:** Graphene helps you use GraphQL in Python without effort.
12+
- **Relay:** Graphene has builtin support for Relay
13+
- **Django:** Automatic *Django model* mapping to Graphene Types. Check a fully working [Django](http://github.com/graphql-python/swapi-graphene) implementation
14+
15+
Graphene also supports *SQLAlchemy*!
16+
17+
*What is supported in this Python version?* **Everything**: Interfaces, ObjectTypes, Scalars, Unions and Relay (Nodes, Connections), in addition to queries, mutations and subscriptions.
18+
19+
**NEW**!: [Try graphene online](http://graphene-python.org/playground/)
20+
21+
## Installation
22+
23+
For instaling graphene, just run this command in your shell
24+
25+
```bash
26+
pip install "graphene-django>=1.0.dev"
27+
```
28+
29+
## Examples
30+
31+
Here is one example for get you started:
32+
33+
```python
34+
from django.db import models
35+
from graphene_django import DjangoObjectType
36+
37+
class UserModel(models.Model):
38+
name = models.CharField(max_length=100)
39+
last_name = models.CharField(max_length=100)
40+
41+
class User(DjangoObjectType):
42+
class Meta:
43+
# This type will transform all the UserModel fields
44+
# into Graphene fields automatically
45+
model = UserModel
46+
47+
# An extra field in the User Type
48+
full_name = graphene.String()
49+
50+
def resolve_full_name(self, args, context, info):
51+
return "{} {}".format(self.name, self.last_name)
52+
```
53+
54+
If you want to learn even more, you can also check the following [examples](examples/):
55+
56+
* **Schema with Filtering**: [Cookbook example](examples/cookbook)
57+
* **Relay Schema**: [Starwars Relay example](examples/starwars)
58+
59+
60+
## Contributing
61+
62+
After cloning this repo, ensure dependencies are installed by running:
63+
64+
```sh
65+
python setup.py install
66+
```
67+
68+
After developing, the full test suite can be evaluated by running:
69+
70+
```sh
71+
python setup.py test # Use --pytest-args="-v -s" for verbose mode
72+
```

bin/autolinter

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Install the required scripts with
4+
# pip install autoflake autopep8 isort
5+
autoflake ./examples/ ./graphene_django/ -r --remove-unused-variables --remove-all-unused-imports --in-place
6+
autopep8 ./examples/ ./graphene_django/ -r --in-place --experimental --aggressive --max-line-length 120
7+
isort -rc ./examples/ ./graphene_django/

bin/convert_documentation

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
pandoc README.md --from markdown --to rst -s -o README.rst

django_test_settings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys, os
2+
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
3+
sys.path.insert(0, ROOT_PATH + '/examples/')
4+
5+
SECRET_KEY = 1
6+
7+
INSTALLED_APPS = [
8+
'graphene_django',
9+
'graphene_django.tests',
10+
'starwars',
11+
]
12+
13+
DATABASES = {
14+
'default': {
15+
'ENGINE': 'django.db.backends.sqlite3',
16+
'NAME': 'django_test.sqlite',
17+
}
18+
}

examples/cookbook/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Cookbook Example Django Project
2+
===============================
3+
4+
This example project demos integration between Graphene and Django.
5+
The project contains two apps, one named `ingredients` and another
6+
named `recepies`.
7+
8+
Getting started
9+
---------------
10+
11+
First you'll need to get the source of the project. Do this by cloning the
12+
whole Graphene repository:
13+
14+
```bash
15+
# Get the example project code
16+
git clone https://github.com/graphql-python/graphene.git
17+
cd graphene/examples/cookbook
18+
```
19+
20+
It is good idea (but not required) to create a virtual environment
21+
for this project. We'll do this using
22+
[virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/)
23+
to keep things simple,
24+
but you may also find something like
25+
[virtualenvwrapper](https://virtualenvwrapper.readthedocs.org/en/latest/)
26+
to be useful:
27+
28+
```bash
29+
# Create a virtualenv in which we can install the dependencies
30+
virtualenv env
31+
source env/bin/activate
32+
```
33+
34+
Now we can install our dependencies:
35+
36+
```bash
37+
pip install -r requirements.txt
38+
```
39+
40+
Now setup our database:
41+
42+
```bash
43+
# Setup the database
44+
./manage.py migrate
45+
46+
# Load some example data
47+
./manage.py loaddata ingredients
48+
49+
# Create an admin user (useful for logging into the admin UI
50+
# at http://127.0.0.1:8000/admin)
51+
./manage.py createsuperuser
52+
```
53+
54+
Now you should be ready to start the server:
55+
56+
```bash
57+
./manage.py runserver
58+
```
59+
60+
Now head on over to
61+
[http://127.0.0.1:8000/graphiql](http://127.0.0.1:8000/graphiql)
62+
and run some queries!
63+
(See the [Django quickstart guide](http://graphene-python.org/docs/quickstart-django/)
64+
for some example queries)

examples/cookbook/cookbook/__init__.py

Whitespace-only changes.

examples/cookbook/cookbook/ingredients/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
3+
from cookbook.ingredients.models import Category, Ingredient
4+
5+
admin.site.register(Ingredient)
6+
admin.site.register(Category)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.apps import AppConfig
2+
3+
4+
class IngredientsConfig(AppConfig):
5+
name = 'cookbook.ingredients'
6+
label = 'ingredients'
7+
verbose_name = 'Ingredients'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"model": "ingredients.category", "pk": 1, "fields": {"name": "Dairy"}}, {"model": "ingredients.category", "pk": 2, "fields": {"name": "Meat"}}, {"model": "ingredients.ingredient", "pk": 1, "fields": {"name": "Eggs", "notes": "Good old eggs", "category": 1}}, {"model": "ingredients.ingredient", "pk": 2, "fields": {"name": "Milk", "notes": "Comes from a cow", "category": 1}}, {"model": "ingredients.ingredient", "pk": 3, "fields": {"name": "Beef", "notes": "Much like milk, this comes from a cow", "category": 2}}, {"model": "ingredients.ingredient", "pk": 4, "fields": {"name": "Chicken", "notes": "Definitely doesn't come from a cow", "category": 2}}]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9 on 2015-12-04 18:15
3+
from __future__ import unicode_literals
4+
5+
import django.db.models.deletion
6+
from django.db import migrations, models
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='Category',
19+
fields=[
20+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21+
('name', models.CharField(max_length=100)),
22+
],
23+
),
24+
migrations.CreateModel(
25+
name='Ingredient',
26+
fields=[
27+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
28+
('name', models.CharField(max_length=100)),
29+
('notes', models.TextField()),
30+
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='ingredients.Category')),
31+
],
32+
),
33+
]

examples/cookbook/cookbook/ingredients/migrations/__init__.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from django.db import models
2+
3+
4+
class Category(models.Model):
5+
name = models.CharField(max_length=100)
6+
7+
def __str__(self):
8+
return self.name
9+
10+
11+
class Ingredient(models.Model):
12+
name = models.CharField(max_length=100)
13+
notes = models.TextField()
14+
category = models.ForeignKey(Category, related_name='ingredients')
15+
16+
def __str__(self):
17+
return self.name

0 commit comments

Comments
 (0)