question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

flask_sqlalchemy example : different types with the same name in the schema: EmployeeConnection, EmployeeConnection.

See original GitHub issue

Hi,

I followed the instruction to use the flask_sqlalchemy example with a Python 2.7 version, when I run the app.py script, I’ve got the following error :

(py27) λ python app.py                                                                                                                      
Traceback (most recent call last):                                                                                                          
  File "app.py", line 7, in <module>                                                                                                        
    from schema import schema                                                                                                               
  File "D:\Thomas\Dev\graphene-sqlalchemy\examples\flask_sqlalchemy\schema.py", line 60, in <module>                                        
    schema = graphene.Schema(query=Query, types=[Department, Employee, Role])         

....
                            
  File "D:\Programmes\Anaconda2\envs\py27\lib\site-packages\graphene\types\typemap.py", line 99, in graphene_reducer                        
    ).format(_type.graphene_type, type)                                                                                                     
AssertionError: Found different types with the same name in the schema: EmployeeConnection, EmployeeConnection.  

What am I doing wrong ?

Thank you

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:29 (3 by maintainers)

github_iconTop GitHub Comments

26reactions
ivanvoronacommented, Aug 20, 2018

@suxin1 thank you for your code but i was lazy reading it 😃 anyway, the fix is as simple as replacing “EmployeeConnection” with “EmployeeConnections”, following post helped me identify root cause: https://github.com/graphql-python/graphene-django/issues/185#issuecomment-388469296 hope will help someone else, all the best.

18reactions
RonaldZhaocommented, Dec 23, 2018

I solved this problem by changing a few names in schema.py, here is my code:

import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from models import Department, Employee


class DepartmentNode(SQLAlchemyObjectType):
    class Meta:
        model = Department
        interfaces = (relay.Node,)


class DepartmentConnection(relay.Connection):
    class Meta:
        node = DepartmentNode


class EmployeeNode(SQLAlchemyObjectType):
    class Meta:
        model = Employee
        interfaces = (relay.Node,)


class EmployeeConnection(relay.Connection):
    class Meta:
        node = EmployeeNode


class Query(graphene.ObjectType):
    node = relay.Node.Field()
    all_employees = SQLAlchemyConnectionField(EmployeeConnection)
    all_departments = SQLAlchemyConnectionField(DepartmentConnection, sort=None)


schema = graphene.Schema(query=Query)

But why? I do not know, just lucky.

Read more comments on GitHub >

github_iconTop Results From Across the Web

graphql-python - Bountysource
flask_sqlalchemy example : different types with the same name in the schema: EmployeeConnection, EmployeeConnection. $ 0. Created 4 years ago in graphql-python/ ...
Read more >
SQLAlchemy + Flask Tutorial - Graphene-Python
In this example, we provide the ability to list all employees via all_employees , and the ability to obtain a specific node via...
Read more >
Using same name of tables with different binds in Flask
Use separate declarative base classes for different databases with the same name, to prevent sharing of SQLAlchemy metadata.
Read more >
The Type Hierarchy - SQLAlchemy 1.4 Documentation
Database types are represented using Python classes, all of which ... have an explicit name in order to support schema-management concerns.
Read more >
Graphene Documentation - Read the Docs
1 SQLAlchemy + Flask Tutorial. 3. 1.1. SetuptheProject . ... Create flask_sqlalchemy/schema.py and type the following:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found