Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14f378d
commit 971fdb3
Showing
4 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
*.egg-info | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .client import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |