石墨烯-Django文件命名约定 [英] Graphene-Django Filenaming Conventions
问题描述
我正在将以前的Django REST API项目重建为GraphQL项目.我现在有疑问&突变工作正常.
I'm rebuilding a former Django REST API project as a GraphQL one. I now have queries & mutations working properly.
我的大部分学习都来自于研究现有的Graphene-Django&石墨烯-Python代码示例.它们之间似乎有很多不一致之处.
Most of my learning came from looking at existing Graphene-Django & Graphene-Python code samples. There seem to be a lot of inconsistencies amongst them.
有人建议将GraphQL查询放置在 schema.py
中,而将突变放置在 mutation.py
中.
In some it was suggested that the GraphQL queries should be placed in schema.py
whereas the mutations should be placed in mutation.py
.
我认为更有意义的是让这两个文件保存各自的代码:-querys.py-突变.py
What I'm thinking makes more sense is to instead have these two files hold their respective code: - queries.py - mutations.py
我是Django&的新手.不过,Python是要确保我没有违反任何约定.
I'm relatively new to Django & Python though so want to be sure that I'm not violating any conventions.
对您的想法感兴趣!
罗伯特
推荐答案
There aren't any conventions yet, since GraphQL is a fairly new alternative method to REST. Thus, "conventions" are created at the moment we speak.
但是,由于 schema
是通用定义的术语,因此您可以将其重命名为 queries
.
However, since schema
is general-defined term you may rename it to queries
.
这是我的项目结构:
django_proj/
manage.py
requirements.txt
my_app/
__init__.py
migrations/
admin.py
schema/
__init__.py
schema.py # holds the class Query. The GraphQL endpoints, if you like
types.py # holds the DjangoObjectType classes
inputs.py # holds the graphene.InputObjectType classes (for defining input to a query or mutation)
mutations.py # holds the mutations (what else?!)
因此,如果愿意,可以将 schema.py
( __ init __
)重命名为 queries.py
.这两个词之间没有太大区别.
So the schema.py
(__init__
) could be renamed to queries.py
if you like. There is no much big difference between these two words.
这篇关于石墨烯-Django文件命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!