Graphene-Django Filenaming Conventions

2024/10/11 19:14:38

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

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.pyrequirements.txtmy_app/__init__.pymigrations/admin.pyschema/__init__.pyschema.py     # holds the class Query. The GraphQL endpoints, if you liketypes.py      # holds the DjangoObjectType classesinputs.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.

https://en.xdnf.cn/q/118286.html

Related Q&A

Summing up CSV power plant data by technology and plant name

Ive got a question regarding the Form 860 data about US power plants.It is organized block-wise and not plant-wise. To become useful, the capacity numbers must be summed up.How may I get the total capa…

Send and receive signals from another class pyqt

I am needing a way to receive signals sent by a Class to another class. I have 2 classes: In my first class I have a function that emits a signal called asignal In my second class I call the first cla…

I can not add many values in one function

I have a gui applicationI put text into text box1, text box2,………… text box70 ,and then click on the pushButton, The function return_text () in the module_b.py be called. Now I can call one instance…

Close browser popup in Selenium Python

I am scraping a page using Selenium, Python. On opening the page one Popup appears. I want to close this popup anyway. I tried as below:url = https://shopping.rochebros.com/shop/categories/37browser = …

How can I replace certain string in a string in Python?

I am trying to write two procedures to replace matched strings in a string in python. And I have to write two procedures. def matched_case(old new): .........note: inputs are two strings, it returns a…

Python: `paste multiple (unknown) csvs together

What I am essentially looking for is the `paste command in bash, but in Python2. Suppose I have a csv file:a1,b1,c1,d1 a2,b2,c2,d2 a3,b3,c3,d3And another such:e1,f1 e2,f2 e3,f3I want to pull them toget…

Django Redirect after Login Error

Im new to Django and I know that to redirect after login I have to set the parameter page. But this only works when the login is successful. How can i do the same thing when some error occurs?? Ps: I…

Python: Pulling .png from a website, outputting to another

Hoping this question is not too vague, or asking for too much. Essentially I am analyzing large amounts of spectra, and wanting to create one large webpage that contains these spectra rather than looki…

Using peakutils - Detecting dull peaks

Im currently using peakutils to find peaks in some data. My data contains some "dull peaks", that is my peaks plateau somewhat. I cant set my code to find these peaks even after playing aroun…

nonlinear scaling image in figure axis matplotlib

enter image description hereI hope I have not over-looked as previously asked question. I dont think so. I have an image of a spectrum. I have several laser lines for calibration. Since the laser li…