How to use the sgqlc.types.__init__.BaseType.__ensure__ function in sgqlc

To help you get started, we’ve selected a few sgqlc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github profusion / sgqlc / sgqlc / types / __init__.py View on Github external
def __contains__(cls, name_or_type):
        if isinstance(name_or_type, str):
            name_or_type = cls.__schema__[name_or_type]
        else:
            name_or_type = BaseType.__ensure__(name_or_type)
        return name_or_type in cls.__types__
github profusion / sgqlc / sgqlc / types / __init__.py View on Github external
>>> obj = TypeWithNonNullFields(json_data)
       >>> obj # repr()
       TypeWithNonNullFields(a_int=1, a_float=2.1)
       >>> for field_name in obj:
       ...     print(field_name, repr(obj[field_name]))
       ...
       a_int 1
       a_float 2.1

    '''
    if isinstance(t, str):
        return Lazy(t, t + '!', non_null)
    elif isinstance(t, Lazy):
        return Lazy(t.target_name, t.target_name + '!', non_null, t)

    t = BaseType.__ensure__(t)
    name = t.__name__ + '!'
    try:
        return t.__schema__.__cache__[name]
    except KeyError:
        pass

    wrapper = _create_non_null_wrapper(name, t)
    t.__schema__.__cache__[name] = wrapper
    return wrapper
github profusion / sgqlc / sgqlc / types / __init__.py View on Github external
def __create_own_fields(cls):
        # call the parent __dir__(), we don't want our overridden version
        # that reports fields we're just deleting
        members = super(ContainerTypeMeta, cls).__dir__()
        for name in members:
            if name.startswith('_'):
                continue

            field = getattr(cls, name)
            if not isinstance(field, Field):
                if not isinstance(field, Lazy):
                    try:
                        field = BaseType.__ensure__(field)
                    except TypeError:
                        continue

                field = Field(field)

            field._set_container(cls.__schema__, cls, name)
            cls.__fields[name] = field
            delattr(cls, name)  # let fallback to cls.__fields using getitem
github profusion / sgqlc / sgqlc / types / __init__.py View on Github external
a(values: [Int] = [1, 2]): String
      b(values: [Int]): String
    }

    >>> print(json.dumps(list_of(int).__to_json_value__([1, 2])))
    [1, 2]
    >>> print(json.dumps(list_of(int).__to_json_value__(None)))
    null

    '''
    if isinstance(t, str):
        return Lazy(t, '[' + t + ']', list_of)
    elif isinstance(t, Lazy):
        return Lazy(t.target_name, '[' + t.target_name + ']', list_of, t)

    t = BaseType.__ensure__(t)
    name = '[' + t.__name__ + ']'
    try:
        return t.__schema__.__cache__[name]
    except KeyError:
        pass

    wrapper = _create_list_of_wrapper(name, t)
    t.__schema__.__cache__[name] = wrapper
    return wrapper
github profusion / sgqlc / sgqlc / types / __init__.py View on Github external
type is not declared yet, then use the string name to query
          in the schema.
        :type typ: :class:`Scalar`, :class:`Type` or str

        :param graphql_name: the name to use in JSON object, usually ``aName``.
          If ``None`` or empty, will be created from python, converting
          ``a_name`` to ``aName`` using
          ``Arg._to_graphql_name()``
        :type graphql_name: str
        '''
        if isinstance(typ, str):
            self._type = Lazy(typ, typ, lambda x: x)
        elif isinstance(typ, Lazy):
            self._type = typ
        else:
            self._type = BaseType.__ensure__(typ)
        self.graphql_name = graphql_name
        self.name = None
        self.schema = None
        self.container = None