Skip to content

Commit

Permalink
Merge pull request #649 from populationgenomics/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
nevoodoo authored Jan 11, 2024
2 parents 3d2df80 + b28b6d0 commit 1a2f22a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 6.6.0
current_version = 6.6.2
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>[A-z0-9-]+)
Expand Down
6 changes: 3 additions & 3 deletions api/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ class GraphQLSequencingGroup:
technology: str
platform: str
meta: strawberry.scalars.JSON
external_ids: strawberry.scalars.JSON | None
external_ids: strawberry.scalars.JSON

internal_id: strawberry.Private[int]
sample_id: strawberry.Private[int]
Expand All @@ -498,7 +498,7 @@ def from_internal(internal: SequencingGroupInternal) -> 'GraphQLSequencingGroup'
technology=internal.technology,
platform=internal.platform,
meta=internal.meta,
external_ids=internal.external_ids,
external_ids=internal.external_ids or {},
# internal
internal_id=internal.id,
sample_id=internal.sample_id,
Expand Down Expand Up @@ -575,7 +575,7 @@ def from_internal(internal: AssayInternal) -> 'GraphQLAssay':
id=internal.id,
type=internal.type,
meta=internal.meta,
external_ids=internal.external_ids,
external_ids=internal.external_ids or {},
# internal
sample_id=internal.sample_id,
)
Expand Down
2 changes: 1 addition & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from api.settings import PROFILE_REQUESTS, SKIP_DATABASE_CONNECTION

# This tag is automatically updated by bump2version
_VERSION = '6.6.0'
_VERSION = '6.6.2'

logger = get_logger()

Expand Down
2 changes: 1 addition & 1 deletion deploy/python/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.6.0
6.6.2
61 changes: 45 additions & 16 deletions metamist/graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

from gql import Client, gql as gql_constructor
from gql.transport.aiohttp import AIOHTTPTransport
from gql.transport.aiohttp import log as aiohttp_logger
from gql.transport.requests import RequestsHTTPTransport
from gql.transport.requests import log as requests_logger

from cpg_utils.cloud import get_google_identity_token

Expand Down Expand Up @@ -54,13 +56,18 @@ def configure_sync_client(
if _sync_client and not force_recreate:
return _sync_client

token = auth_token or get_google_identity_token(
target_audience=metamist.configuration.sm_url
)
transport = RequestsHTTPTransport(
url=url or get_sm_url(),
headers={'Authorization': f'Bearer {token}'},
)
env = os.getenv('SM_ENVIRONMENT', 'PRODUCTION').lower()
if env == 'local':
transport = RequestsHTTPTransport(url=url or get_sm_url())
else:
token = auth_token or get_google_identity_token(
target_audience=metamist.configuration.sm_url
)
transport = RequestsHTTPTransport(
url=url or get_sm_url(),
headers={'Authorization': f'Bearer {token}'},
)

_sync_client = Client(
transport=transport, schema=schema, fetch_schema_from_transport=schema is None
)
Expand All @@ -78,13 +85,18 @@ async def configure_async_client(
if _async_client and not force_recreate:
return _async_client

token = auth_token or get_google_identity_token(
target_audience=metamist.configuration.sm_url
)
transport = AIOHTTPTransport(
url=url or get_sm_url(),
headers={'Authorization': f'Bearer {token}'},
)
env = os.getenv('SM_ENVIRONMENT', 'PRODUCTION').lower()
if env == 'local':
transport = AIOHTTPTransport(url=url or get_sm_url())
else:
token = auth_token or get_google_identity_token(
target_audience=metamist.configuration.sm_url
)
transport = AIOHTTPTransport(
url=url or get_sm_url(),
headers={'Authorization': f'Bearer {token}'},
)

_async_client = Client(
transport=transport, schema=schema, fetch_schema_from_transport=schema is None
)
Expand Down Expand Up @@ -126,31 +138,48 @@ def validate(doc: DocumentNode, client=None, use_local_schema=False):

# use older style typing to broaden supported Python versions
def query(
_query: str | DocumentNode, variables: Dict = None, client: Client = None
_query: str | DocumentNode, variables: Dict = None, client: Client = None, log_response: bool = False
) -> Dict[str, Any]:
"""Query the metamist GraphQL API"""
if variables is None:
variables = {}

# disable logging for gql
current_level = aiohttp_logger.level
if not log_response:
requests_logger.setLevel('WARNING')

response = (client or configure_sync_client()).execute_sync(
_query if isinstance(_query, DocumentNode) else gql(_query),
variable_values=variables,
)

if not log_response:
requests_logger.setLevel(current_level)
return response


async def query_async(
_query: str | DocumentNode, variables: Dict = None, client: Client = None
_query: str | DocumentNode, variables: Dict = None, client: Client = None, log_response: bool = False
) -> Dict[str, Any]:
"""Asynchronously query the Metamist GraphQL API"""
if variables is None:
variables = {}

# disable logging for gql
current_level = aiohttp_logger.level
if log_response:
aiohttp_logger.setLevel('WARNING')

if not client:
client = await configure_async_client()

response = await client.execute_async(
_query if isinstance(_query, DocumentNode) else gql(_query),
variable_values=variables,
)

if log_response:
aiohttp_logger.setLevel(current_level)

return response
2 changes: 1 addition & 1 deletion models/models/assay.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AssayInternal(SMBase):
sample_id: int
meta: dict[str, Any] | None
type: str
external_ids: dict[str, str] | None = None
external_ids: dict[str, str] | None = {}

def __repr__(self):
return ', '.join(f'{k}={v}' for k, v in vars(self).items())
Expand Down
2 changes: 1 addition & 1 deletion models/models/sequencing_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SequencingGroupInternal(SMBase):
platform: str | None = None
meta: dict[str, str] | None = None
sample_id: int | None = None
external_ids: dict[str, str] | None = None
external_ids: dict[str, str] | None = {}
archived: bool | None = None

project: int | None = None
Expand Down
11 changes: 7 additions & 4 deletions openapi-templates/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ JSON_SCHEMA_VALIDATION_KEYWORDS = {

sm_url = getenv('SM_URL')
if not sm_url:
env = getenv('SM_ENVIRONMENT', 'PRODUCTION')
if 'local' in env.lower():
env = getenv('SM_ENVIRONMENT', 'PRODUCTION').lower()
if 'local' in env:
sm_url = "http://localhost:8000"
elif 'dev' in env.lower():
elif 'dev' in env:
sm_url = 'https://sample-metadata-api-dev-mnrpw3mdza-ts.a.run.app'
else:
sm_url = 'https://sample-metadata-api-mnrpw3mdza-ts.a.run.app'
Expand Down Expand Up @@ -192,7 +192,7 @@ conf = {{{packageName}}}.Configuration(
):
"""Constructor
"""
env = getenv('SM_ENVIRONMENT', 'PRODUCTION')
self.env = getenv('SM_ENVIRONMENT', 'PRODUCTION').lower()
self._base_path = host or sm_url

"""Default Base url
Expand Down Expand Up @@ -491,6 +491,9 @@ conf = {{{packageName}}}.Configuration(

:return: The Auth Settings information dict.
"""
if self.env == 'local':
return {}

auth = {
'HTTPBearer': {
'type': 'bearer',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
setup(
name=PKG,
# This tag is automatically updated by bump2version
version='6.6.0',
version='6.6.2',
description='Python API for interacting with the Sample API system',
long_description=readme,
long_description_content_type='text/markdown',
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metamist",
"version": "6.6.0",
"version": "6.6.2",
"private": true,
"dependencies": {
"@apollo/client": "^3.7.3",
Expand Down

0 comments on commit 1a2f22a

Please sign in to comment.