diff --git a/entgql/internal/todo/ent.graphql b/entgql/internal/todo/ent.graphql index 9b424aeff..3dcc74fdf 100644 --- a/entgql/internal/todo/ent.graphql +++ b/entgql/internal/todo/ent.graphql @@ -137,6 +137,7 @@ Input was generated by ent. """ input CreateUserInput { name: String + password: String groupIDs: [ID!] friendIDs: [ID!] } @@ -504,6 +505,8 @@ Input was generated by ent. """ input UpdateUserInput { name: String + clearPassword: Boolean + password: String addGroupIDs: [ID!] removeGroupIDs: [ID!] addFriendIDs: [ID!] diff --git a/entgql/internal/todo/ent/gql_mutation_input.go b/entgql/internal/todo/ent/gql_mutation_input.go index d5dede741..5a1837536 100644 --- a/entgql/internal/todo/ent/gql_mutation_input.go +++ b/entgql/internal/todo/ent/gql_mutation_input.go @@ -115,6 +115,7 @@ func (c *TodoUpdateOne) SetInput(i UpdateTodoInput) *TodoUpdateOne { // CreateUserInput represents a mutation input for creating users. type CreateUserInput struct { Name *string + Password *string GroupIDs []int FriendIDs []int } @@ -124,6 +125,9 @@ func (i *CreateUserInput) Mutate(m *UserMutation) { if v := i.Name; v != nil { m.SetName(*v) } + if v := i.Password; v != nil { + m.SetPassword(*v) + } if v := i.GroupIDs; len(v) > 0 { m.AddGroupIDs(v...) } @@ -141,6 +145,8 @@ func (c *UserCreate) SetInput(i CreateUserInput) *UserCreate { // UpdateUserInput represents a mutation input for updating users. type UpdateUserInput struct { Name *string + ClearPassword bool + Password *string AddGroupIDs []int RemoveGroupIDs []int AddFriendIDs []int @@ -152,6 +158,12 @@ func (i *UpdateUserInput) Mutate(m *UserMutation) { if v := i.Name; v != nil { m.SetName(*v) } + if i.ClearPassword { + m.ClearPassword() + } + if v := i.Password; v != nil { + m.SetPassword(*v) + } if v := i.AddGroupIDs; len(v) > 0 { m.AddGroupIDs(v...) } diff --git a/entgql/internal/todo/ent/gql_node.go b/entgql/internal/todo/ent/gql_node.go index c96d69f66..481c03e72 100644 --- a/entgql/internal/todo/ent/gql_node.go +++ b/entgql/internal/todo/ent/gql_node.go @@ -302,7 +302,7 @@ func (u *User) Node(ctx context.Context) (node *Node, err error) { node = &Node{ ID: u.ID, Type: "User", - Fields: make([]*Field, 1), + Fields: make([]*Field, 2), Edges: make([]*Edge, 3), } var buf []byte @@ -314,6 +314,14 @@ func (u *User) Node(ctx context.Context) (node *Node, err error) { Name: "name", Value: string(buf), } + if buf, err = json.Marshal(u.Password); err != nil { + return nil, err + } + node.Fields[1] = &Field{ + Type: "string", + Name: "password", + Value: string(buf), + } node.Edges[0] = &Edge{ Type: "Group", Name: "groups", diff --git a/entgql/internal/todo/ent/gql_where_input.go b/entgql/internal/todo/ent/gql_where_input.go index cc1b6d1fc..d352be146 100644 --- a/entgql/internal/todo/ent/gql_where_input.go +++ b/entgql/internal/todo/ent/gql_where_input.go @@ -1200,6 +1200,23 @@ type UserWhereInput struct { NameEqualFold *string `json:"nameEqualFold,omitempty"` NameContainsFold *string `json:"nameContainsFold,omitempty"` + // "password" field predicates. + Password *string `json:"password,omitempty"` + PasswordNEQ *string `json:"passwordNEQ,omitempty"` + PasswordIn []string `json:"passwordIn,omitempty"` + PasswordNotIn []string `json:"passwordNotIn,omitempty"` + PasswordGT *string `json:"passwordGT,omitempty"` + PasswordGTE *string `json:"passwordGTE,omitempty"` + PasswordLT *string `json:"passwordLT,omitempty"` + PasswordLTE *string `json:"passwordLTE,omitempty"` + PasswordContains *string `json:"passwordContains,omitempty"` + PasswordHasPrefix *string `json:"passwordHasPrefix,omitempty"` + PasswordHasSuffix *string `json:"passwordHasSuffix,omitempty"` + PasswordIsNil bool `json:"passwordIsNil,omitempty"` + PasswordNotNil bool `json:"passwordNotNil,omitempty"` + PasswordEqualFold *string `json:"passwordEqualFold,omitempty"` + PasswordContainsFold *string `json:"passwordContainsFold,omitempty"` + // "groups" edge predicates. HasGroups *bool `json:"hasGroups,omitempty"` HasGroupsWith []*GroupWhereInput `json:"hasGroupsWith,omitempty"` @@ -1347,6 +1364,51 @@ func (i *UserWhereInput) P() (predicate.User, error) { if i.NameContainsFold != nil { predicates = append(predicates, user.NameContainsFold(*i.NameContainsFold)) } + if i.Password != nil { + predicates = append(predicates, user.PasswordEQ(*i.Password)) + } + if i.PasswordNEQ != nil { + predicates = append(predicates, user.PasswordNEQ(*i.PasswordNEQ)) + } + if len(i.PasswordIn) > 0 { + predicates = append(predicates, user.PasswordIn(i.PasswordIn...)) + } + if len(i.PasswordNotIn) > 0 { + predicates = append(predicates, user.PasswordNotIn(i.PasswordNotIn...)) + } + if i.PasswordGT != nil { + predicates = append(predicates, user.PasswordGT(*i.PasswordGT)) + } + if i.PasswordGTE != nil { + predicates = append(predicates, user.PasswordGTE(*i.PasswordGTE)) + } + if i.PasswordLT != nil { + predicates = append(predicates, user.PasswordLT(*i.PasswordLT)) + } + if i.PasswordLTE != nil { + predicates = append(predicates, user.PasswordLTE(*i.PasswordLTE)) + } + if i.PasswordContains != nil { + predicates = append(predicates, user.PasswordContains(*i.PasswordContains)) + } + if i.PasswordHasPrefix != nil { + predicates = append(predicates, user.PasswordHasPrefix(*i.PasswordHasPrefix)) + } + if i.PasswordHasSuffix != nil { + predicates = append(predicates, user.PasswordHasSuffix(*i.PasswordHasSuffix)) + } + if i.PasswordIsNil { + predicates = append(predicates, user.PasswordIsNil()) + } + if i.PasswordNotNil { + predicates = append(predicates, user.PasswordNotNil()) + } + if i.PasswordEqualFold != nil { + predicates = append(predicates, user.PasswordEqualFold(*i.PasswordEqualFold)) + } + if i.PasswordContainsFold != nil { + predicates = append(predicates, user.PasswordContainsFold(*i.PasswordContainsFold)) + } if i.HasGroups != nil { p := user.HasGroups() diff --git a/entgql/internal/todo/ent/migrate/schema.go b/entgql/internal/todo/ent/migrate/schema.go index db91ce583..02307b8cb 100644 --- a/entgql/internal/todo/ent/migrate/schema.go +++ b/entgql/internal/todo/ent/migrate/schema.go @@ -125,6 +125,7 @@ var ( UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString, Default: "Anonymous"}, + {Name: "password", Type: field.TypeString, Nullable: true}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ diff --git a/entgql/internal/todo/ent/mutation.go b/entgql/internal/todo/ent/mutation.go index 575801e9d..224ee461f 100644 --- a/entgql/internal/todo/ent/mutation.go +++ b/entgql/internal/todo/ent/mutation.go @@ -2721,6 +2721,7 @@ type UserMutation struct { typ string id *int name *string + password *string clearedFields map[string]struct{} groups map[int]struct{} removedgroups map[int]struct{} @@ -2870,6 +2871,55 @@ func (m *UserMutation) ResetName() { m.name = nil } +// SetPassword sets the "password" field. +func (m *UserMutation) SetPassword(s string) { + m.password = &s +} + +// Password returns the value of the "password" field in the mutation. +func (m *UserMutation) Password() (r string, exists bool) { + v := m.password + if v == nil { + return + } + return *v, true +} + +// OldPassword returns the old "password" field's value of the User entity. +// If the User object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPassword is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPassword requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPassword: %w", err) + } + return oldValue.Password, nil +} + +// ClearPassword clears the value of the "password" field. +func (m *UserMutation) ClearPassword() { + m.password = nil + m.clearedFields[user.FieldPassword] = struct{}{} +} + +// PasswordCleared returns if the "password" field was cleared in this mutation. +func (m *UserMutation) PasswordCleared() bool { + _, ok := m.clearedFields[user.FieldPassword] + return ok +} + +// ResetPassword resets all changes to the "password" field. +func (m *UserMutation) ResetPassword() { + m.password = nil + delete(m.clearedFields, user.FieldPassword) +} + // AddGroupIDs adds the "groups" edge to the Group entity by ids. func (m *UserMutation) AddGroupIDs(ids ...int) { if m.groups == nil { @@ -3051,10 +3101,13 @@ func (m *UserMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 1) + fields := make([]string, 0, 2) if m.name != nil { fields = append(fields, user.FieldName) } + if m.password != nil { + fields = append(fields, user.FieldPassword) + } return fields } @@ -3065,6 +3118,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { switch name { case user.FieldName: return m.Name() + case user.FieldPassword: + return m.Password() } return nil, false } @@ -3076,6 +3131,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er switch name { case user.FieldName: return m.OldName(ctx) + case user.FieldPassword: + return m.OldPassword(ctx) } return nil, fmt.Errorf("unknown User field %s", name) } @@ -3092,6 +3149,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { } m.SetName(v) return nil + case user.FieldPassword: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPassword(v) + return nil } return fmt.Errorf("unknown User field %s", name) } @@ -3121,7 +3185,11 @@ func (m *UserMutation) AddField(name string, value ent.Value) error { // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserMutation) ClearedFields() []string { - return nil + var fields []string + if m.FieldCleared(user.FieldPassword) { + fields = append(fields, user.FieldPassword) + } + return fields } // FieldCleared returns a boolean indicating if a field with the given name was @@ -3134,6 +3202,11 @@ func (m *UserMutation) FieldCleared(name string) bool { // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *UserMutation) ClearField(name string) error { + switch name { + case user.FieldPassword: + m.ClearPassword() + return nil + } return fmt.Errorf("unknown User nullable field %s", name) } @@ -3144,6 +3217,9 @@ func (m *UserMutation) ResetField(name string) error { case user.FieldName: m.ResetName() return nil + case user.FieldPassword: + m.ResetPassword() + return nil } return fmt.Errorf("unknown User field %s", name) } diff --git a/entgql/internal/todo/ent/schema/user.go b/entgql/internal/todo/ent/schema/user.go index 3c87b8161..16fb4bd97 100644 --- a/entgql/internal/todo/ent/schema/user.go +++ b/entgql/internal/todo/ent/schema/user.go @@ -32,6 +32,9 @@ func (User) Fields() []ent.Field { return []ent.Field{ field.String("name"). Default("Anonymous"), + field.String("password"). + Sensitive(). + Optional(), } } diff --git a/entgql/internal/todo/ent/user.go b/entgql/internal/todo/ent/user.go index e424621cf..50a52900e 100644 --- a/entgql/internal/todo/ent/user.go +++ b/entgql/internal/todo/ent/user.go @@ -31,6 +31,8 @@ type User struct { ID int `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` + // Password holds the value of the "password" field. + Password string `json:"-"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the UserQuery when eager-loading is set. Edges UserEdges `json:"edges"` @@ -89,7 +91,7 @@ func (*User) scanValues(columns []string) ([]any, error) { switch columns[i] { case user.FieldID: values[i] = new(sql.NullInt64) - case user.FieldName: + case user.FieldName, user.FieldPassword: values[i] = new(sql.NullString) default: return nil, fmt.Errorf("unexpected column %q for type User", columns[i]) @@ -118,6 +120,12 @@ func (u *User) assignValues(columns []string, values []any) error { } else if value.Valid { u.Name = value.String } + case user.FieldPassword: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field password", values[i]) + } else if value.Valid { + u.Password = value.String + } } } return nil @@ -163,6 +171,8 @@ func (u *User) String() string { builder.WriteString(fmt.Sprintf("id=%v, ", u.ID)) builder.WriteString("name=") builder.WriteString(u.Name) + builder.WriteString(", ") + builder.WriteString("password=") builder.WriteByte(')') return builder.String() } diff --git a/entgql/internal/todo/ent/user/user.go b/entgql/internal/todo/ent/user/user.go index 397afd23d..dcdd7e2f6 100644 --- a/entgql/internal/todo/ent/user/user.go +++ b/entgql/internal/todo/ent/user/user.go @@ -23,6 +23,8 @@ const ( FieldID = "id" // FieldName holds the string denoting the name field in the database. FieldName = "name" + // FieldPassword holds the string denoting the password field in the database. + FieldPassword = "password" // EdgeGroups holds the string denoting the groups edge name in mutations. EdgeGroups = "groups" // EdgeFriends holds the string denoting the friends edge name in mutations. @@ -51,6 +53,7 @@ const ( var Columns = []string{ FieldID, FieldName, + FieldPassword, } var ( diff --git a/entgql/internal/todo/ent/user/where.go b/entgql/internal/todo/ent/user/where.go index 0990e9d76..0fa5471cf 100644 --- a/entgql/internal/todo/ent/user/where.go +++ b/entgql/internal/todo/ent/user/where.go @@ -100,6 +100,13 @@ func Name(v string) predicate.User { }) } +// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. +func Password(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.User { return predicate.User(func(s *sql.Selector) { @@ -199,6 +206,119 @@ func NameContainsFold(v string) predicate.User { }) } +// PasswordEQ applies the EQ predicate on the "password" field. +func PasswordEQ(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + +// PasswordNEQ applies the NEQ predicate on the "password" field. +func PasswordNEQ(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldPassword), v)) + }) +} + +// PasswordIn applies the In predicate on the "password" field. +func PasswordIn(vs ...string) predicate.User { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.User(func(s *sql.Selector) { + s.Where(sql.In(s.C(FieldPassword), v...)) + }) +} + +// PasswordNotIn applies the NotIn predicate on the "password" field. +func PasswordNotIn(vs ...string) predicate.User { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NotIn(s.C(FieldPassword), v...)) + }) +} + +// PasswordGT applies the GT predicate on the "password" field. +func PasswordGT(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldPassword), v)) + }) +} + +// PasswordGTE applies the GTE predicate on the "password" field. +func PasswordGTE(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldPassword), v)) + }) +} + +// PasswordLT applies the LT predicate on the "password" field. +func PasswordLT(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldPassword), v)) + }) +} + +// PasswordLTE applies the LTE predicate on the "password" field. +func PasswordLTE(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldPassword), v)) + }) +} + +// PasswordContains applies the Contains predicate on the "password" field. +func PasswordContains(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldPassword), v)) + }) +} + +// PasswordHasPrefix applies the HasPrefix predicate on the "password" field. +func PasswordHasPrefix(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldPassword), v)) + }) +} + +// PasswordHasSuffix applies the HasSuffix predicate on the "password" field. +func PasswordHasSuffix(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldPassword), v)) + }) +} + +// PasswordIsNil applies the IsNil predicate on the "password" field. +func PasswordIsNil() predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldPassword))) + }) +} + +// PasswordNotNil applies the NotNil predicate on the "password" field. +func PasswordNotNil() predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldPassword))) + }) +} + +// PasswordEqualFold applies the EqualFold predicate on the "password" field. +func PasswordEqualFold(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldPassword), v)) + }) +} + +// PasswordContainsFold applies the ContainsFold predicate on the "password" field. +func PasswordContainsFold(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldPassword), v)) + }) +} + // HasGroups applies the HasEdge predicate on the "groups" edge. func HasGroups() predicate.User { return predicate.User(func(s *sql.Selector) { diff --git a/entgql/internal/todo/ent/user_create.go b/entgql/internal/todo/ent/user_create.go index fa6cc4dae..cdc1793a9 100644 --- a/entgql/internal/todo/ent/user_create.go +++ b/entgql/internal/todo/ent/user_create.go @@ -49,6 +49,20 @@ func (uc *UserCreate) SetNillableName(s *string) *UserCreate { return uc } +// SetPassword sets the "password" field. +func (uc *UserCreate) SetPassword(s string) *UserCreate { + uc.mutation.SetPassword(s) + return uc +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uc *UserCreate) SetNillablePassword(s *string) *UserCreate { + if s != nil { + uc.SetPassword(*s) + } + return uc +} + // AddGroupIDs adds the "groups" edge to the Group entity by IDs. func (uc *UserCreate) AddGroupIDs(ids ...int) *UserCreate { uc.mutation.AddGroupIDs(ids...) @@ -217,6 +231,14 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { }) _node.Name = value } + if value, ok := uc.mutation.Password(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + _node.Password = value + } if nodes := uc.mutation.GroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/entgql/internal/todo/ent/user_update.go b/entgql/internal/todo/ent/user_update.go index 6dff4ddfc..82bcc820e 100644 --- a/entgql/internal/todo/ent/user_update.go +++ b/entgql/internal/todo/ent/user_update.go @@ -57,6 +57,26 @@ func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { return uu } +// SetPassword sets the "password" field. +func (uu *UserUpdate) SetPassword(s string) *UserUpdate { + uu.mutation.SetPassword(s) + return uu +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate { + if s != nil { + uu.SetPassword(*s) + } + return uu +} + +// ClearPassword clears the value of the "password" field. +func (uu *UserUpdate) ClearPassword() *UserUpdate { + uu.mutation.ClearPassword() + return uu +} + // AddGroupIDs adds the "groups" edge to the Group entity by IDs. func (uu *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate { uu.mutation.AddGroupIDs(ids...) @@ -249,6 +269,19 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: user.FieldName, }) } + if value, ok := uu.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + } + if uu.mutation.PasswordCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: user.FieldPassword, + }) + } if uu.mutation.GroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, @@ -456,6 +489,26 @@ func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { return uuo } +// SetPassword sets the "password" field. +func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne { + uuo.mutation.SetPassword(s) + return uuo +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne { + if s != nil { + uuo.SetPassword(*s) + } + return uuo +} + +// ClearPassword clears the value of the "password" field. +func (uuo *UserUpdateOne) ClearPassword() *UserUpdateOne { + uuo.mutation.ClearPassword() + return uuo +} + // AddGroupIDs adds the "groups" edge to the Group entity by IDs. func (uuo *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne { uuo.mutation.AddGroupIDs(ids...) @@ -678,6 +731,19 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Column: user.FieldName, }) } + if value, ok := uuo.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + } + if uuo.mutation.PasswordCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: user.FieldPassword, + }) + } if uuo.mutation.GroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/entgql/internal/todo/generated.go b/entgql/internal/todo/generated.go index de6a7539f..e9e15b248 100644 --- a/entgql/internal/todo/generated.go +++ b/entgql/internal/todo/generated.go @@ -902,6 +902,7 @@ Input was generated by ent. """ input CreateUserInput { name: String + password: String groupIDs: [ID!] friendIDs: [ID!] } @@ -1269,6 +1270,8 @@ Input was generated by ent. """ input UpdateUserInput { name: String + clearPassword: Boolean + password: String addGroupIDs: [ID!] removeGroupIDs: [ID!] addFriendIDs: [ID!] @@ -7424,6 +7427,14 @@ func (ec *executionContext) unmarshalInputCreateUserInput(ctx context.Context, o if err != nil { return it, err } + case "password": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "groupIDs": var err error @@ -8449,6 +8460,22 @@ func (ec *executionContext) unmarshalInputUpdateUserInput(ctx context.Context, o if err != nil { return it, err } + case "clearPassword": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearPassword")) + it.ClearPassword, err = ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + case "password": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "addGroupIDs": var err error diff --git a/entgql/internal/todogotype/generated.go b/entgql/internal/todogotype/generated.go index 66b44660d..d89f56fc9 100644 --- a/entgql/internal/todogotype/generated.go +++ b/entgql/internal/todogotype/generated.go @@ -920,6 +920,7 @@ Input was generated by ent. """ input CreateUserInput { name: String + password: String groupIDs: [ID!] friendIDs: [ID!] } @@ -1287,6 +1288,8 @@ Input was generated by ent. """ input UpdateUserInput { name: String + clearPassword: Boolean + password: String addGroupIDs: [ID!] removeGroupIDs: [ID!] addFriendIDs: [ID!] @@ -7445,6 +7448,14 @@ func (ec *executionContext) unmarshalInputCreateUserInput(ctx context.Context, o if err != nil { return it, err } + case "password": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "groupIDs": var err error @@ -8485,6 +8496,22 @@ func (ec *executionContext) unmarshalInputUpdateUserInput(ctx context.Context, o if err != nil { return it, err } + case "clearPassword": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearPassword")) + it.ClearPassword, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + case "password": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "addGroupIDs": var err error diff --git a/entgql/internal/todogotype/models_gen.go b/entgql/internal/todogotype/models_gen.go index aa7ba8d34..207e7c1bc 100644 --- a/entgql/internal/todogotype/models_gen.go +++ b/entgql/internal/todogotype/models_gen.go @@ -6,6 +6,7 @@ package todo // Input was generated by ent. type CreateUserInput struct { Name *string `json:"name"` + Password *string `json:"password"` GroupIDs []string `json:"groupIDs"` FriendIDs []string `json:"friendIDs"` } @@ -14,6 +15,8 @@ type CreateUserInput struct { // Input was generated by ent. type UpdateUserInput struct { Name *string `json:"name"` + ClearPassword *bool `json:"clearPassword"` + Password *string `json:"password"` AddGroupIDs []string `json:"addGroupIDs"` RemoveGroupIDs []string `json:"removeGroupIDs"` AddFriendIDs []string `json:"addFriendIDs"` diff --git a/entgql/internal/todopulid/ent/gql_mutation_input.go b/entgql/internal/todopulid/ent/gql_mutation_input.go index b252edab9..0350be948 100644 --- a/entgql/internal/todopulid/ent/gql_mutation_input.go +++ b/entgql/internal/todopulid/ent/gql_mutation_input.go @@ -118,6 +118,7 @@ func (c *TodoUpdateOne) SetInput(i UpdateTodoInput) *TodoUpdateOne { // CreateUserInput represents a mutation input for creating users. type CreateUserInput struct { Name *string + Password *string GroupIDs []pulid.ID FriendIDs []pulid.ID } @@ -127,6 +128,9 @@ func (i *CreateUserInput) Mutate(m *UserMutation) { if v := i.Name; v != nil { m.SetName(*v) } + if v := i.Password; v != nil { + m.SetPassword(*v) + } if v := i.GroupIDs; len(v) > 0 { m.AddGroupIDs(v...) } @@ -144,6 +148,8 @@ func (c *UserCreate) SetInput(i CreateUserInput) *UserCreate { // UpdateUserInput represents a mutation input for updating users. type UpdateUserInput struct { Name *string + ClearPassword bool + Password *string AddGroupIDs []pulid.ID RemoveGroupIDs []pulid.ID AddFriendIDs []pulid.ID @@ -155,6 +161,12 @@ func (i *UpdateUserInput) Mutate(m *UserMutation) { if v := i.Name; v != nil { m.SetName(*v) } + if i.ClearPassword { + m.ClearPassword() + } + if v := i.Password; v != nil { + m.SetPassword(*v) + } if v := i.AddGroupIDs; len(v) > 0 { m.AddGroupIDs(v...) } diff --git a/entgql/internal/todopulid/ent/gql_node.go b/entgql/internal/todopulid/ent/gql_node.go index 6c07cb5be..49686b1ef 100644 --- a/entgql/internal/todopulid/ent/gql_node.go +++ b/entgql/internal/todopulid/ent/gql_node.go @@ -297,7 +297,7 @@ func (u *User) Node(ctx context.Context) (node *Node, err error) { node = &Node{ ID: u.ID, Type: "User", - Fields: make([]*Field, 1), + Fields: make([]*Field, 2), Edges: make([]*Edge, 3), } var buf []byte @@ -309,6 +309,14 @@ func (u *User) Node(ctx context.Context) (node *Node, err error) { Name: "name", Value: string(buf), } + if buf, err = json.Marshal(u.Password); err != nil { + return nil, err + } + node.Fields[1] = &Field{ + Type: "string", + Name: "password", + Value: string(buf), + } node.Edges[0] = &Edge{ Type: "Group", Name: "groups", diff --git a/entgql/internal/todopulid/ent/gql_where_input.go b/entgql/internal/todopulid/ent/gql_where_input.go index c27dea4db..f72d29742 100644 --- a/entgql/internal/todopulid/ent/gql_where_input.go +++ b/entgql/internal/todopulid/ent/gql_where_input.go @@ -1309,6 +1309,23 @@ type UserWhereInput struct { NameEqualFold *string `json:"nameEqualFold,omitempty"` NameContainsFold *string `json:"nameContainsFold,omitempty"` + // "password" field predicates. + Password *string `json:"password,omitempty"` + PasswordNEQ *string `json:"passwordNEQ,omitempty"` + PasswordIn []string `json:"passwordIn,omitempty"` + PasswordNotIn []string `json:"passwordNotIn,omitempty"` + PasswordGT *string `json:"passwordGT,omitempty"` + PasswordGTE *string `json:"passwordGTE,omitempty"` + PasswordLT *string `json:"passwordLT,omitempty"` + PasswordLTE *string `json:"passwordLTE,omitempty"` + PasswordContains *string `json:"passwordContains,omitempty"` + PasswordHasPrefix *string `json:"passwordHasPrefix,omitempty"` + PasswordHasSuffix *string `json:"passwordHasSuffix,omitempty"` + PasswordIsNil bool `json:"passwordIsNil,omitempty"` + PasswordNotNil bool `json:"passwordNotNil,omitempty"` + PasswordEqualFold *string `json:"passwordEqualFold,omitempty"` + PasswordContainsFold *string `json:"passwordContainsFold,omitempty"` + // "groups" edge predicates. HasGroups *bool `json:"hasGroups,omitempty"` HasGroupsWith []*GroupWhereInput `json:"hasGroupsWith,omitempty"` @@ -1456,6 +1473,51 @@ func (i *UserWhereInput) P() (predicate.User, error) { if i.NameContainsFold != nil { predicates = append(predicates, user.NameContainsFold(*i.NameContainsFold)) } + if i.Password != nil { + predicates = append(predicates, user.PasswordEQ(*i.Password)) + } + if i.PasswordNEQ != nil { + predicates = append(predicates, user.PasswordNEQ(*i.PasswordNEQ)) + } + if len(i.PasswordIn) > 0 { + predicates = append(predicates, user.PasswordIn(i.PasswordIn...)) + } + if len(i.PasswordNotIn) > 0 { + predicates = append(predicates, user.PasswordNotIn(i.PasswordNotIn...)) + } + if i.PasswordGT != nil { + predicates = append(predicates, user.PasswordGT(*i.PasswordGT)) + } + if i.PasswordGTE != nil { + predicates = append(predicates, user.PasswordGTE(*i.PasswordGTE)) + } + if i.PasswordLT != nil { + predicates = append(predicates, user.PasswordLT(*i.PasswordLT)) + } + if i.PasswordLTE != nil { + predicates = append(predicates, user.PasswordLTE(*i.PasswordLTE)) + } + if i.PasswordContains != nil { + predicates = append(predicates, user.PasswordContains(*i.PasswordContains)) + } + if i.PasswordHasPrefix != nil { + predicates = append(predicates, user.PasswordHasPrefix(*i.PasswordHasPrefix)) + } + if i.PasswordHasSuffix != nil { + predicates = append(predicates, user.PasswordHasSuffix(*i.PasswordHasSuffix)) + } + if i.PasswordIsNil { + predicates = append(predicates, user.PasswordIsNil()) + } + if i.PasswordNotNil { + predicates = append(predicates, user.PasswordNotNil()) + } + if i.PasswordEqualFold != nil { + predicates = append(predicates, user.PasswordEqualFold(*i.PasswordEqualFold)) + } + if i.PasswordContainsFold != nil { + predicates = append(predicates, user.PasswordContainsFold(*i.PasswordContainsFold)) + } if i.HasGroups != nil { p := user.HasGroups() diff --git a/entgql/internal/todopulid/ent/migrate/schema.go b/entgql/internal/todopulid/ent/migrate/schema.go index 3cfe19ea3..fd39bcd92 100644 --- a/entgql/internal/todopulid/ent/migrate/schema.go +++ b/entgql/internal/todopulid/ent/migrate/schema.go @@ -125,6 +125,7 @@ var ( UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeString}, {Name: "name", Type: field.TypeString, Default: "Anonymous"}, + {Name: "password", Type: field.TypeString, Nullable: true}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ diff --git a/entgql/internal/todopulid/ent/mutation.go b/entgql/internal/todopulid/ent/mutation.go index 8c49b3830..ab3b60584 100644 --- a/entgql/internal/todopulid/ent/mutation.go +++ b/entgql/internal/todopulid/ent/mutation.go @@ -2743,6 +2743,7 @@ type UserMutation struct { typ string id *pulid.ID name *string + password *string clearedFields map[string]struct{} groups map[pulid.ID]struct{} removedgroups map[pulid.ID]struct{} @@ -2898,6 +2899,55 @@ func (m *UserMutation) ResetName() { m.name = nil } +// SetPassword sets the "password" field. +func (m *UserMutation) SetPassword(s string) { + m.password = &s +} + +// Password returns the value of the "password" field in the mutation. +func (m *UserMutation) Password() (r string, exists bool) { + v := m.password + if v == nil { + return + } + return *v, true +} + +// OldPassword returns the old "password" field's value of the User entity. +// If the User object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPassword is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPassword requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPassword: %w", err) + } + return oldValue.Password, nil +} + +// ClearPassword clears the value of the "password" field. +func (m *UserMutation) ClearPassword() { + m.password = nil + m.clearedFields[user.FieldPassword] = struct{}{} +} + +// PasswordCleared returns if the "password" field was cleared in this mutation. +func (m *UserMutation) PasswordCleared() bool { + _, ok := m.clearedFields[user.FieldPassword] + return ok +} + +// ResetPassword resets all changes to the "password" field. +func (m *UserMutation) ResetPassword() { + m.password = nil + delete(m.clearedFields, user.FieldPassword) +} + // AddGroupIDs adds the "groups" edge to the Group entity by ids. func (m *UserMutation) AddGroupIDs(ids ...pulid.ID) { if m.groups == nil { @@ -3079,10 +3129,13 @@ func (m *UserMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 1) + fields := make([]string, 0, 2) if m.name != nil { fields = append(fields, user.FieldName) } + if m.password != nil { + fields = append(fields, user.FieldPassword) + } return fields } @@ -3093,6 +3146,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { switch name { case user.FieldName: return m.Name() + case user.FieldPassword: + return m.Password() } return nil, false } @@ -3104,6 +3159,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er switch name { case user.FieldName: return m.OldName(ctx) + case user.FieldPassword: + return m.OldPassword(ctx) } return nil, fmt.Errorf("unknown User field %s", name) } @@ -3120,6 +3177,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { } m.SetName(v) return nil + case user.FieldPassword: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPassword(v) + return nil } return fmt.Errorf("unknown User field %s", name) } @@ -3149,7 +3213,11 @@ func (m *UserMutation) AddField(name string, value ent.Value) error { // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserMutation) ClearedFields() []string { - return nil + var fields []string + if m.FieldCleared(user.FieldPassword) { + fields = append(fields, user.FieldPassword) + } + return fields } // FieldCleared returns a boolean indicating if a field with the given name was @@ -3162,6 +3230,11 @@ func (m *UserMutation) FieldCleared(name string) bool { // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *UserMutation) ClearField(name string) error { + switch name { + case user.FieldPassword: + m.ClearPassword() + return nil + } return fmt.Errorf("unknown User nullable field %s", name) } @@ -3172,6 +3245,9 @@ func (m *UserMutation) ResetField(name string) error { case user.FieldName: m.ResetName() return nil + case user.FieldPassword: + m.ResetPassword() + return nil } return fmt.Errorf("unknown User field %s", name) } diff --git a/entgql/internal/todopulid/ent/user.go b/entgql/internal/todopulid/ent/user.go index 66ad6620e..bf66e97f2 100644 --- a/entgql/internal/todopulid/ent/user.go +++ b/entgql/internal/todopulid/ent/user.go @@ -32,6 +32,8 @@ type User struct { ID pulid.ID `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` + // Password holds the value of the "password" field. + Password string `json:"-"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the UserQuery when eager-loading is set. Edges UserEdges `json:"edges"` @@ -90,7 +92,7 @@ func (*User) scanValues(columns []string) ([]any, error) { switch columns[i] { case user.FieldID: values[i] = new(pulid.ID) - case user.FieldName: + case user.FieldName, user.FieldPassword: values[i] = new(sql.NullString) default: return nil, fmt.Errorf("unexpected column %q for type User", columns[i]) @@ -119,6 +121,12 @@ func (u *User) assignValues(columns []string, values []any) error { } else if value.Valid { u.Name = value.String } + case user.FieldPassword: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field password", values[i]) + } else if value.Valid { + u.Password = value.String + } } } return nil @@ -164,6 +172,8 @@ func (u *User) String() string { builder.WriteString(fmt.Sprintf("id=%v, ", u.ID)) builder.WriteString("name=") builder.WriteString(u.Name) + builder.WriteString(", ") + builder.WriteString("password=") builder.WriteByte(')') return builder.String() } diff --git a/entgql/internal/todopulid/ent/user/user.go b/entgql/internal/todopulid/ent/user/user.go index 283421700..624fb520a 100644 --- a/entgql/internal/todopulid/ent/user/user.go +++ b/entgql/internal/todopulid/ent/user/user.go @@ -27,6 +27,8 @@ const ( FieldID = "id" // FieldName holds the string denoting the name field in the database. FieldName = "name" + // FieldPassword holds the string denoting the password field in the database. + FieldPassword = "password" // EdgeGroups holds the string denoting the groups edge name in mutations. EdgeGroups = "groups" // EdgeFriends holds the string denoting the friends edge name in mutations. @@ -55,6 +57,7 @@ const ( var Columns = []string{ FieldID, FieldName, + FieldPassword, } var ( diff --git a/entgql/internal/todopulid/ent/user/where.go b/entgql/internal/todopulid/ent/user/where.go index 6f9677633..530cf70b5 100644 --- a/entgql/internal/todopulid/ent/user/where.go +++ b/entgql/internal/todopulid/ent/user/where.go @@ -101,6 +101,13 @@ func Name(v string) predicate.User { }) } +// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. +func Password(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.User { return predicate.User(func(s *sql.Selector) { @@ -200,6 +207,119 @@ func NameContainsFold(v string) predicate.User { }) } +// PasswordEQ applies the EQ predicate on the "password" field. +func PasswordEQ(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + +// PasswordNEQ applies the NEQ predicate on the "password" field. +func PasswordNEQ(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldPassword), v)) + }) +} + +// PasswordIn applies the In predicate on the "password" field. +func PasswordIn(vs ...string) predicate.User { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.User(func(s *sql.Selector) { + s.Where(sql.In(s.C(FieldPassword), v...)) + }) +} + +// PasswordNotIn applies the NotIn predicate on the "password" field. +func PasswordNotIn(vs ...string) predicate.User { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NotIn(s.C(FieldPassword), v...)) + }) +} + +// PasswordGT applies the GT predicate on the "password" field. +func PasswordGT(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldPassword), v)) + }) +} + +// PasswordGTE applies the GTE predicate on the "password" field. +func PasswordGTE(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldPassword), v)) + }) +} + +// PasswordLT applies the LT predicate on the "password" field. +func PasswordLT(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldPassword), v)) + }) +} + +// PasswordLTE applies the LTE predicate on the "password" field. +func PasswordLTE(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldPassword), v)) + }) +} + +// PasswordContains applies the Contains predicate on the "password" field. +func PasswordContains(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldPassword), v)) + }) +} + +// PasswordHasPrefix applies the HasPrefix predicate on the "password" field. +func PasswordHasPrefix(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldPassword), v)) + }) +} + +// PasswordHasSuffix applies the HasSuffix predicate on the "password" field. +func PasswordHasSuffix(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldPassword), v)) + }) +} + +// PasswordIsNil applies the IsNil predicate on the "password" field. +func PasswordIsNil() predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldPassword))) + }) +} + +// PasswordNotNil applies the NotNil predicate on the "password" field. +func PasswordNotNil() predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldPassword))) + }) +} + +// PasswordEqualFold applies the EqualFold predicate on the "password" field. +func PasswordEqualFold(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldPassword), v)) + }) +} + +// PasswordContainsFold applies the ContainsFold predicate on the "password" field. +func PasswordContainsFold(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldPassword), v)) + }) +} + // HasGroups applies the HasEdge predicate on the "groups" edge. func HasGroups() predicate.User { return predicate.User(func(s *sql.Selector) { diff --git a/entgql/internal/todopulid/ent/user_create.go b/entgql/internal/todopulid/ent/user_create.go index d6e61407c..87ed1ca77 100644 --- a/entgql/internal/todopulid/ent/user_create.go +++ b/entgql/internal/todopulid/ent/user_create.go @@ -50,6 +50,20 @@ func (uc *UserCreate) SetNillableName(s *string) *UserCreate { return uc } +// SetPassword sets the "password" field. +func (uc *UserCreate) SetPassword(s string) *UserCreate { + uc.mutation.SetPassword(s) + return uc +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uc *UserCreate) SetNillablePassword(s *string) *UserCreate { + if s != nil { + uc.SetPassword(*s) + } + return uc +} + // SetID sets the "id" field. func (uc *UserCreate) SetID(pu pulid.ID) *UserCreate { uc.mutation.SetID(pu) @@ -245,6 +259,14 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { }) _node.Name = value } + if value, ok := uc.mutation.Password(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + _node.Password = value + } if nodes := uc.mutation.GroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/entgql/internal/todopulid/ent/user_update.go b/entgql/internal/todopulid/ent/user_update.go index 3bc70d4e4..ab18aae75 100644 --- a/entgql/internal/todopulid/ent/user_update.go +++ b/entgql/internal/todopulid/ent/user_update.go @@ -58,6 +58,26 @@ func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { return uu } +// SetPassword sets the "password" field. +func (uu *UserUpdate) SetPassword(s string) *UserUpdate { + uu.mutation.SetPassword(s) + return uu +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate { + if s != nil { + uu.SetPassword(*s) + } + return uu +} + +// ClearPassword clears the value of the "password" field. +func (uu *UserUpdate) ClearPassword() *UserUpdate { + uu.mutation.ClearPassword() + return uu +} + // AddGroupIDs adds the "groups" edge to the Group entity by IDs. func (uu *UserUpdate) AddGroupIDs(ids ...pulid.ID) *UserUpdate { uu.mutation.AddGroupIDs(ids...) @@ -250,6 +270,19 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: user.FieldName, }) } + if value, ok := uu.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + } + if uu.mutation.PasswordCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: user.FieldPassword, + }) + } if uu.mutation.GroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, @@ -466,6 +499,26 @@ func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { return uuo } +// SetPassword sets the "password" field. +func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne { + uuo.mutation.SetPassword(s) + return uuo +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne { + if s != nil { + uuo.SetPassword(*s) + } + return uuo +} + +// ClearPassword clears the value of the "password" field. +func (uuo *UserUpdateOne) ClearPassword() *UserUpdateOne { + uuo.mutation.ClearPassword() + return uuo +} + // AddGroupIDs adds the "groups" edge to the Group entity by IDs. func (uuo *UserUpdateOne) AddGroupIDs(ids ...pulid.ID) *UserUpdateOne { uuo.mutation.AddGroupIDs(ids...) @@ -688,6 +741,19 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Column: user.FieldName, }) } + if value, ok := uuo.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + } + if uuo.mutation.PasswordCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: user.FieldPassword, + }) + } if uuo.mutation.GroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/entgql/internal/todopulid/generated.go b/entgql/internal/todopulid/generated.go index 34320fa76..81e25bde3 100644 --- a/entgql/internal/todopulid/generated.go +++ b/entgql/internal/todopulid/generated.go @@ -920,6 +920,7 @@ Input was generated by ent. """ input CreateUserInput { name: String + password: String groupIDs: [ID!] friendIDs: [ID!] } @@ -1287,6 +1288,8 @@ Input was generated by ent. """ input UpdateUserInput { name: String + clearPassword: Boolean + password: String addGroupIDs: [ID!] removeGroupIDs: [ID!] addFriendIDs: [ID!] @@ -7445,6 +7448,14 @@ func (ec *executionContext) unmarshalInputCreateUserInput(ctx context.Context, o if err != nil { return it, err } + case "password": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "groupIDs": var err error @@ -8485,6 +8496,22 @@ func (ec *executionContext) unmarshalInputUpdateUserInput(ctx context.Context, o if err != nil { return it, err } + case "clearPassword": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearPassword")) + it.ClearPassword, err = ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + case "password": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "addGroupIDs": var err error diff --git a/entgql/internal/todouuid/ent/gql_mutation_input.go b/entgql/internal/todouuid/ent/gql_mutation_input.go index f88d878f6..672cca7c1 100644 --- a/entgql/internal/todouuid/ent/gql_mutation_input.go +++ b/entgql/internal/todouuid/ent/gql_mutation_input.go @@ -118,6 +118,7 @@ func (c *TodoUpdateOne) SetInput(i UpdateTodoInput) *TodoUpdateOne { // CreateUserInput represents a mutation input for creating users. type CreateUserInput struct { Name *string + Password *string GroupIDs []uuid.UUID FriendIDs []uuid.UUID } @@ -127,6 +128,9 @@ func (i *CreateUserInput) Mutate(m *UserMutation) { if v := i.Name; v != nil { m.SetName(*v) } + if v := i.Password; v != nil { + m.SetPassword(*v) + } if v := i.GroupIDs; len(v) > 0 { m.AddGroupIDs(v...) } @@ -144,6 +148,8 @@ func (c *UserCreate) SetInput(i CreateUserInput) *UserCreate { // UpdateUserInput represents a mutation input for updating users. type UpdateUserInput struct { Name *string + ClearPassword bool + Password *string AddGroupIDs []uuid.UUID RemoveGroupIDs []uuid.UUID AddFriendIDs []uuid.UUID @@ -155,6 +161,12 @@ func (i *UpdateUserInput) Mutate(m *UserMutation) { if v := i.Name; v != nil { m.SetName(*v) } + if i.ClearPassword { + m.ClearPassword() + } + if v := i.Password; v != nil { + m.SetPassword(*v) + } if v := i.AddGroupIDs; len(v) > 0 { m.AddGroupIDs(v...) } diff --git a/entgql/internal/todouuid/ent/gql_node.go b/entgql/internal/todouuid/ent/gql_node.go index b65bb6afb..25e2df7b1 100644 --- a/entgql/internal/todouuid/ent/gql_node.go +++ b/entgql/internal/todouuid/ent/gql_node.go @@ -297,7 +297,7 @@ func (u *User) Node(ctx context.Context) (node *Node, err error) { node = &Node{ ID: u.ID, Type: "User", - Fields: make([]*Field, 1), + Fields: make([]*Field, 2), Edges: make([]*Edge, 3), } var buf []byte @@ -309,6 +309,14 @@ func (u *User) Node(ctx context.Context) (node *Node, err error) { Name: "name", Value: string(buf), } + if buf, err = json.Marshal(u.Password); err != nil { + return nil, err + } + node.Fields[1] = &Field{ + Type: "string", + Name: "password", + Value: string(buf), + } node.Edges[0] = &Edge{ Type: "Group", Name: "groups", diff --git a/entgql/internal/todouuid/ent/gql_where_input.go b/entgql/internal/todouuid/ent/gql_where_input.go index 35d389109..ebb677adf 100644 --- a/entgql/internal/todouuid/ent/gql_where_input.go +++ b/entgql/internal/todouuid/ent/gql_where_input.go @@ -1201,6 +1201,23 @@ type UserWhereInput struct { NameEqualFold *string `json:"nameEqualFold,omitempty"` NameContainsFold *string `json:"nameContainsFold,omitempty"` + // "password" field predicates. + Password *string `json:"password,omitempty"` + PasswordNEQ *string `json:"passwordNEQ,omitempty"` + PasswordIn []string `json:"passwordIn,omitempty"` + PasswordNotIn []string `json:"passwordNotIn,omitempty"` + PasswordGT *string `json:"passwordGT,omitempty"` + PasswordGTE *string `json:"passwordGTE,omitempty"` + PasswordLT *string `json:"passwordLT,omitempty"` + PasswordLTE *string `json:"passwordLTE,omitempty"` + PasswordContains *string `json:"passwordContains,omitempty"` + PasswordHasPrefix *string `json:"passwordHasPrefix,omitempty"` + PasswordHasSuffix *string `json:"passwordHasSuffix,omitempty"` + PasswordIsNil bool `json:"passwordIsNil,omitempty"` + PasswordNotNil bool `json:"passwordNotNil,omitempty"` + PasswordEqualFold *string `json:"passwordEqualFold,omitempty"` + PasswordContainsFold *string `json:"passwordContainsFold,omitempty"` + // "groups" edge predicates. HasGroups *bool `json:"hasGroups,omitempty"` HasGroupsWith []*GroupWhereInput `json:"hasGroupsWith,omitempty"` @@ -1348,6 +1365,51 @@ func (i *UserWhereInput) P() (predicate.User, error) { if i.NameContainsFold != nil { predicates = append(predicates, user.NameContainsFold(*i.NameContainsFold)) } + if i.Password != nil { + predicates = append(predicates, user.PasswordEQ(*i.Password)) + } + if i.PasswordNEQ != nil { + predicates = append(predicates, user.PasswordNEQ(*i.PasswordNEQ)) + } + if len(i.PasswordIn) > 0 { + predicates = append(predicates, user.PasswordIn(i.PasswordIn...)) + } + if len(i.PasswordNotIn) > 0 { + predicates = append(predicates, user.PasswordNotIn(i.PasswordNotIn...)) + } + if i.PasswordGT != nil { + predicates = append(predicates, user.PasswordGT(*i.PasswordGT)) + } + if i.PasswordGTE != nil { + predicates = append(predicates, user.PasswordGTE(*i.PasswordGTE)) + } + if i.PasswordLT != nil { + predicates = append(predicates, user.PasswordLT(*i.PasswordLT)) + } + if i.PasswordLTE != nil { + predicates = append(predicates, user.PasswordLTE(*i.PasswordLTE)) + } + if i.PasswordContains != nil { + predicates = append(predicates, user.PasswordContains(*i.PasswordContains)) + } + if i.PasswordHasPrefix != nil { + predicates = append(predicates, user.PasswordHasPrefix(*i.PasswordHasPrefix)) + } + if i.PasswordHasSuffix != nil { + predicates = append(predicates, user.PasswordHasSuffix(*i.PasswordHasSuffix)) + } + if i.PasswordIsNil { + predicates = append(predicates, user.PasswordIsNil()) + } + if i.PasswordNotNil { + predicates = append(predicates, user.PasswordNotNil()) + } + if i.PasswordEqualFold != nil { + predicates = append(predicates, user.PasswordEqualFold(*i.PasswordEqualFold)) + } + if i.PasswordContainsFold != nil { + predicates = append(predicates, user.PasswordContainsFold(*i.PasswordContainsFold)) + } if i.HasGroups != nil { p := user.HasGroups() diff --git a/entgql/internal/todouuid/ent/migrate/schema.go b/entgql/internal/todouuid/ent/migrate/schema.go index 639747c01..adfefedba 100644 --- a/entgql/internal/todouuid/ent/migrate/schema.go +++ b/entgql/internal/todouuid/ent/migrate/schema.go @@ -125,6 +125,7 @@ var ( UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "name", Type: field.TypeString, Default: "Anonymous"}, + {Name: "password", Type: field.TypeString, Nullable: true}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ diff --git a/entgql/internal/todouuid/ent/mutation.go b/entgql/internal/todouuid/ent/mutation.go index 3ca33f4be..0accfaac3 100644 --- a/entgql/internal/todouuid/ent/mutation.go +++ b/entgql/internal/todouuid/ent/mutation.go @@ -2743,6 +2743,7 @@ type UserMutation struct { typ string id *uuid.UUID name *string + password *string clearedFields map[string]struct{} groups map[uuid.UUID]struct{} removedgroups map[uuid.UUID]struct{} @@ -2898,6 +2899,55 @@ func (m *UserMutation) ResetName() { m.name = nil } +// SetPassword sets the "password" field. +func (m *UserMutation) SetPassword(s string) { + m.password = &s +} + +// Password returns the value of the "password" field in the mutation. +func (m *UserMutation) Password() (r string, exists bool) { + v := m.password + if v == nil { + return + } + return *v, true +} + +// OldPassword returns the old "password" field's value of the User entity. +// If the User object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPassword is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPassword requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPassword: %w", err) + } + return oldValue.Password, nil +} + +// ClearPassword clears the value of the "password" field. +func (m *UserMutation) ClearPassword() { + m.password = nil + m.clearedFields[user.FieldPassword] = struct{}{} +} + +// PasswordCleared returns if the "password" field was cleared in this mutation. +func (m *UserMutation) PasswordCleared() bool { + _, ok := m.clearedFields[user.FieldPassword] + return ok +} + +// ResetPassword resets all changes to the "password" field. +func (m *UserMutation) ResetPassword() { + m.password = nil + delete(m.clearedFields, user.FieldPassword) +} + // AddGroupIDs adds the "groups" edge to the Group entity by ids. func (m *UserMutation) AddGroupIDs(ids ...uuid.UUID) { if m.groups == nil { @@ -3079,10 +3129,13 @@ func (m *UserMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 1) + fields := make([]string, 0, 2) if m.name != nil { fields = append(fields, user.FieldName) } + if m.password != nil { + fields = append(fields, user.FieldPassword) + } return fields } @@ -3093,6 +3146,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { switch name { case user.FieldName: return m.Name() + case user.FieldPassword: + return m.Password() } return nil, false } @@ -3104,6 +3159,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er switch name { case user.FieldName: return m.OldName(ctx) + case user.FieldPassword: + return m.OldPassword(ctx) } return nil, fmt.Errorf("unknown User field %s", name) } @@ -3120,6 +3177,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { } m.SetName(v) return nil + case user.FieldPassword: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPassword(v) + return nil } return fmt.Errorf("unknown User field %s", name) } @@ -3149,7 +3213,11 @@ func (m *UserMutation) AddField(name string, value ent.Value) error { // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserMutation) ClearedFields() []string { - return nil + var fields []string + if m.FieldCleared(user.FieldPassword) { + fields = append(fields, user.FieldPassword) + } + return fields } // FieldCleared returns a boolean indicating if a field with the given name was @@ -3162,6 +3230,11 @@ func (m *UserMutation) FieldCleared(name string) bool { // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *UserMutation) ClearField(name string) error { + switch name { + case user.FieldPassword: + m.ClearPassword() + return nil + } return fmt.Errorf("unknown User nullable field %s", name) } @@ -3172,6 +3245,9 @@ func (m *UserMutation) ResetField(name string) error { case user.FieldName: m.ResetName() return nil + case user.FieldPassword: + m.ResetPassword() + return nil } return fmt.Errorf("unknown User field %s", name) } diff --git a/entgql/internal/todouuid/ent/user.go b/entgql/internal/todouuid/ent/user.go index 9e2910eb1..4ff0ac17c 100644 --- a/entgql/internal/todouuid/ent/user.go +++ b/entgql/internal/todouuid/ent/user.go @@ -32,6 +32,8 @@ type User struct { ID uuid.UUID `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` + // Password holds the value of the "password" field. + Password string `json:"-"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the UserQuery when eager-loading is set. Edges UserEdges `json:"edges"` @@ -88,7 +90,7 @@ func (*User) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case user.FieldName: + case user.FieldName, user.FieldPassword: values[i] = new(sql.NullString) case user.FieldID: values[i] = new(uuid.UUID) @@ -119,6 +121,12 @@ func (u *User) assignValues(columns []string, values []any) error { } else if value.Valid { u.Name = value.String } + case user.FieldPassword: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field password", values[i]) + } else if value.Valid { + u.Password = value.String + } } } return nil @@ -164,6 +172,8 @@ func (u *User) String() string { builder.WriteString(fmt.Sprintf("id=%v, ", u.ID)) builder.WriteString("name=") builder.WriteString(u.Name) + builder.WriteString(", ") + builder.WriteString("password=") builder.WriteByte(')') return builder.String() } diff --git a/entgql/internal/todouuid/ent/user/user.go b/entgql/internal/todouuid/ent/user/user.go index 0470b8843..05db78d2a 100644 --- a/entgql/internal/todouuid/ent/user/user.go +++ b/entgql/internal/todouuid/ent/user/user.go @@ -27,6 +27,8 @@ const ( FieldID = "id" // FieldName holds the string denoting the name field in the database. FieldName = "name" + // FieldPassword holds the string denoting the password field in the database. + FieldPassword = "password" // EdgeGroups holds the string denoting the groups edge name in mutations. EdgeGroups = "groups" // EdgeFriends holds the string denoting the friends edge name in mutations. @@ -55,6 +57,7 @@ const ( var Columns = []string{ FieldID, FieldName, + FieldPassword, } var ( diff --git a/entgql/internal/todouuid/ent/user/where.go b/entgql/internal/todouuid/ent/user/where.go index 4feeea007..5c4100040 100644 --- a/entgql/internal/todouuid/ent/user/where.go +++ b/entgql/internal/todouuid/ent/user/where.go @@ -101,6 +101,13 @@ func Name(v string) predicate.User { }) } +// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. +func Password(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.User { return predicate.User(func(s *sql.Selector) { @@ -200,6 +207,119 @@ func NameContainsFold(v string) predicate.User { }) } +// PasswordEQ applies the EQ predicate on the "password" field. +func PasswordEQ(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + +// PasswordNEQ applies the NEQ predicate on the "password" field. +func PasswordNEQ(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldPassword), v)) + }) +} + +// PasswordIn applies the In predicate on the "password" field. +func PasswordIn(vs ...string) predicate.User { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.User(func(s *sql.Selector) { + s.Where(sql.In(s.C(FieldPassword), v...)) + }) +} + +// PasswordNotIn applies the NotIn predicate on the "password" field. +func PasswordNotIn(vs ...string) predicate.User { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NotIn(s.C(FieldPassword), v...)) + }) +} + +// PasswordGT applies the GT predicate on the "password" field. +func PasswordGT(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldPassword), v)) + }) +} + +// PasswordGTE applies the GTE predicate on the "password" field. +func PasswordGTE(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldPassword), v)) + }) +} + +// PasswordLT applies the LT predicate on the "password" field. +func PasswordLT(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldPassword), v)) + }) +} + +// PasswordLTE applies the LTE predicate on the "password" field. +func PasswordLTE(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldPassword), v)) + }) +} + +// PasswordContains applies the Contains predicate on the "password" field. +func PasswordContains(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldPassword), v)) + }) +} + +// PasswordHasPrefix applies the HasPrefix predicate on the "password" field. +func PasswordHasPrefix(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldPassword), v)) + }) +} + +// PasswordHasSuffix applies the HasSuffix predicate on the "password" field. +func PasswordHasSuffix(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldPassword), v)) + }) +} + +// PasswordIsNil applies the IsNil predicate on the "password" field. +func PasswordIsNil() predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldPassword))) + }) +} + +// PasswordNotNil applies the NotNil predicate on the "password" field. +func PasswordNotNil() predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldPassword))) + }) +} + +// PasswordEqualFold applies the EqualFold predicate on the "password" field. +func PasswordEqualFold(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldPassword), v)) + }) +} + +// PasswordContainsFold applies the ContainsFold predicate on the "password" field. +func PasswordContainsFold(v string) predicate.User { + return predicate.User(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldPassword), v)) + }) +} + // HasGroups applies the HasEdge predicate on the "groups" edge. func HasGroups() predicate.User { return predicate.User(func(s *sql.Selector) { diff --git a/entgql/internal/todouuid/ent/user_create.go b/entgql/internal/todouuid/ent/user_create.go index 9f437dd25..abd8586f7 100644 --- a/entgql/internal/todouuid/ent/user_create.go +++ b/entgql/internal/todouuid/ent/user_create.go @@ -50,6 +50,20 @@ func (uc *UserCreate) SetNillableName(s *string) *UserCreate { return uc } +// SetPassword sets the "password" field. +func (uc *UserCreate) SetPassword(s string) *UserCreate { + uc.mutation.SetPassword(s) + return uc +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uc *UserCreate) SetNillablePassword(s *string) *UserCreate { + if s != nil { + uc.SetPassword(*s) + } + return uc +} + // SetID sets the "id" field. func (uc *UserCreate) SetID(u uuid.UUID) *UserCreate { uc.mutation.SetID(u) @@ -245,6 +259,14 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { }) _node.Name = value } + if value, ok := uc.mutation.Password(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + _node.Password = value + } if nodes := uc.mutation.GroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/entgql/internal/todouuid/ent/user_update.go b/entgql/internal/todouuid/ent/user_update.go index c05a679da..38c1ad67d 100644 --- a/entgql/internal/todouuid/ent/user_update.go +++ b/entgql/internal/todouuid/ent/user_update.go @@ -58,6 +58,26 @@ func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { return uu } +// SetPassword sets the "password" field. +func (uu *UserUpdate) SetPassword(s string) *UserUpdate { + uu.mutation.SetPassword(s) + return uu +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate { + if s != nil { + uu.SetPassword(*s) + } + return uu +} + +// ClearPassword clears the value of the "password" field. +func (uu *UserUpdate) ClearPassword() *UserUpdate { + uu.mutation.ClearPassword() + return uu +} + // AddGroupIDs adds the "groups" edge to the Group entity by IDs. func (uu *UserUpdate) AddGroupIDs(ids ...uuid.UUID) *UserUpdate { uu.mutation.AddGroupIDs(ids...) @@ -250,6 +270,19 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: user.FieldName, }) } + if value, ok := uu.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + } + if uu.mutation.PasswordCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: user.FieldPassword, + }) + } if uu.mutation.GroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, @@ -466,6 +499,26 @@ func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { return uuo } +// SetPassword sets the "password" field. +func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne { + uuo.mutation.SetPassword(s) + return uuo +} + +// SetNillablePassword sets the "password" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne { + if s != nil { + uuo.SetPassword(*s) + } + return uuo +} + +// ClearPassword clears the value of the "password" field. +func (uuo *UserUpdateOne) ClearPassword() *UserUpdateOne { + uuo.mutation.ClearPassword() + return uuo +} + // AddGroupIDs adds the "groups" edge to the Group entity by IDs. func (uuo *UserUpdateOne) AddGroupIDs(ids ...uuid.UUID) *UserUpdateOne { uuo.mutation.AddGroupIDs(ids...) @@ -688,6 +741,19 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Column: user.FieldName, }) } + if value, ok := uuo.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: user.FieldPassword, + }) + } + if uuo.mutation.PasswordCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: user.FieldPassword, + }) + } if uuo.mutation.GroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/entgql/internal/todouuid/generated.go b/entgql/internal/todouuid/generated.go index c8bb48564..8cc665dbb 100644 --- a/entgql/internal/todouuid/generated.go +++ b/entgql/internal/todouuid/generated.go @@ -921,6 +921,7 @@ Input was generated by ent. """ input CreateUserInput { name: String + password: String groupIDs: [ID!] friendIDs: [ID!] } @@ -1288,6 +1289,8 @@ Input was generated by ent. """ input UpdateUserInput { name: String + clearPassword: Boolean + password: String addGroupIDs: [ID!] removeGroupIDs: [ID!] addFriendIDs: [ID!] @@ -7446,6 +7449,14 @@ func (ec *executionContext) unmarshalInputCreateUserInput(ctx context.Context, o if err != nil { return it, err } + case "password": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "groupIDs": var err error @@ -8486,6 +8497,22 @@ func (ec *executionContext) unmarshalInputUpdateUserInput(ctx context.Context, o if err != nil { return it, err } + case "clearPassword": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearPassword")) + it.ClearPassword, err = ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + case "password": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "addGroupIDs": var err error diff --git a/entgql/schema.go b/entgql/schema.go index bdc57ddae..985cb2617 100644 --- a/entgql/schema.go +++ b/entgql/schema.go @@ -320,7 +320,7 @@ func (e *schemaGenerator) buildType(t *gen.Type, ant *Annotation, gqlType, pkg s if err != nil { return nil, err } - if ant.Skip.Is(SkipType) { + if ant.Skip.Is(SkipType) || f.Sensitive() { continue } @@ -486,14 +486,14 @@ func (e *schemaGenerator) buildWhereInput(t *gen.Type, nodeGQLType, gqlType stri fields := allFields(t) for _, f := range fields { - if t.IsEdgeSchema() && f.IsEdgeField() { + if t.IsEdgeSchema() && f.IsEdgeField() || !f.Type.Comparable() || f.Sensitive() { continue } ant, err := annotation(f.Annotations) if err != nil { return nil, err } - if ant.Skip.Is(SkipWhereInput) || !f.Type.Comparable() { + if ant.Skip.Is(SkipWhereInput) { continue } for i, op := range f.Ops() { diff --git a/entgql/schema_test.go b/entgql/schema_test.go index 9fd4151f8..ccbd383ac 100644 --- a/entgql/schema_test.go +++ b/entgql/schema_test.go @@ -85,6 +85,7 @@ Input was generated by ent. """ input CreateUserInput { name: String + password: String groupIDs: [ID!] friendIDs: [ID!] } @@ -164,6 +165,8 @@ Input was generated by ent. """ input UpdateUserInput { name: String + clearPassword: Boolean + password: String addGroupIDs: [ID!] removeGroupIDs: [ID!] addFriendIDs: [ID!] @@ -330,6 +333,7 @@ Input was generated by ent. """ input CreateUserInput { name: String + password: String groupIDs: [ID!] friendIDs: [ID!] } @@ -665,6 +669,8 @@ Input was generated by ent. """ input UpdateUserInput { name: String + clearPassword: Boolean + password: String addGroupIDs: [ID!] removeGroupIDs: [ID!] addFriendIDs: [ID!]