Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
# 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
def __populate_meta_fields(cls):
field = Field(non_null('String'), '__typename')
field._set_container(cls.__schema__, cls, '__typename__')
cls.__meta_fields__ = {
'__typename__': field,
}
def __populate_fields_from_selection_list(self, sl, json_data):
for sel in sl:
field = sel.__field__
ftype = self.__get_type_for_selection(sel, json_data)
if sel.__alias__ is not None:
alias = sel.__alias__
field = Field(ftype, alias, field.args)
field._set_container(self.__schema__, self, alias)
self.__populate_field_data(field, ftype, sel, json_data)
casts = sl.__casts__
if casts:
tname = json_data.get('__typename')
csl = casts.get(tname)
if csl:
self.__populate_fields_from_selection_list(csl, json_data)
: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
:func:`BaseItem._to_graphql_name()`
:type graphql_name: str
:param args: The field parameters as a :class:`ArgDict` or
compatible type (dict, or iterable of key-value pairs). The
value may be a mapped Python type (ie: ``str``), explicit
type (ie: ``String``), type name (ie: ``"String"``, to allow
cross references) or :class:`Arg` instances.
:type args: :class:`ArgDict`
'''
super(Field, self).__init__(typ, graphql_name)
self.args = ArgDict(args)