Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Apr 5, 2019
2 parents 67a621f + c9af40c commit 9dd34ca
Show file tree
Hide file tree
Showing 26 changed files with 81 additions and 61 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ repos:
rev: 88caf5ac484f5c09aedc02167c59c66ff0af0068 # 3.7.7
hooks:
- id: flake8
- repo: git://github.com/asottile/seed-isort-config
rev: v1.7.0
hooks:
- id: seed-isort-config
- repo: git://github.com/pre-commit/mirrors-isort
rev: v4.3.4
hooks:
- id: isort
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
# html_theme = 'alabaster'
# if on_rtd:
# html_theme = 'sphinx_rtd_theme'
import sphinx_graphene_theme
import sphinx_graphene_theme # isort:skip

html_theme = "sphinx_graphene_theme"

Expand Down
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Create ``flask_sqlalchemy/schema.py`` and type the following:
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from models import db_session, Department as DepartmentModel, Employee as EmployeeModel
from .models import db_session, Department as DepartmentModel, Employee as EmployeeModel
class Department(SQLAlchemyObjectType):
Expand Down Expand Up @@ -146,8 +146,8 @@ installed makes this task quite easy.
from flask import Flask
from flask_graphql import GraphQLView
from models import db_session
from schema import schema, Department
from .models import db_session
from .schema import schema, Department
app = Flask(__name__)
app.debug = True
Expand Down Expand Up @@ -175,7 +175,7 @@ Creating some data
$ python
>>> from models import engine, db_session, Base, Department, Employee
>>> from .models import engine, db_session, Base, Department, Employee
>>> Base.metadata.create_all(bind=engine)
>>> # Fill the tables with some data
Expand Down
5 changes: 3 additions & 2 deletions examples/flask_sqlalchemy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from flask import Flask

from database import db_session, init_db
from flask_graphql import GraphQLView
from schema import schema

from .database import db_session, init_db
from .schema import schema

app = Flask(__name__)
app.debug = True
Expand Down
2 changes: 1 addition & 1 deletion examples/flask_sqlalchemy/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def init_db():
# import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()
from models import Department, Employee, Role
from .models import Department, Employee, Role
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)

Expand Down
2 changes: 1 addition & 1 deletion examples/flask_sqlalchemy/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func
from sqlalchemy.orm import backref, relationship

from database import Base
from .database import Base


class Department(Base):
Expand Down
10 changes: 6 additions & 4 deletions examples/flask_sqlalchemy/schema.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyConnectionField, SQLAlchemyObjectType, utils
from models import Department as DepartmentModel
from models import Employee as EmployeeModel
from models import Role as RoleModel
from graphene_sqlalchemy import (SQLAlchemyConnectionField,
SQLAlchemyObjectType, utils)

from .models import Department as DepartmentModel
from .models import Employee as EmployeeModel
from .models import Role as RoleModel


class Department(SQLAlchemyObjectType):
Expand Down
9 changes: 5 additions & 4 deletions examples/nameko_sqlalchemy/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from database import db_session, init_db
from schema import schema

from graphql_server import (HttpQueryError, default_format_error,
encode_execution_results, json_encode,load_json_body, run_http_query)
encode_execution_results, json_encode,
load_json_body, run_http_query)

from .database import db_session, init_db
from .schema import schema


class App():
Expand Down
2 changes: 1 addition & 1 deletion examples/nameko_sqlalchemy/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def init_db():
# import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()
from models import Department, Employee, Role
from .models import Department, Employee, Role
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)

Expand Down
2 changes: 1 addition & 1 deletion examples/nameko_sqlalchemy/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func
from sqlalchemy.orm import backref, relationship

from database import Base
from .database import Base


class Department(Base):
Expand Down
7 changes: 4 additions & 3 deletions examples/nameko_sqlalchemy/schema.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyConnectionField, SQLAlchemyObjectType
from models import Department as DepartmentModel
from models import Employee as EmployeeModel
from models import Role as RoleModel

from .models import Department as DepartmentModel
from .models import Employee as EmployeeModel
from .models import Role as RoleModel


class Department(SQLAlchemyObjectType):
Expand Down
3 changes: 2 additions & 1 deletion examples/nameko_sqlalchemy/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from nameko.web.handlers import http
from app import App

from .app import App


class DepartmentService:
Expand Down
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .fields import SQLAlchemyConnectionField
from .utils import get_query, get_session

__version__ = "2.1.0"
__version__ = "2.1.1"

__all__ = [
"__version__",
Expand Down
3 changes: 2 additions & 1 deletion graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm import interfaces

from graphene import ID, Boolean, Dynamic, Enum, Field, Float, Int, List, String
from graphene import (ID, Boolean, Dynamic, Enum, Field, Float, Int, List,
String)
from graphene.types.json import JSONString

from .fields import createConnectionField
Expand Down
3 changes: 2 additions & 1 deletion graphene_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import partial
from promise import is_thenable, Promise

from promise import Promise, is_thenable
from sqlalchemy.orm.query import Query

from graphene.relay import Connection, ConnectionField
Expand Down
8 changes: 3 additions & 5 deletions graphene_sqlalchemy/tests/test_connectionfactory.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from graphene_sqlalchemy.fields import (
SQLAlchemyConnectionField,
registerConnectionFieldFactory,
unregisterConnectionFieldFactory,
)
import graphene
from graphene_sqlalchemy.fields import (SQLAlchemyConnectionField,
registerConnectionFieldFactory,
unregisterConnectionFieldFactory)


def test_register():
Expand Down
12 changes: 5 additions & 7 deletions graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import enum

from py.test import raises
from sqlalchemy import Column, Table, case, types, select, func
from sqlalchemy import Column, Table, case, func, select, types
from sqlalchemy.dialects import postgresql
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import composite, column_property
from sqlalchemy.orm import column_property, composite
from sqlalchemy.sql.elements import Label
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType

Expand All @@ -13,11 +13,9 @@
from graphene.types.datetime import DateTime
from graphene.types.json import JSONString

from ..converter import (
convert_sqlalchemy_column,
convert_sqlalchemy_composite,
convert_sqlalchemy_relationship,
)
from ..converter import (convert_sqlalchemy_column,
convert_sqlalchemy_composite,
convert_sqlalchemy_relationship)
from ..fields import UnsortedSQLAlchemyConnectionField
from ..registry import Registry
from ..types import SQLAlchemyObjectType
Expand Down
6 changes: 4 additions & 2 deletions graphene_sqlalchemy/tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from graphene.relay import Connection
import pytest

from graphene.relay import Connection

from ..fields import SQLAlchemyConnectionField
from ..types import SQLAlchemyObjectType
from ..utils import sort_argument_for_model
from .models import Pet as PetModel, Editor
from .models import Editor
from .models import Pet as PetModel


class Pet(SQLAlchemyObjectType):
Expand Down
4 changes: 2 additions & 2 deletions graphene_sqlalchemy/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import graphene
from graphene.relay import Connection, Node

from ..registry import reset_global_registry
from ..fields import SQLAlchemyConnectionField
from ..registry import reset_global_registry
from ..types import SQLAlchemyObjectType
from ..utils import sort_argument_for_model, sort_enum_for_model
from .models import Article, Base, Editor, Pet, Reporter, Hairkind
from .models import Article, Base, Editor, Hairkind, Pet, Reporter

db = create_engine("sqlite:///test_sqlalchemy.sqlite3")

Expand Down
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from .models import Pet
from ..registry import Registry
from ..types import SQLAlchemyObjectType
from .models import Pet


def test_register_incorrect_objecttype():
Expand Down
8 changes: 5 additions & 3 deletions graphene_sqlalchemy/tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from collections import OrderedDict
from graphene import Field, Int, Interface, ObjectType
from graphene.relay import Node, is_node, Connection

import six # noqa F401
from promise import Promise

from graphene import Field, Int, Interface, ObjectType
from graphene.relay import Connection, Node, is_node

from ..fields import SQLAlchemyConnectionField
from ..registry import Registry
from ..types import SQLAlchemyObjectType, SQLAlchemyObjectTypeOptions
from .models import Article, Reporter
from ..fields import SQLAlchemyConnectionField

registry = Registry()

Expand Down
7 changes: 4 additions & 3 deletions graphene_sqlalchemy/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from graphene import Enum, List, ObjectType, Schema, String
import sqlalchemy as sa

from ..utils import get_session, sort_enum_for_model, sort_argument_for_model
from .models import Pet, Editor
from graphene import Enum, List, ObjectType, Schema, String

from ..utils import get_session, sort_argument_for_model, sort_enum_for_model
from .models import Editor, Pet


def test_get_session():
Expand Down
12 changes: 5 additions & 7 deletions graphene_sqlalchemy/types.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
from collections import OrderedDict

import sqlalchemy
from sqlalchemy.inspection import inspect as sqlalchemyinspect
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.inspection import inspect as sqlalchemyinspect
from sqlalchemy.orm.exc import NoResultFound

from graphene import Field # , annotate, ResolveInfo
from graphene.relay import Connection, Node
from graphene.types.objecttype import ObjectType, ObjectTypeOptions
from graphene.types.utils import yank_fields_from_attrs

from .converter import (
convert_sqlalchemy_column,
convert_sqlalchemy_composite,
convert_sqlalchemy_relationship,
convert_sqlalchemy_hybrid_method,
)
from .converter import (convert_sqlalchemy_column,
convert_sqlalchemy_composite,
convert_sqlalchemy_hybrid_method,
convert_sqlalchemy_relationship)
from .registry import Registry, get_global_registry
from .utils import get_query, is_mapped_class, is_mapped_instance

Expand Down
3 changes: 2 additions & 1 deletion graphene_sqlalchemy/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from graphene import Argument, Enum, List
from sqlalchemy.exc import ArgumentError
from sqlalchemy.inspection import inspect
from sqlalchemy.orm import class_mapper, object_mapper
from sqlalchemy.orm.exc import UnmappedClassError, UnmappedInstanceError

from graphene import Argument, Enum, List


def get_session(context):
return context.get("session")
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ test=pytest
exclude = setup.py,docs/*,examples/*,tests
max-line-length = 120

# TODO Add isort as a pre-commit hook
[isort]
known_first_party=graphene,graphene_sqlalchemy
known_graphene=graphene,graphql_relay,flask_graphql,graphql_server,sphinx_graphene_theme
known_first_party=graphene_sqlalchemy
known_third_party=flask,nameko,promise,py,pytest,setuptools,singledispatch,six,sqlalchemy,sqlalchemy_utils
sections=FUTURE,STDLIB,THIRDPARTY,GRAPHENE,FIRSTPARTY,LOCALFOLDER
no_lines_before=FIRSTPARTY

[bdist_wheel]
universal=1
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from setuptools import find_packages, setup
import sys
import ast
import re
import sys

from setuptools import find_packages, setup

_version_re = re.compile(r"__version__\s+=\s+(.*)")

Expand Down

0 comments on commit 9dd34ca

Please sign in to comment.