Robert_LY Robert_LY - 3 years ago 127
Python Question

Graphene-Django Filenaming Conventions

I'm rebuilding a former Django REST API project as a GraphQL one. I now have queries & mutations working properly.

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.

In some it was suggested that the GraphQL queries should be placed in

schema.py
whereas the mutations should be placed in
mutation.py
.

What I'm thinking makes more sense is to instead have these two files hold their respective code:
- queries.py
- mutations.py

I'm relatively new to Django & Python though so want to be sure that I'm not violating any conventions.

Interested in your thoughts!

Robert

Answer Source

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.

However, since schema is general-defined term you may rename it to queries.

This is my project structure:

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?!)

So the schema.py (__init__) could be renamed to queries.py if you like. There is no much big difference between these two words.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download