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

[WIP] 1st PoC for typed gql queries design doc #2367

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions reconcile/service_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from reconcile.utils import gql
from reconcile import queries
from reconcile.utils.typed_gql_queries import query_saas_files


APPS_QUERY = """
Expand Down Expand Up @@ -63,6 +64,10 @@ def get_desired_dependency_names(app, dependency_map):
if github_urls:
required_dep_names.update(get_dependency_names(dependency_map, "github"))

for saas_file in query_saas_files():
# Do stuff on types :)
print(f"{saas_file.name} {saas_file.pipelines_provider.name}")

jenkins_configs = app.get("jenkinsConfigs")
if jenkins_configs:
instances = {jc["instance"]["name"] for jc in jenkins_configs}
Expand All @@ -89,6 +94,7 @@ def get_desired_dependency_names(app, dependency_map):
def run(dry_run):
settings = queries.get_app_interface_settings()
dependency_map = settings.get("dependencies")

if not dependency_map:
sys.exit()

Expand Down
47 changes: 47 additions & 0 deletions reconcile/utils/typed_gql_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
########################################
# Very basic and dirty PoC for querying code-generated types
########################################
from schema.qontract_schema import App_v1, SaasFile_v2
from schema.saas_file_query import Operations as saas_file_operations

# TODO: remove type ignore
from sgqlc.endpoint.http import HTTPEndpoint # type: ignore[import]

from reconcile.utils.config import get_config
from urllib.parse import urlparse


_endpoint = None


def _get_endpoint():
global _endpoint
if _endpoint:
return _endpoint

config = get_config()
server_url = urlparse(config["graphql"]["server"])
server = server_url.geturl()
token = config["graphql"].get("token")
headers = {}
if token:
headers["Authorization"] = token
_endpoint = HTTPEndpoint(server, headers)
return _endpoint


def query_saas_files() -> list[SaasFile_v2]:
# Query defined in saas_files_query.gql
op = saas_file_operations.query.list_saas_files_v2

# Query the data
data = _get_endpoint()(op)

# Bring data into desired format - there is probably a more elegant way to do this
apps: list[App_v1] = (op + data).apps
all_saas_files: list[SaasFile_v2] = []
for app in apps:
for app_saas_file in app.saas_files_v2:
all_saas_files.append(app_saas_file)

return all_saas_files
Empty file added schema/__init__.py
Empty file.
Loading