How to use the sgqlc.types.__init__.Lazy 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
>>> json_data = {'aInt': 1, 'aFloat': 2.1}
       >>> 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 __init__(self, typ, graphql_name=None):
        '''
        :param typ: the :class:`Scalar` or :class:`Type` derived
          class. If this would cause a cross reference and the other
          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
github profusion / sgqlc / sgqlc / types / __init__.py View on Github external
>>> TypeWithListInput
    type TypeWithListInput {
      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
or ``__repr__()``

       >>> json_data = {'aInt': 1, 'aFloat': 2.1}
       >>> 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
``None``, and they won't show in ``iter(obj)``, ``__str__()``
       or ``__repr__()``

       >>> json_data = {'aInt': 1, 'aFloat': 2.1}
       >>> 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
...     b = Field(str, args={'values': Arg(list_of(int))})
    ...
    >>> TypeWithListInput
    type TypeWithListInput {
      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