-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL support now totally matches Hiku's functionality
- Loading branch information
1 parent
5d75c9c
commit b91f905
Showing
3 changed files
with
104 additions
and
29 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
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
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,16 +1,61 @@ | ||
from hiku.query import Node, Field | ||
import pytest | ||
|
||
from hiku.query import Node, Field, Link | ||
from hiku.readers.graphql import read | ||
|
||
from .base import TestCase, reqs_eq_patcher | ||
from .base import reqs_eq_patcher | ||
|
||
|
||
def check_read(source, query): | ||
parsed_query = read(source) | ||
with reqs_eq_patcher(): | ||
assert parsed_query == query | ||
|
||
|
||
def test_field(): | ||
check_read( | ||
'{ vaward }', | ||
Node([Field('vaward')]), | ||
) | ||
|
||
|
||
def test_field_args(): | ||
check_read( | ||
'{ ozone(auer: "spence") }', | ||
Node([Field('ozone', options={'auer': 'spence'})]), | ||
) | ||
|
||
|
||
def test_field_alias(): | ||
with pytest.raises(NotImplementedError) as err: | ||
read('{ glamors: foule }') | ||
err.match('Field aliases are not supported') | ||
|
||
|
||
def test_complex_field(): | ||
check_read( | ||
'{ saale { slighty } }', | ||
Node([Link('saale', Node([Field('slighty')]))]), | ||
) | ||
|
||
|
||
def test_complex_field_args(): | ||
check_read( | ||
'{ saale(lammie: "nursy") { slighty } }', | ||
Node([Link('saale', Node([Field('slighty')]), | ||
options={'lammie': 'nursy'})]), | ||
) | ||
|
||
|
||
def test_multiple_operations(): | ||
with pytest.raises(NotImplementedError) as err: | ||
read('{ gummed } { calce } { aaron }') | ||
err.match('Only single operation per document is supported, ' | ||
'3 operations was provided') | ||
|
||
class TestReadGraphQL(TestCase): | ||
|
||
def test(self): | ||
with reqs_eq_patcher(): | ||
self.assertEqual( | ||
read(""" | ||
{ hello } | ||
"""), | ||
Node([Field('hello')]), | ||
) | ||
def test_mutation_operation(): | ||
with pytest.raises(NotImplementedError) as err: | ||
read('mutation { doSomething(kokam: "screens") }') | ||
err.match('Only "query" operations are supported, "mutation" operation ' | ||
'was provided') |