def generate_update_mutation(self) -> None: self.update = MagqlField( self.magql_name + "Payload", { "id": MagqlArgument(MagqlNonNull("ID")), "input": MagqlArgument(MagqlNonNull(self.magql_name + "Input")), }, self.update_resolver, )
def generate_create_mutation(self) -> None: # TODO: Move backend auth functions into manager collection self.create = MagqlField( self.magql_name + "Payload", {"input": MagqlArgument(MagqlNonNull(self.magql_name + "InputRequired"))}, self.create_resolver, )
def generate_check_delete(self) -> None: check_delete_manager = MagqlManager("checkDelete") self.magql_names = [] for _table_name, manager in self.manager_map.items(): if manager: self.magql_names.append(manager.magql_name) for _table_name, manager in self.manager_map.items(): if isinstance(manager, MagqlTableManager) and manager: self.magql_name_to_table[manager.magql_name] = manager.table check_delete_manager.magql_types["SQLAlchemyTableUnion"] = MagqlUnionType( "SQLAlchemyTableUnion", self.magql_names, SQLAlchemyTableUnionResolver(self.magql_name_to_table), ) check_delete_manager.query.fields["checkDelete"] = MagqlField( MagqlList("SQLAlchemyTableUnion"), { "tableName": MagqlArgument("String"), "id": MagqlArgument(MagqlNonNull("ID")), }, CheckDeleteResolver(list(self.magql_name_to_table.values())), ) self.manager_map["checkDelete"] = check_delete_manager
def generate_many_query(self) -> None: self.many = MagqlField( self.magql_name + "ListPayload", { "filter": MagqlArgument(self.magql_name + "Filter"), "sort": MagqlArgument( MagqlList(MagqlNonNull(self.magql_name + "Sort")) ), "page": MagqlArgument("Page"), }, self.many_resolver, )
"to_convert", [ MagqlObjectType("Test", MagqlField(MagqlList(MagqlString))), MagqlObjectType("TestEmptyObject", {}), MagqlObjectType( "TestNestedObjects", { "EnumField": MagqlField( MagqlEnumType("TestEnum", { "RED": 0, "GREEN": 1, "BLUE": 2 })), "InputField": MagqlInputField(MagqlNonNull(MagqlInt)), "List": MagqlList(MagqlString), "InputObjectType": MagqlInputObjectType( "TestInputObject", MagqlNonNull( MagqlUnionType( "TestUnion", [MagqlString, MagqlID], print("test"), )), ), "ArgumentType": MagqlArgument(MagqlBoolean), "Float":
def add_rels(self, managers: t.Optional[t.List[MagqlManager]] = None) -> None: # TODO managers shouldn't be None, no checks for it. try: table_mapper = get_mapper(self.table) except ValueError: logging.getLogger(__name__).warning( f"No mapper for table {self.table.name!r}." ) return None for rel_name, rel in table_mapper.relationships.items(): rel_table = rel.target if rel_table.name in t.cast(t.List[MagqlManager], managers): rel_manager = t.cast(t.List[MagqlManager], managers)[rel_table.name] if rel_manager is None: continue else: rel_manager = None direction = rel.direction.name required = is_rel_required(rel) field_name = js_camelize(rel_name) # use magql name of rel manager if it exists else use default name target_name = ( rel_manager.magql_name if rel_manager else camelize(rel.target.name) ) base_field = target_name input_field_types = { str: "String", int: "Int", bool: "Boolean", float: "Float", } try: field_type = input_field_types[ rel_table.primary_key.columns.id.type.python_type ] except KeyError: raise KeyError( "The value set as the primary key for the relationship is not valid" ) input_field: t.Union[str, MagqlList] = field_type input_required_field: t.Union[str, MagqlList, MagqlNonNull] = field_type if "TOMANY" in direction: base_field = MagqlList(base_field) input_required_field = MagqlList(input_required_field) input_field = MagqlList(input_field) elif required: input_required_field = MagqlNonNull(input_required_field) if ( field_name not in self.magql_types[self.magql_name + "InputRequired"].fields ): self.magql_types[self.magql_name + "InputRequired"].fields[ field_name ] = MagqlInputField(input_required_field) if field_name not in self.magql_types[self.magql_name + "Input"].fields: self.magql_types[self.magql_name + "Input"].fields[ field_name ] = MagqlInputField(input_field) if field_name not in self.magql_types[self.magql_name].fields: self.magql_types[self.magql_name].fields[field_name] = MagqlField( base_field, None, Resolver() ) if field_name not in self.magql_types[self.magql_name + "Filter"].fields: self.magql_types[self.magql_name + "Filter"].fields[ field_name ] = MagqlInputField(RelFilter) self.magql_types[self.magql_name + "Payload"] = MagqlNonNull( MagqlObjectType( self.magql_name + "Payload", { "errors": MagqlField(MagqlList("String")), "result": MagqlField(self.magql_name, None, ResultResolver()), }, ) ) self.magql_types[self.magql_name + "ListPayload"] = MagqlNonNull( MagqlObjectType( self.magql_name + "ListPayload", { "errors": MagqlField(MagqlList("String")), "result": MagqlField( MagqlList(self.magql_name), None, ResultResolver() ), "count": MagqlField("Int", None, CountResolver()), }, ) ) return None
def generate_single_query(self) -> None: self.single = MagqlField( self.magql_name + "Payload", {"id": MagqlArgument(MagqlNonNull("ID"))}, self.single_resolver, )
def generate_delete_mutation(self) -> None: self.delete = MagqlField( self.magql_name + "Payload", {"id": MagqlArgument(MagqlNonNull("ID"))}, self.delete_resolver, )