dataall icon indicating copy to clipboard operation
dataall copied to clipboard

Enhancements: Refactor cache_instances under GQL module for better Debugging

Open anilsoni7 opened this issue 11 months ago • 3 comments

TLDR: Improper repr of classes present under backend/dataall/base/api/gql

repr of the classes present under backend/dataall/base/api/gql points to the cache_instance function present under backend/dataall/base/api/gql/_cache.py. due to this one cannot navigate to the proper function or class while navigating through the stack frames.

image

Solution

context: cache_instance is a decorator which wraps the class to add instance caching mechanism.

Creating new class named CacheInstances which implements the new dunder method provided by python for instance creation. CacheInstances is inherited by the classes such as ObjectType, QueryField, MutationField, Enum, Union, InputType.

` class CacheInstances: class_instances = {}

  def __new__(cls, name, scope='default', *args, **kwargs):
      obj = super().__new__(cls)
      if scope not in cls.class_instances:
          cls.class_instances[scope] = {}
      cls.class_instances[scope][name] = obj
      return obj

  @classmethod
  def get_instance(cls, name, scope='default'):
      try:
          return cls.class_instances[scope].get(name, None)
      except KeyError as e:
          print(f'scope: {scope} not found in class instances')
          raise e

`

`class GraphqlEnum(CacheInstances):

def __init__(self, name, values = None):
    self.name = name
    self.values = values

def gql(self, with_directives=True):
    n = '\n'
    # return f"enum {self.name}{{{n}{n.join(self.values)}{n}}}"
    return f'enum {self.name}{{{n}{n.join([v.name for v in self.values])}{n}}}'

`

P.S. Don't attach files. Please, prefer add code snippets directly in the message body.

anilsoni7 avatar Mar 15 '24 10:03 anilsoni7

Hi @anilsoni7, I have noticed that issue too and thanks for reporting it.

We are currently exploring (see #958) a migration from ApiGateway to AppSync and in that case all of the custom gql logic will be removed (aka all the code under gql/ and the definition of the types). So maybe the best approach here is to wait a bit for a decision on the AppSync migration and act a bit later.

petrkalos avatar Mar 21 '24 13:03 petrkalos

@petrkalos should we revisit this issue as candidate for 2.7?

dlpzx avatar Jul 12 '24 07:07 dlpzx

@dlpzx yes I think so

petrkalos avatar Jul 12 '24 11:07 petrkalos