diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a710a5ff..f9da16d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,12 +7,11 @@ repos: - id: check-merge-conflict - id: check-yaml - id: debug-statements -# TDOO Enable in separate PR -# - id: end-of-file-fixer -# exclude: ^docs/.*$ -# - id: trailing-whitespace -# exclude: README.md -# - repo: git://github.com/PyCQA/flake8 -# rev: 88caf5ac484f5c09aedc02167c59c66ff0af0068 # 3.7.7 -# hooks: -# - id: flake8 + - id: end-of-file-fixer + exclude: ^docs/.*$ + - id: trailing-whitespace + exclude: README.md +- repo: git://github.com/PyCQA/flake8 + rev: 88caf5ac484f5c09aedc02167c59c66ff0af0068 # 3.7.7 + hooks: + - id: flake8 diff --git a/docs/examples.rst b/docs/examples.rst index 45fa3c55..283a0f5e 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -37,14 +37,14 @@ Search all Models with Union class Query(graphene.ObjectType): node = relay.Node.Field() search = graphene.List(SearchResult, q=graphene.String()) # List field for search results - + # Normal Fields all_books = SQLAlchemyConnectionField(BookConnection) all_authors = SQLAlchemyConnectionField(AuthorConnection) def resolve_search(self, info, **args): q = args.get("q") # Search query - + # Get queries bookdata_query = BookData.get_query(info) author_query = Author.get_query(info) @@ -53,14 +53,14 @@ Search all Models with Union books = bookdata_query.filter((BookModel.title.contains(q)) | (BookModel.isbn.contains(q)) | (BookModel.authors.any(AuthorModel.name.contains(q)))).all() - + # Query Authors authors = author_query.filter(AuthorModel.name.contains(q)).all() return authors + books # Combine lists schema = graphene.Schema(query=Query, types=[Book, Author, SearchResult]) - + Example GraphQL query .. code:: diff --git a/docs/tips.rst b/docs/tips.rst index cb25bd48..1fd39107 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -31,7 +31,7 @@ If you don't specify any, the following error will be displayed: Sorting ------- -By default the SQLAlchemyConnectionField sorts the result elements over the primary key(s). +By default the SQLAlchemyConnectionField sorts the result elements over the primary key(s). The query has a `sort` argument which allows to sort over a different column(s) Given the model diff --git a/examples/nameko_sqlalchemy/README.md b/examples/nameko_sqlalchemy/README.md index f60ccb00..39cfe925 100644 --- a/examples/nameko_sqlalchemy/README.md +++ b/examples/nameko_sqlalchemy/README.md @@ -51,4 +51,4 @@ Now the following command will setup the database, and start the server: Now head on over to postman and send POST request to: [http://127.0.0.1:5000/graphql](http://127.0.0.1:5000/graphql) -and run some queries! \ No newline at end of file +and run some queries! diff --git a/examples/nameko_sqlalchemy/app.py b/examples/nameko_sqlalchemy/app.py index f7fe150a..18302ce6 100755 --- a/examples/nameko_sqlalchemy/app.py +++ b/examples/nameko_sqlalchemy/app.py @@ -19,7 +19,7 @@ def query(self, request): execution_results, format_error=default_format_error,is_batch=False, encode=json_encode) return result - + def parse_body(self,request): # We use mimetype here since we don't need the other # information provided by content_type @@ -33,4 +33,4 @@ def parse_body(self,request): elif content_type in ('application/x-www-form-urlencoded', 'multipart/form-data'): return request.form - return {} \ No newline at end of file + return {} diff --git a/examples/nameko_sqlalchemy/config.yml b/examples/nameko_sqlalchemy/config.yml index cdea553c..8ca6a45c 100644 --- a/examples/nameko_sqlalchemy/config.yml +++ b/examples/nameko_sqlalchemy/config.yml @@ -1 +1 @@ -WEB_SERVER_ADDRESS: '0.0.0.0:5000' \ No newline at end of file +WEB_SERVER_ADDRESS: '0.0.0.0:5000' diff --git a/examples/nameko_sqlalchemy/requirements.txt b/examples/nameko_sqlalchemy/requirements.txt index 1f7be7db..be037f73 100644 --- a/examples/nameko_sqlalchemy/requirements.txt +++ b/examples/nameko_sqlalchemy/requirements.txt @@ -1,4 +1,4 @@ graphene[sqlalchemy] SQLAlchemy==1.0.11 nameko -graphql-server-core \ No newline at end of file +graphql-server-core diff --git a/examples/nameko_sqlalchemy/run.sh b/examples/nameko_sqlalchemy/run.sh index d3953677..bfe17d9a 100755 --- a/examples/nameko_sqlalchemy/run.sh +++ b/examples/nameko_sqlalchemy/run.sh @@ -1,4 +1,4 @@ #!/bin/sh echo "Starting application service server" # Run Service -nameko run --config config.yml service \ No newline at end of file +nameko run --config config.yml service diff --git a/examples/nameko_sqlalchemy/service.py b/examples/nameko_sqlalchemy/service.py index 394764e4..d83ab861 100644 --- a/examples/nameko_sqlalchemy/service.py +++ b/examples/nameko_sqlalchemy/service.py @@ -1,11 +1,11 @@ #!/usr/bin/env python from nameko.web.handlers import http -from app import App +from app import App class DepartmentService: - name = 'department' + name = 'department' @http('POST', '/graphql') def query(self, request): - return App().query(request) \ No newline at end of file + return App().query(request) diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index c2ec3e49..c6c49bba 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -168,7 +168,7 @@ class Test(Base): ) graphene_type = convert_sqlalchemy_column(Test.column) - assert graphene_type.kwargs["required"] == False + assert not graphene_type.kwargs["required"] def test_should_scalar_list_convert_list(): @@ -343,4 +343,3 @@ def __init__(self, col1, col2): ) assert "Don't know how to convert the composite field" in str(excinfo.value) - diff --git a/graphene_sqlalchemy/tests/test_query.py b/graphene_sqlalchemy/tests/test_query.py index f1116d9d..8bb4891c 100644 --- a/graphene_sqlalchemy/tests/test_query.py +++ b/graphene_sqlalchemy/tests/test_query.py @@ -555,4 +555,3 @@ def makeNodes(nodeList): assert set(node["node"]["name"] for node in value["edges"]) == set( node["node"]["name"] for node in expectedNoSort[key]["edges"] ) - diff --git a/graphene_sqlalchemy/tests/test_reflected.py b/graphene_sqlalchemy/tests/test_reflected.py index c8a1a70f..46e10de9 100644 --- a/graphene_sqlalchemy/tests/test_reflected.py +++ b/graphene_sqlalchemy/tests/test_reflected.py @@ -18,4 +18,3 @@ def test_objecttype_registered(): assert issubclass(Reflected, ObjectType) assert Reflected._meta.model == ReflectedEditor assert list(Reflected._meta.fields.keys()) == ["editor_id", "name"] - diff --git a/graphene_sqlalchemy/tests/test_schema.py b/graphene_sqlalchemy/tests/test_schema.py index 909570a6..628da185 100644 --- a/graphene_sqlalchemy/tests/test_schema.py +++ b/graphene_sqlalchemy/tests/test_schema.py @@ -47,4 +47,3 @@ class Meta: model = Reporter only_fields = ("id", "email") assert list(Reporter2._meta.fields.keys()) == ["id", "email"] - diff --git a/graphene_sqlalchemy/tests/test_types.py b/graphene_sqlalchemy/tests/test_types.py index c11ec351..b6dce726 100644 --- a/graphene_sqlalchemy/tests/test_types.py +++ b/graphene_sqlalchemy/tests/test_types.py @@ -1,7 +1,7 @@ from collections import OrderedDict from graphene import Field, Int, Interface, ObjectType from graphene.relay import Node, is_node, Connection -import six +import six # noqa F401 from promise import Promise from ..registry import Registry @@ -176,7 +176,9 @@ class TestConnection(Connection): class Meta: node = ReporterWithCustomOptions - resolver = lambda *args, **kwargs: Promise.resolve([]) + def resolver(*args, **kwargs): + return Promise.resolve([]) + result = SQLAlchemyConnectionField.connection_resolver( resolver, TestConnection, ReporterWithCustomOptions, None, None ) diff --git a/graphene_sqlalchemy/types.py b/graphene_sqlalchemy/types.py index e8a05c8f..300af684 100644 --- a/graphene_sqlalchemy/types.py +++ b/graphene_sqlalchemy/types.py @@ -1,5 +1,6 @@ from collections import OrderedDict +import sqlalchemy from sqlalchemy.inspection import inspect as sqlalchemyinspect from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm.exc import NoResultFound @@ -80,9 +81,9 @@ def construct_fields(model, registry, only_fields, exclude_fields): class SQLAlchemyObjectTypeOptions(ObjectTypeOptions): - model = None # type: Model - registry = None # type: Registry - connection = None # type: Type[Connection] + model = None # type: sqlalchemy.Model + registry = None # type: sqlalchemy.Registry + connection = None # type: sqlalchemy.Type[sqlalchemy.Connection] id = None # type: str