Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve README to include Getting Started section #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
__pycache__
*.lock
*.pyc
.idea
build
db.sqlite
node_modules
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# An introduction to Graphene and Relay

This is the supporting material for a tutorial on Graphene and Relay.
This is the supporting material for a tutorial on Graphene and Relay. For the
slides, check out this [speaker deck](https://speakerdeck.com/mjtamlyn/an-introduction-to-graphene-and-relay)

## Data model

Expand All @@ -23,3 +24,36 @@ The `relay` directory contains a Relay-compliant, Django database model backed
implementation of the data model.

The `application` directory contains a full Relay application.

## Getting started

To run this application locally, use the following steps:

- **Clone this repository and pip install requirements**

- **Migrate and populate your new village**
From the root directory of the project:

```
./manage.py migrate
./manage.py create_village
```

N.B. This tutorial uses a basic sqlite database. You can change `settings.py`
to use a different [dj_database_url](https://github.com/kennethreitz/dj-database-url)
config instead.

- **Start Making Queries**

```
./manage.py runserver
```

Go to `http://127.0.0.1:8000/plain/graphql` or
`http://127.0.0.1:8000/relay/graphql` to interact with the API using GraphiQL

- **Optional Step: Build JavaScript package**
```
npm install
npm run build
```
Empty file added relay/management/__init__.py
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions relay/management/commands/create_village.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.core.management.base import BaseCommand

from relay.population import create_village


class Command(BaseCommand):

help = "Populates the database with some initial entries"

def handle(self, *args, **options):
create_village()
self.stdout.write("Village population created!")
12 changes: 12 additions & 0 deletions relay/management/commands/delete_village.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.core.management.base import BaseCommand

from relay.population import delete_village


class Command(BaseCommand):

help = "Deletes all Streets, Houses, Persons from the database"

def handle(self, *args, **options):
delete_village()
self.stdout.write("Village population deleted!")
2 changes: 1 addition & 1 deletion relay/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create_village():
Person.objects.create(name='Owain', family='Thomas', residence=ysgol_4)


def destroy_village():
def delete_village():
Person.objects.all().delete()
House.objects.all().delete()
Street.objects.all().delete()
4 changes: 2 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Django
graphene --pre
graphene-django --pre
graphene
graphene-django
django-graphiql
django-webpack-loader
psycopg2
Expand Down
9 changes: 4 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ dj-database-url==0.4.1
dj-static==0.0.6
django-graphiql==0.4.4
django-webpack-loader==0.3.3
Django==1.10.1 # via django-graphiql, graphene-django, graphql-django-view
graphene-django==1.0.dev20160917000001
graphene==1.0.dev20160918041239
graphql-core==1.0.dev20160909040033 # via graphene, graphql-django-view, graphql-relay
graphql-django-view==1.4 # via graphene-django
Django==1.10.1 # via django-graphiql, graphene-django
graphene-django==1.0
graphene==1.0.1
graphql-core==1.0 # via graphene, graphql-relay
graphql-relay==0.4.4 # via graphene
gunicorn==19.6.0
iso8601==0.1.11 # via graphene-django
Expand Down
2 changes: 1 addition & 1 deletion village/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {'default': dj_database_url.config(default='postgres://localhost/village')}
DATABASES = {'default': dj_database_url.config(default='sqlite:///db.sqlite')}


# Password validation
Expand Down