Open ekampf opened 5 years ago
pls use a syntax that looks like python, so that various tools that highlight/parse python don't break:
Foo = gql(''' .... ''')
some parsers/tools/highlighters might freak out over gql'''
pattern.
(In practice, both my primary tools - Notepad++ and Pygmentize don't have any issues with gql'''
).
@aviv-ebates I thought about this too and checked the IDEs I have:
The con of using a function syntax is that it can be confused by the reader as a real function call. Having an "invalid" python code there immediately strikes the eye as out of the ordinary - something special happens here that you need to understand.
As far as IDEs go, I looked at how pyxl
sole it and they simply provide an extension to IDEs:
https://github.com/christoffer/pycharm-pyxl
https://github.com/yyjhao/sublime-pyxl
Out syntax is way simpler so it shouldn't be a problem to do the same.
As for non IDE tools - like pylint, mypy etc - when they do open(filename)
codec should run automatically and they should get the generated code and never see the gql
syntax.
(This poses other problems - how do we make this generated code not break the users build on pylint\flake8\whatever he's using)
WDYT?
Another problem with the gql( ... )
syntax is that if your code has import gql
said IDEs will definitely not like it...
I would like for all tools - esp lints - to run on source code (i.e., what the user actually types) rather then generated code; mypy only works on the AST, but other tools (pylint) check for code formatting.
I don't understand the issue with import gql
- it's a real name, isn't it?
As far as the user being confused with gql()
looking like a function:
Also, making this section valid python would allow us to provide a good error message if the user somehow didn't load our custom encoder, rather than having the python loader error out.
If mypy sees the generated code, it might show up errors that don't make sense to the user; I'm sort-of guessing the generated code should end up being just GetFilm = from .generated_gql_stuff import GetFilm
, and all the rest goes in the new file.
@aviv-ebates isn't the whole point of strong typing the response objects is for these tools to be able to recognize them? For example:
GetFilm = gql'''
query GetFilm {
film(id: "1") { title, director }
}
'''
result = GetFilm.execute()
film = result.data.starship
I would like this code to throw some lint\mypy error that data
doesn't have a starship
property
Like we talked offline - for some things (like "exactly 1 space before =
") we want the tool to see the original code, and for others (static typing) to see the generated stuff (but we need to make sure the error messages make sense).
I'm a little surprised by open()
considering the encoding
directive, but the tool might not have the codec loaded, and it might not even be written in Python anyway.
Allow embedding GraphQL queries in Python code. For example:
Should render all the relevant Operation class and result dataclasses and set
GetFilm
to be the operation class: