graphene-sqlalchemy
graphene-sqlalchemy copied to clipboard
Model vs Node in naming in docs and tests
The documentation and example code use: Example and ExampleModel.
https://github.com/graphql-python/graphene-sqlalchemy/blob/08fcfc0b2548cd3519e4b19772acda4495089392/docs/tutorial.rst#schema
from models import db_session, Department as DepartmentModel, Employee as EmployeeModel
class Department(SQLAlchemyObjectType):
class Meta:
model = DepartmentModel
interfaces = (relay.Node, )
The unit tests use the opposite naming convention: ExampleNode and Example.
https://github.com/graphql-python/graphene-sqlalchemy/blob/08fcfc0b2548cd3519e4b19772acda4495089392/graphene_sqlalchemy/tests/test_query.py#L10
from .models import Article, Base, Editor, Reporter
class ArticleNode(SQLAlchemyObjectType):
class Meta:
model = Article
interfaces = (Node, )
Which is "correct"?
both are correct, the only difference is the import statement.
from graphene import relay
from graphene.relay import Node
Both work, but only one is "correct." The question is which? There should be only one recommendation.
It depends, To me, the second one is better since it's simple to remember you need a Node instance, and in this case, you only have a relay.Node instance but maybe you want to implement a custom behavior and you create a new class Node so you only need to change the import statement, one of the pros you only import the class Node.
For others, the first is better since Namespaces are one honking great idea, so when you read your code again you can see what kind of Node instance is, then it helps to omit to go to the import section since it's more readable, the con is you are importing the whole module but you only use one class of that package and this approach is more acceptable for standard libraries than custom.
So not only one is "correct", both are, think about what is better for you. and use that style.
If you want to clarify what is your style import statements section from pep8 can help you.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.