def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of # SQLAlchemyInterface (excluding SQLAlchemyInterface class itself). if not is_base_type(bases, SQLAlchemyInterfaceMeta): return type.__new__(cls, name, bases, attrs) options = Options( attrs.pop('Meta', None), name=name, description=attrs.pop('__doc__', None), model=None, local_fields=None, only_fields=(), exclude_fields=(), # id='id', registry=None ) if not options.registry: options.registry = get_global_registry() assert isinstance(options.registry, Registry), ( 'The attribute registry in {}.Meta needs to be an' ' instance of Registry, received "{}".' ).format(name, options.registry) assert is_mapped(options.model), ( 'You need to pass a valid SQLAlchemy Model in ' '{}.Meta, received "{}".' ).format(name, options.model) cls = type.__new__(cls, name, bases, dict(attrs, _meta=options)) options.base_fields = () options.base_fields = get_base_fields(bases, _as=Field) if not options.local_fields: options.local_fields = yank_fields_from_attrs(attrs, _as=Field) # options.registry.register(cls) options.fields = merge( options.base_fields, options.local_fields ) options.sqlalchemy_fields = yank_fields_from_attrs( construct_fields(options), _as=Field, ) options.fields = merge( options.sqlalchemy_fields, options.base_fields, options.local_fields ) return cls
def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of SQLAlchemyInterface # (excluding SQLAlchemyInterface class itself). if not is_base_type(bases, SQLAlchemyInterfaceMeta): return type.__new__(cls, name, bases, attrs) options = Options( attrs.pop('Meta', None), name=name, description=attrs.pop('__doc__', None), model=None, local_fields=None, only_fields=(), exclude_fields=(), # id='id', registry=None) if not options.registry: options.registry = get_global_registry() assert isinstance( options.registry, Registry), ('The attribute registry in {}.Meta needs to be an' ' instance of Registry, received "{}".').format( name, options.registry) assert is_mapped( options.model), ('You need to pass a valid SQLAlchemy Model in ' '{}.Meta, received "{}".').format( name, options.model) cls = type.__new__(cls, name, bases, dict(attrs, _meta=options)) options.base_fields = () options.base_fields = get_base_fields(bases, _as=Field) if not options.local_fields: options.local_fields = yank_fields_from_attrs(attrs, _as=Field) # options.registry.register(cls) options.fields = merge(options.base_fields, options.local_fields) options.sqlalchemy_fields = yank_fields_from_attrs( construct_fields(options), _as=Field, ) options.fields = merge(options.sqlalchemy_fields, options.base_fields, options.local_fields) return cls
def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of # DjangoObjectType if not is_base_type(bases, DjangoObjectTypeMeta): return type.__new__(cls, name, bases, attrs) defaults = dict( name=name, description=attrs.pop('__doc__', None), model=None, local_fields=None, only_fields=(), exclude_fields=(), interfaces=(), registry=None ) if DJANGO_FILTER_INSTALLED: # In case Django filter is available, then # we allow more attributes in Meta defaults.update( filter_fields=(), filter_order_by=(), ) options = Options( attrs.pop('Meta', None), **defaults ) if not options.registry: options.registry = get_global_registry() assert isinstance(options.registry, Registry), ( 'The attribute registry in {}.Meta needs to be an instance of ' 'Registry, received "{}".' ).format(name, options.registry) assert is_valid_django_model(options.model), ( 'You need to pass a valid Django Model in {}.Meta, received "{}".' ).format(name, options.model) cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options)) options.registry.register(cls) options.django_fields = yank_fields_from_attrs( construct_fields(options), _as=Field, ) options.fields = merge( options.interface_fields, options.django_fields, options.base_fields, options.local_fields ) return cls
def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of Model # (excluding Model class itself). if not is_base_type(bases, SQLAlchemyObjectTypeMeta): return type.__new__(cls, name, bases, attrs) meta = attrs.pop('Meta', None) local_fields = OrderedDict( {k: v for k, v in attrs.items() if _is_graphql(v)}) tbl_doc = attrs.pop('__doc__', getattr(meta.model, '__doc__', None)) options = Options(meta, name=name, description=tbl_doc if not tbl_doc else (tbl_doc if isinstance(tbl_doc, unicode) else tbl_doc.decode('utf8')), model=None, local_fields=local_fields, exclude_fields=set(), interfaces=(), registry=None) if not options.registry: options.registry = get_global_registry() assert isinstance( options.registry, Registry), ('The attribute registry in {}.Meta needs to be an' ' instance of Registry, received "{}".').format( name, options.registry) assert is_mapped( options.model), ('You need to pass a valid SQLAlchemy Model in ' '{}.Meta, received "{}".').format( name, options.model) cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options)) options.registry.register(cls) options.sqlalchemy_fields = yank_fields_from_attrs( construct_fields(options), _as=graphene.Field, ) options.fields = merge(options.interface_fields, options.sqlalchemy_fields, options.base_fields, options.local_fields) return cls
def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of Model # (excluding Model class itself). if not is_base_type(bases, SQLAlchemyObjectTypeMeta): return type.__new__(cls, name, bases, attrs) meta = attrs.pop('Meta', None) local_fields = OrderedDict({k:v for k,v in attrs.items() if _is_graphql(v)}) options = Options( meta, name=name, description=attrs.pop('__doc__', getattr(meta.model, '__doc__', None)), model=None, local_fields=local_fields, exclude_fields=set(), interfaces=(), registry=None ) if not options.registry: options.registry = get_global_registry() assert isinstance(options.registry, Registry), ( 'The attribute registry in {}.Meta needs to be an' ' instance of Registry, received "{}".' ).format(name, options.registry) assert is_mapped(options.model), ( 'You need to pass a valid SQLAlchemy Model in ' '{}.Meta, received "{}".' ).format(name, options.model) cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options)) options.registry.register(cls) options.sqlalchemy_fields = yank_fields_from_attrs( construct_fields(options), _as = graphene.Field, ) options.fields = merge( options.interface_fields, options.sqlalchemy_fields, options.base_fields, options.local_fields ) return cls
def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of Model # (excluding Model class itself). if not is_base_type(bases, PynamoObjectTypeMeta): return type.__new__(cls, name, bases, attrs) options = Options( attrs.pop('Meta', None), name=name, description=attrs.pop('__doc__', None), model=None, local_fields=None, only_fields=(), exclude_fields=(), id='id', interfaces=(), registry=None ) if not options.registry: options.registry = get_global_registry() assert isinstance(options.registry, Registry), ( 'The attribute registry in {}.Meta needs to be an' ' instance of Registry, received "{}".' ).format(name, options.registry) assert (inspect.isclass(options.model) and issubclass(options.model, Model)), ( 'You need to pass a valid PynamoDB Model in ' '{}.Meta, received "{}".' ).format(name, options.model) cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options)) options.registry.register(cls) options.pynamo_fields = yank_fields_from_attrs( construct_fields(options), _as=Field, ) options.fields = merge( options.interface_fields, options.pynamo_fields, options.base_fields, options.local_fields ) return cls
def __new__(cls, name, bases, attrs): # We'll get called also for non-user classes like DjangoModelInput. Only # kick in when called for a sub-class. if not is_base_type(bases, DjangoModelInputMeta): return type.__new__(cls, name, bases, attrs) # Pop Meta info. Must be removed from class, otherwise graphene will # complain. meta = attrs.pop('Meta') if not hasattr(meta, 'exclude_fields'): setattr(meta, 'exclude_fields', ()) if not hasattr(meta, 'only_fields'): setattr(meta, 'only_fields', ()) fields = convert_fields(model=meta.model, only_fields=meta.only_fields, exclude_fields=meta.exclude_fields) attrs = merge(attrs, fields) return type.__new__(cls, name, bases, attrs)