Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reuse connection when using DSL? #138

Closed
Jeff17Robbins opened this issue Sep 8, 2020 · 5 comments
Closed

How to reuse connection when using DSL? #138

Jeff17Robbins opened this issue Sep 8, 2020 · 5 comments
Labels
type: feature A new feature

Comments

@Jeff17Robbins
Copy link

Each DSL operation calls self.client.execute which apparently creates a new connection each time. Passing a session to DSLSchema doesn't work and causes an infinite recursion.

Traceback (most recent call last):
  File "gql_test2.py", line 45, in <module>
    query = ds.Query.listCasess().select(ds.ModelCasesConnection.items.select(ds.Cases.id))
  File "C:\Program Files\Python38\lib\site-packages\gql\dsl.py", line 38, in __getattr__
    type_def = self.schema.get_type(name)
  File "C:\Program Files\Python38\lib\site-packages\gql\dsl.py", line 38, in __getattr__
    type_def = self.schema.get_type(name)
  File "C:\Program Files\Python38\lib\site-packages\gql\dsl.py", line 38, in __getattr__
    type_def = self.schema.get_type(name)
  [Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded

Is there some known good way to reuse the connection when using DSL? Is the session meant to work, and this is simply a bug?

@leszekhanusz
Copy link
Collaborator

leszekhanusz commented Sep 9, 2020

It is not possible to reuse the connection with the current DSL code.
The DSL code was made before all the 3.0 changes and is still quite experimental.
A refactor is probably needed so that it only returns a DocumentNode instead of needing to execute the query itself, this way we could execute the query how we want (in a session for example)

@leszekhanusz leszekhanusz added the type: feature A new feature label Sep 9, 2020
@Jeff17Robbins
Copy link
Author

That makes sense. For now, I'm doing this

    query = f'mutation {{ {str(_query)} }}' # where _query is built using the DSL
    res = session.execute(gql(query))

If I understood you properly, in the future, it might be possible to do this

    res = session.execute(_query)

and avoid the trip back to text and parsing?

@leszekhanusz
Copy link
Collaborator

If I understood you properly, in the future, it might be possible to do this

    res = session.execute(_query)

and avoid the trip back to text and parsing?

Yes, exactly, something like this.

@leszekhanusz
Copy link
Collaborator

leszekhanusz commented Nov 8, 2020

I refactored the DSL code and the proposed way is a little bit different.
Example:

query = dsl_gql(DSLQuery(ds.Query.hero.select(ds.Character.name)))                                                            
result = session.execute(query)

leszekhanusz added a commit that referenced this issue Nov 21, 2020
Refactoring of the DSL code.

The DSLSchema only needs a schema, a Client is no more needed.
New dsl_gql function to convert the DSL operations into a Document
This allows DSL queries to be executed in a session instead of a client (Solves #138)
Added typing annotations
Added code documentation and sphinx docs (Solves #82)
Supports Subscriptions
Fix nested input arguments
Allow to set the alias directly in the select method
Allow multiple operations in a document
Allow to set the operation name
@leszekhanusz
Copy link
Collaborator

Fixed in v3.0.0a5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

No branches or pull requests

2 participants