Skip to content

Commit

Permalink
release initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
schickling committed May 12, 2016
1 parent 14f378d commit 971fdb3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
.DS_Store
*.egg-info
*.pyc
19 changes: 19 additions & 0 deletions example_run.py
@@ -0,0 +1,19 @@
#!/usr/bin/env python

from graphqlclient import GraphQLClient

def main():
client = GraphQLClient('http://graphql-swapi.parseapp.com/')

print(client.execute('''
{
allFilms {
films {
title
}
}
}
'''))

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions graphqlclient/__init__.py
@@ -0,0 +1 @@
from .client import *
20 changes: 18 additions & 2 deletions graphqlclient/client.py
@@ -1,4 +1,20 @@
import urllib2
import json

class GraphQLClient:
def __init__(self, endpoint):
self.endpoint = endpoint

def query():
return "test"
def execute(self, query, variables=None):
return self._send(query, variables)

def _send(self, query, variables):
data = {'query': query,
'variables': variables}
headers = {'Accept': 'application/json',
'Content-Type': 'application/json'}

req = urllib2.Request(self.endpoint, json.dumps(data), headers)
response = urllib2.urlopen(req)

return response.read()

0 comments on commit 971fdb3

Please sign in to comment.