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

Added handling for TransportQueryError #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/plugins/action/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def has_project(client: GqlClient, project):

try:
return res["projectByName"] is not None
except KeyError:
except (KeyError, TypeError):
return False


Expand Down
10 changes: 7 additions & 3 deletions api/plugins/module_utils/gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ansible.module_utils.errors import AnsibleValidationError
from gql.transport.requests import RequestsHTTPTransport
from gql.transport.exceptions import TransportQueryError
from gql import Client, gql
from gql.dsl import DSLExecutable, DSLField, DSLSchema, DSLType, dsl_gql
from graphql import print_ast
Expand Down Expand Up @@ -64,9 +65,12 @@ def execute_query(self, query: str, variables: Optional[Dict[str, Any]]={}) -> D
query_ast = gql(query)
self.vvvv(f"GraphQL built query: \n{print_ast(query_ast)}")
self.vvvv(f"GraphQL query variables: \n{variables}")
res = self.client.execute(query_ast, variable_values=variables)
self.vvvv(f"GraphQL query result: {res}")
return res
try:
res = self.client.execute(query_ast, variable_values=variables)
self.vvvv(f"GraphQL query result: {res}")
return res
except TransportQueryError as e:
return e

def build_dynamic_query(self, query: str, mainType: str, args: Optional[Dict[str, Any]] = {}, fields: List[str] = [], subFieldsMap: Optional[Dict[str, List[str]]] = {}) -> DSLField:
"""
Expand Down
Loading