Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Created by https://www.gitignore.io

.venv

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install:
- pip install -r ./dev_requirements.txt
- pip install -e .
script:
- flake8 gql
- py.test --cov=gql tests
- flake8 pygql
- py.test --cov=pygql tests
after_success:
- coveralls
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
# GQL
# PYGQL

This is a GraphQL client for Python.
Is a fork of GQL and a GraphQL client for Python.
Plays nicely with `graphene`, `graphql-core`, `graphql-js` and any other GraphQL implementation compatible with the spec.

GQL architecture is inspired by `React-Relay` and `Apollo-Client`.

[![travis][travis-image]][travis-url]
[![pypi][pypi-image]][pypi-url]
[![coveralls][coveralls-image]][coveralls-url]

[travis-image]: https://img.shields.io/travis/graphql-python/gql.svg?style=flat
[travis-url]: https://travis-ci.org/graphql-python/gql
[pypi-image]: https://img.shields.io/pypi/v/gql.svg?style=flat
[pypi-url]: https://pypi.python.org/pypi/gql
[coveralls-image]: https://coveralls.io/repos/graphql-python/gql/badge.svg?branch=master&service=github
[coveralls-url]: https://coveralls.io/github/graphql-python/gql?branch=master
[travis-image]: https://img.shields.io/travis/itolosa/pygql.svg?style=flat
[travis-url]: https://travis-ci.org/itolosa/pygql
[coveralls-image]: https://coveralls.io/repos/itolosa/pygql/badge.svg?branch=master&service=github
[coveralls-url]: https://coveralls.io/github/itolosa/pygql?branch=master

## Installation

$ pip install gql
$ pip install pygql


## Usage
Expand All @@ -27,7 +24,7 @@ The example below shows how you can execute queries against a local schema.


```python
from gql import gql, Client
from pygql import gql, Client

client = Client(schema=schema)
query = gql('''
Expand All @@ -41,4 +38,4 @@ client.execute(query)

## License

[MIT License](https://github.com/graphql-python/gql/blob/master/LICENSE)
[MIT License](https://github.com/itolosa/pygql/blob/master/LICENSE)
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ schema.

.. code:: python

from gql import gql, Client
from pygql import gql, Client

client = Client(schema=schema)
query = gql('''
Expand Down
6 changes: 3 additions & 3 deletions bin/autolinter
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

# Install the required scripts with
# pip install autoflake autopep8 isort
autoflake ./tests/ ./gql/ -r --remove-unused-variables --remove-all-unused-imports --in-place
autopep8 ./tests/ ./gql/ -r --in-place --experimental --aggressive --max-line-length 120
isort -rc ./tests/ ./gql/
autoflake ./tests/ ./pygql/ -r --remove-unused-variables --remove-all-unused-imports --in-place
autopep8 ./tests/ ./pygql/ -r --in-place --experimental --aggressive --max-line-length 120
isort -rc ./tests/ ./pygql/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion gql-checker/README.rst → pygql-checker/README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gql-checker
pygql-checker
===========

|Build Status|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"__email__", "__license__", "__copyright__",
]

__title__ = "gql-checker"
__title__ = "pygql-checker"
__summary__ = (
"Flake8 and pylama plugin that checks gql GraphQL calls."
"Flake8 and pylama plugin that checks pygql GraphQL calls."
)
__uri__ = "https://github.com/graphql-python/gql-checker"
__uri__ = "https://github.com/graphql-python/pygql-checker"

__version__ = "0.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import pycodestyle

from gql_checker.__about__ import (
from pygql_checker.__about__ import (
__author__, __copyright__, __email__, __license__, __summary__, __title__,
__uri__, __version__
)
from gql_checker.stdlib_list import STDLIB_NAMES
from pygql_checker.stdlib_list import STDLIB_NAMES
from graphql import Source, validate, parse, build_client_schema


Expand All @@ -16,8 +16,8 @@
"__email__", "__license__", "__copyright__",
]

GQL_SYNTAX_ERROR = 'GQL100'
GQL_VALIDATION_ERROR = 'GQL101'
PYGQL_SYNTAX_ERROR = 'PYGQL100'
PYGQL_VALIDATION_ERROR = 'PYGQL101'

class ImportVisitor(ast.NodeVisitor):
"""
Expand All @@ -30,7 +30,7 @@ def __init__(self, filename, options):
self.calls = []

def visit_Call(self, node): # noqa
if node.func.id == 'gql':
if node.func.id == 'pygql':
self.calls.append(node)

def node_query(self, node):
Expand Down Expand Up @@ -69,10 +69,10 @@ def load_file(self):
self.tree = ast.parse("".join(self.lines))

def get_schema(self):
gql_introspection_schema = self.options.get('gql_introspection_schema')
pygql_introspection_schema = self.options.get('pygql_introspection_schema')
if gql_introspection_schema:
try:
with open(gql_introspection_schema) as data_file:
with open(pygql_introspection_schema) as data_file:
introspection_schema = json.load(data_file)
return build_client_schema(introspection_schema)
except IOError as e:
Expand All @@ -87,7 +87,7 @@ def validation_errors(self, ast):
def error(self, node, code, message):
raise NotImplemented()

def check_gql(self):
def check_pygql(self):
if not self.tree or not self.lines:
self.load_file()

Expand All @@ -104,15 +104,15 @@ def check_gql(self):
continue

try:
source = Source(query, 'gql query')
source = Source(query, 'pygql query')
ast = parse(source)
except Exception as e:
message = str(e)
yield self.error(node, GQL_SYNTAX_ERROR, message)
yield self.error(node, PYGQL_SYNTAX_ERROR, message)
continue

validation_errors = self.validation_errors(ast)
if validation_errors:
for error in validation_errors:
message = str(error)
yield self.error(node, GQL_VALIDATION_ERROR, message)
yield self.error(node, PYGQL_VALIDATION_ERROR, message)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import absolute_import

import gql_checker
from gql_checker import ImportOrderChecker
import pygql_checker
from pygql_checker import ImportOrderChecker


class Linter(ImportOrderChecker):
name = "gql"
version = gql_checker.__version__
version = pygql_checker.__version__

def __init__(self, tree, filename):
super(Linter, self).__init__(filename, tree)
Expand All @@ -15,28 +15,28 @@ def __init__(self, tree, filename):
def add_options(cls, parser):
# List of application import names. They go last.
parser.add_option(
"--gql-introspection-schema",
"--pygql-introspection-schema",
metavar="FILE",
help="Import names to consider as application specific"
)
parser.add_option(
"--gql-typedef-schema",
"--pygql-typedef-schema",
default='',
action="store",
type="string",
help=("Style to follow. Available: "
"cryptography, google, smarkets, pep8")
)
parser.config_options.append("gql-introspection-schema")
parser.config_options.append("gql-typedef-schema")
parser.config_options.append("pygql-introspection-schema")
parser.config_options.append("pygql-typedef-schema")

@classmethod
def parse_options(cls, options):
optdict = {}

optdict = dict(
gql_introspection_schema=options.gql_introspection_schema,
gql_typedef_schema=options.gql_typedef_schema,
pygql_introspection_schema=options.pygql_introspection_schema,
pygql_typedef_schema=options.pygql_typedef_schema,
)

cls.options = optdict
Expand All @@ -46,5 +46,5 @@ def error(self, node, code, message):
return (lineno, col_offset, '{0} {1}'.format(code, message), Linter)

def run(self):
for error in self.check_gql():
for error in self.check_pygql():
yield error
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from pylama.lint import Linter as BaseLinter

import gql_checker
from gql_checker import ImportOrderChecker
import pygql_checker
from pygql_checker import ImportOrderChecker


class Linter(ImportOrderChecker, BaseLinter):
name = "gql"
version = gql_checker.__version__
name = "pygql"
version = pygql_checker.__version__

def __init__(self):
super(Linter, self).__init__(None, None)
Expand All @@ -32,5 +32,5 @@ def run(self, path, **meta):
{'schema': ''},
**meta)

for error in self.check_gql():
for error in self.check_pygql():
yield error
File renamed without changes.
8 changes: 4 additions & 4 deletions gql-checker/setup.py → pygql-checker/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
base_dir = os.path.dirname(__file__)

about = {}
with open(os.path.join(base_dir, "gql_checker", "__about__.py")) as f:
with open(os.path.join(base_dir, "pygql_checker", "__about__.py")) as f:
exec(f.read(), about)

with open(os.path.join(base_dir, "README.rst")) as f:
Expand Down Expand Up @@ -37,13 +37,13 @@
"pylama"
],

py_modules=['gql_checker'],
py_modules=['pygql_checker'],
entry_points={
'flake8.extension': [
'GQL = gql_checker.flake8_linter:Linter',
'pygql = pygql_checker.flake8_linter:Linter',
],
'pylama.linter': [
'gql_checker = gql_checker.pylama_linter:Linter'
'pygql_checker = pygql_checker.pylama_linter:Linter'
]
},

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gql import gql
from pygql import gql

gql('''
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from gql import gql
from pygql import gql

gql(''' wrong query ''') # noqa
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from gql import gql
from pygql import gql

gql(''' wrong query ''') # GQL100
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gql import gql
from pygql import gql


gql('''
Expand All @@ -25,13 +25,13 @@
favoriteSpaceship
}
}
''') # GQL101: Cannot query field "favoriteSpaceship" on type "Character".
''') # PYGQL101: Cannot query field "favoriteSpaceship" on type "Character".

gql('''
query HeroNoFieldsQuery {
hero
}
''') # GQL101: Field "hero" of type "Character" must have a sub selection.
''') # PYGQL101: Field "hero" of type "Character" must have a sub selection.


gql('''
Expand All @@ -42,7 +42,7 @@
}
}
}
''') # GQL101: Field "name" of type "String" must not have a sub selection.
''') # PYGQL101: Field "name" of type "String" must not have a sub selection.


gql('''
Expand All @@ -52,7 +52,7 @@
primaryFunction
}
}
''') # GQL101: Cannot query field "primaryFunction" on type "Character". However, this field exists on "Droid". Perhaps you meant to use an inline fragment?
''') # PYGQL101: Cannot query field "primaryFunction" on type "Character". However, this field exists on "Droid". Perhaps you meant to use an inline fragment?

gql('''
query DroidFieldInFragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pycodestyle
import pytest

from gql_checker.flake8_linter import Linter
from pygql_checker.flake8_linter import Linter

from tests.utils import extract_expected_errors

Expand Down Expand Up @@ -37,7 +37,7 @@ def load_test_cases():
)
def test_expected_error(tree, filename, expected_codes, expected_messages):
argv = [
"--gql-introspection-schema=./tests/introspection_schema.json"
"--pygql-introspection-schema=./tests/introspection_schema.json"
]

parser = pycodestyle.get_parser('', '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from gql_checker import pylama_linter
from pygql_checker import pylama_linter

from tests.utils import extract_expected_errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re


ERROR_RX = re.compile("# ((GQL[0-9]+ ?)+)(: (.*))?$")
ERROR_RX = re.compile("# ((PYGQL[0-9]+ ?)+)(: (.*))?$")


def extract_expected_errors(data):
Expand Down
Loading