diff --git a/entgql/internal/todo/ent.graphql b/entgql/internal/todo/ent.graphql index c1d5b1595..03c085a81 100644 --- a/entgql/internal/todo/ent.graphql +++ b/entgql/internal/todo/ent.graphql @@ -318,6 +318,7 @@ input CreateTodoInput { priority: Int text: String! init: Map + value: Int parentID: ID childIDs: [ID!] categoryID: ID @@ -974,6 +975,7 @@ type Todo implements Node { init: Map custom: [Custom!] customp: [Custom] + value: Int! parent: Todo children( """ @@ -1145,6 +1147,17 @@ input TodoWhereInput { categoryIDIsNil: Boolean categoryIDNotNil: Boolean """ + value field predicates + """ + value: Int + valueNEQ: Int + valueIn: [Int!] + valueNotIn: [Int!] + valueGT: Int + valueGTE: Int + valueLT: Int + valueLTE: Int + """ parent edge predicates """ hasParent: Boolean @@ -1208,6 +1221,7 @@ input UpdateTodoInput { text: String init: Map clearInit: Boolean + value: Int parentID: ID clearParent: Boolean addChildIDs: [ID!] diff --git a/entgql/internal/todo/ent/gql_collection.go b/entgql/internal/todo/ent/gql_collection.go index 175dea929..ebe4ddd37 100644 --- a/entgql/internal/todo/ent/gql_collection.go +++ b/entgql/internal/todo/ent/gql_collection.go @@ -1123,6 +1123,11 @@ func (t *TodoQuery) collectField(ctx context.Context, oneNode bool, opCtx *graph selectedFields = append(selectedFields, todo.FieldCustomp) fieldSeen[todo.FieldCustomp] = struct{}{} } + case "value": + if _, ok := fieldSeen[todo.FieldValue]; !ok { + selectedFields = append(selectedFields, todo.FieldValue) + fieldSeen[todo.FieldValue] = struct{}{} + } case "id": case "__typename": default: diff --git a/entgql/internal/todo/ent/gql_mutation_input.go b/entgql/internal/todo/ent/gql_mutation_input.go index 730c07fff..08842e642 100644 --- a/entgql/internal/todo/ent/gql_mutation_input.go +++ b/entgql/internal/todo/ent/gql_mutation_input.go @@ -205,6 +205,7 @@ type CreateTodoInput struct { Priority *int Text string Init map[string]interface{} + Value *int ParentID *int ChildIDs []int CategoryID *int @@ -221,6 +222,9 @@ func (i *CreateTodoInput) Mutate(m *TodoMutation) { if v := i.Init; v != nil { m.SetInit(v) } + if v := i.Value; v != nil { + m.SetValue(*v) + } if v := i.ParentID; v != nil { m.SetParentID(*v) } @@ -248,6 +252,7 @@ type UpdateTodoInput struct { Text *string ClearInit bool Init map[string]interface{} + Value *int ClearParent bool ParentID *int ClearChildren bool @@ -274,6 +279,9 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) { if v := i.Init; v != nil { m.SetInit(v) } + if v := i.Value; v != nil { + m.SetValue(*v) + } if i.ClearParent { m.ClearParent() } diff --git a/entgql/internal/todo/ent/gql_node_descriptor.go b/entgql/internal/todo/ent/gql_node_descriptor.go index d2c36b293..fbdf93b28 100644 --- a/entgql/internal/todo/ent/gql_node_descriptor.go +++ b/entgql/internal/todo/ent/gql_node_descriptor.go @@ -334,7 +334,7 @@ func (t *Todo) Node(ctx context.Context) (node *Node, err error) { node = &Node{ ID: t.ID, Type: "Todo", - Fields: make([]*Field, 8), + Fields: make([]*Field, 9), Edges: make([]*Edge, 3), } var buf []byte @@ -402,6 +402,14 @@ func (t *Todo) Node(ctx context.Context) (node *Node, err error) { Name: "customp", Value: string(buf), } + if buf, err = json.Marshal(t.Value); err != nil { + return nil, err + } + node.Fields[8] = &Field{ + Type: "int", + Name: "value", + Value: string(buf), + } node.Edges[0] = &Edge{ Type: "Todo", Name: "parent", diff --git a/entgql/internal/todo/ent/gql_pagination.go b/entgql/internal/todo/ent/gql_pagination.go index 8a950a382..89d25786a 100644 --- a/entgql/internal/todo/ent/gql_pagination.go +++ b/entgql/internal/todo/ent/gql_pagination.go @@ -2205,7 +2205,7 @@ var ( // TodoOrderFieldParentStatus orders by PARENT_STATUS. TodoOrderFieldParentStatus = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("parent_status") + return t.GetValue("parent_status") }, column: "parent_status", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -2215,7 +2215,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("parent_status") + cv, _ := t.GetValue("parent_status") return Cursor{ ID: t.ID, Value: cv, @@ -2225,7 +2225,7 @@ var ( // TodoOrderFieldChildrenCount orders by CHILDREN_COUNT. TodoOrderFieldChildrenCount = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("children_count") + return t.GetValue("children_count") }, column: "children_count", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -2234,7 +2234,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("children_count") + cv, _ := t.GetValue("children_count") return Cursor{ ID: t.ID, Value: cv, @@ -2244,7 +2244,7 @@ var ( // TodoOrderFieldCategoryText orders by CATEGORY_TEXT. TodoOrderFieldCategoryText = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("category_text") + return t.GetValue("category_text") }, column: "category_text", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -2254,7 +2254,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("category_text") + cv, _ := t.GetValue("category_text") return Cursor{ ID: t.ID, Value: cv, diff --git a/entgql/internal/todo/ent/gql_where_input.go b/entgql/internal/todo/ent/gql_where_input.go index e1f3560da..060d464d6 100644 --- a/entgql/internal/todo/ent/gql_where_input.go +++ b/entgql/internal/todo/ent/gql_where_input.go @@ -1601,6 +1601,16 @@ type TodoWhereInput struct { CategoryIDIsNil bool `json:"categoryIDIsNil,omitempty"` CategoryIDNotNil bool `json:"categoryIDNotNil,omitempty"` + // "value" field predicates. + Value *int `json:"value,omitempty"` + ValueNEQ *int `json:"valueNEQ,omitempty"` + ValueIn []int `json:"valueIn,omitempty"` + ValueNotIn []int `json:"valueNotIn,omitempty"` + ValueGT *int `json:"valueGT,omitempty"` + ValueGTE *int `json:"valueGTE,omitempty"` + ValueLT *int `json:"valueLT,omitempty"` + ValueLTE *int `json:"valueLTE,omitempty"` + // "parent" edge predicates. HasParent *bool `json:"hasParent,omitempty"` HasParentWith []*TodoWhereInput `json:"hasParentWith,omitempty"` @@ -1826,6 +1836,30 @@ func (i *TodoWhereInput) P() (predicate.Todo, error) { if i.CategoryIDNotNil { predicates = append(predicates, todo.CategoryIDNotNil()) } + if i.Value != nil { + predicates = append(predicates, todo.ValueEQ(*i.Value)) + } + if i.ValueNEQ != nil { + predicates = append(predicates, todo.ValueNEQ(*i.ValueNEQ)) + } + if len(i.ValueIn) > 0 { + predicates = append(predicates, todo.ValueIn(i.ValueIn...)) + } + if len(i.ValueNotIn) > 0 { + predicates = append(predicates, todo.ValueNotIn(i.ValueNotIn...)) + } + if i.ValueGT != nil { + predicates = append(predicates, todo.ValueGT(*i.ValueGT)) + } + if i.ValueGTE != nil { + predicates = append(predicates, todo.ValueGTE(*i.ValueGTE)) + } + if i.ValueLT != nil { + predicates = append(predicates, todo.ValueLT(*i.ValueLT)) + } + if i.ValueLTE != nil { + predicates = append(predicates, todo.ValueLTE(*i.ValueLTE)) + } if i.HasParent != nil { p := todo.HasParent() diff --git a/entgql/internal/todo/ent/migrate/schema.go b/entgql/internal/todo/ent/migrate/schema.go index d5a611113..683b904f3 100644 --- a/entgql/internal/todo/ent/migrate/schema.go +++ b/entgql/internal/todo/ent/migrate/schema.go @@ -139,6 +139,7 @@ var ( {Name: "init", Type: field.TypeJSON, Nullable: true}, {Name: "custom", Type: field.TypeJSON, Nullable: true}, {Name: "customp", Type: field.TypeJSON, Nullable: true}, + {Name: "value", Type: field.TypeInt, Default: 0}, {Name: "category_id", Type: field.TypeInt, Nullable: true}, {Name: "project_todos", Type: field.TypeInt, Nullable: true}, {Name: "todo_children", Type: field.TypeInt, Nullable: true}, @@ -152,25 +153,25 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "todos_categories_todos", - Columns: []*schema.Column{TodosColumns[9]}, + Columns: []*schema.Column{TodosColumns[10]}, RefColumns: []*schema.Column{CategoriesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_projects_todos", - Columns: []*schema.Column{TodosColumns[10]}, + Columns: []*schema.Column{TodosColumns[11]}, RefColumns: []*schema.Column{ProjectsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_todos_children", - Columns: []*schema.Column{TodosColumns[11]}, + Columns: []*schema.Column{TodosColumns[12]}, RefColumns: []*schema.Column{TodosColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_very_secrets_secret", - Columns: []*schema.Column{TodosColumns[12]}, + Columns: []*schema.Column{TodosColumns[13]}, RefColumns: []*schema.Column{VerySecretsColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/entgql/internal/todo/ent/mutation.go b/entgql/internal/todo/ent/mutation.go index 70e8290ad..563fbb10e 100644 --- a/entgql/internal/todo/ent/mutation.go +++ b/entgql/internal/todo/ent/mutation.go @@ -3497,6 +3497,8 @@ type TodoMutation struct { appendcustom []customstruct.Custom customp *[]*customstruct.Custom appendcustomp []*customstruct.Custom + value *int + addvalue *int clearedFields map[string]struct{} parent *int clearedparent bool @@ -4051,6 +4053,62 @@ func (m *TodoMutation) ResetCustomp() { delete(m.clearedFields, todo.FieldCustomp) } +// SetValue sets the "value" field. +func (m *TodoMutation) SetValue(i int) { + m.value = &i + m.addvalue = nil +} + +// Value returns the value of the "value" field in the mutation. +func (m *TodoMutation) Value() (r int, exists bool) { + v := m.value + if v == nil { + return + } + return *v, true +} + +// OldValue returns the old "value" field's value of the Todo entity. +// If the Todo 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 *TodoMutation) OldValue(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldValue is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldValue requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldValue: %w", err) + } + return oldValue.Value, nil +} + +// AddValue adds i to the "value" field. +func (m *TodoMutation) AddValue(i int) { + if m.addvalue != nil { + *m.addvalue += i + } else { + m.addvalue = &i + } +} + +// AddedValue returns the value that was added to the "value" field in this mutation. +func (m *TodoMutation) AddedValue() (r int, exists bool) { + v := m.addvalue + if v == nil { + return + } + return *v, true +} + +// ResetValue resets all changes to the "value" field. +func (m *TodoMutation) ResetValue() { + m.value = nil + m.addvalue = nil +} + // SetParentID sets the "parent" edge to the Todo entity by id. func (m *TodoMutation) SetParentID(id int) { m.parent = &id @@ -4244,7 +4302,7 @@ func (m *TodoMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *TodoMutation) Fields() []string { - fields := make([]string, 0, 9) + fields := make([]string, 0, 10) if m.created_at != nil { fields = append(fields, todo.FieldCreatedAt) } @@ -4272,6 +4330,9 @@ func (m *TodoMutation) Fields() []string { if m.customp != nil { fields = append(fields, todo.FieldCustomp) } + if m.value != nil { + fields = append(fields, todo.FieldValue) + } return fields } @@ -4298,6 +4359,8 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) { return m.Custom() case todo.FieldCustomp: return m.Customp() + case todo.FieldValue: + return m.Value() } return nil, false } @@ -4325,6 +4388,8 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldCustom(ctx) case todo.FieldCustomp: return m.OldCustomp(ctx) + case todo.FieldValue: + return m.OldValue(ctx) } return nil, fmt.Errorf("unknown Todo field %s", name) } @@ -4397,6 +4462,13 @@ func (m *TodoMutation) SetField(name string, value ent.Value) error { } m.SetCustomp(v) return nil + case todo.FieldValue: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetValue(v) + return nil } return fmt.Errorf("unknown Todo field %s", name) } @@ -4408,6 +4480,9 @@ func (m *TodoMutation) AddedFields() []string { if m.addpriority != nil { fields = append(fields, todo.FieldPriority) } + if m.addvalue != nil { + fields = append(fields, todo.FieldValue) + } return fields } @@ -4418,6 +4493,8 @@ func (m *TodoMutation) AddedField(name string) (ent.Value, bool) { switch name { case todo.FieldPriority: return m.AddedPriority() + case todo.FieldValue: + return m.AddedValue() } return nil, false } @@ -4434,6 +4511,13 @@ func (m *TodoMutation) AddField(name string, value ent.Value) error { } m.AddPriority(v) return nil + case todo.FieldValue: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddValue(v) + return nil } return fmt.Errorf("unknown Todo numeric field %s", name) } @@ -4521,6 +4605,9 @@ func (m *TodoMutation) ResetField(name string) error { case todo.FieldCustomp: m.ResetCustomp() return nil + case todo.FieldValue: + m.ResetValue() + return nil } return fmt.Errorf("unknown Todo field %s", name) } diff --git a/entgql/internal/todo/ent/runtime.go b/entgql/internal/todo/ent/runtime.go index d936fe4d5..19e24fe28 100644 --- a/entgql/internal/todo/ent/runtime.go +++ b/entgql/internal/todo/ent/runtime.go @@ -71,6 +71,10 @@ func init() { todoDescText := todoFields[3].Descriptor() // todo.TextValidator is a validator for the "text" field. It is called by the builders before save. todo.TextValidator = todoDescText.Validators[0].(func(string) error) + // todoDescValue is the schema descriptor for value field. + todoDescValue := todoFields[9].Descriptor() + // todo.DefaultValue holds the default value on creation for the value field. + todo.DefaultValue = todoDescValue.Default.(int) userFields := schema.User{}.Fields() _ = userFields // userDescName is the schema descriptor for name field. diff --git a/entgql/internal/todo/ent/schema/todo.go b/entgql/internal/todo/ent/schema/todo.go index b77a7de97..a0c6bca71 100644 --- a/entgql/internal/todo/ent/schema/todo.go +++ b/entgql/internal/todo/ent/schema/todo.go @@ -86,6 +86,8 @@ func (Todo) Fields() []ent.Field { entgql.Skip(entgql.SkipMutationUpdateInput), ). Optional(), + field.Int("value"). + Default(0), } } diff --git a/entgql/internal/todo/ent/todo.go b/entgql/internal/todo/ent/todo.go index 890c15543..fe352ab24 100644 --- a/entgql/internal/todo/ent/todo.go +++ b/entgql/internal/todo/ent/todo.go @@ -53,6 +53,8 @@ type Todo struct { Custom []customstruct.Custom `json:"custom,omitempty"` // Customp holds the value of the "customp" field. Customp []*customstruct.Custom `json:"customp,omitempty"` + // Value holds the value of the "value" field. + Value int `json:"value,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the TodoQuery when eager-loading is set. Edges TodoEdges `json:"edges"` @@ -130,7 +132,7 @@ func (*Todo) scanValues(columns []string) ([]any, error) { switch columns[i] { case todo.FieldBlob, todo.FieldInit, todo.FieldCustom, todo.FieldCustomp: values[i] = new([]byte) - case todo.FieldID, todo.FieldPriority, todo.FieldCategoryID: + case todo.FieldID, todo.FieldPriority, todo.FieldCategoryID, todo.FieldValue: values[i] = new(sql.NullInt64) case todo.FieldStatus, todo.FieldText: values[i] = new(sql.NullString) @@ -223,6 +225,12 @@ func (t *Todo) assignValues(columns []string, values []any) error { return fmt.Errorf("unmarshal field customp: %w", err) } } + case todo.FieldValue: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field value", values[i]) + } else if value.Valid { + t.Value = int(value.Int64) + } case todo.ForeignKeys[0]: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field project_todos", value) @@ -251,9 +259,9 @@ func (t *Todo) assignValues(columns []string, values []any) error { return nil } -// Value returns the ent.Value that was dynamically selected and assigned to the Todo. +// GetValue returns the ent.Value that was dynamically selected and assigned to the Todo. // This includes values selected through modifiers, order, etc. -func (t *Todo) Value(name string) (ent.Value, error) { +func (t *Todo) GetValue(name string) (ent.Value, error) { return t.selectValues.Get(name) } @@ -326,6 +334,9 @@ func (t *Todo) String() string { builder.WriteString(", ") builder.WriteString("customp=") builder.WriteString(fmt.Sprintf("%v", t.Customp)) + builder.WriteString(", ") + builder.WriteString("value=") + builder.WriteString(fmt.Sprintf("%v", t.Value)) builder.WriteByte(')') return builder.String() } diff --git a/entgql/internal/todo/ent/todo/todo.go b/entgql/internal/todo/ent/todo/todo.go index 417014489..e386089d8 100644 --- a/entgql/internal/todo/ent/todo/todo.go +++ b/entgql/internal/todo/ent/todo/todo.go @@ -49,6 +49,8 @@ const ( FieldCustom = "custom" // FieldCustomp holds the string denoting the customp field in the database. FieldCustomp = "customp" + // FieldValue holds the string denoting the value field in the database. + FieldValue = "value" // EdgeParent holds the string denoting the parent edge name in mutations. EdgeParent = "parent" // EdgeChildren holds the string denoting the children edge name in mutations. @@ -95,6 +97,7 @@ var Columns = []string{ FieldInit, FieldCustom, FieldCustomp, + FieldValue, } // ForeignKeys holds the SQL foreign-keys that are owned by the "todos" @@ -127,6 +130,8 @@ var ( DefaultPriority int // TextValidator is a validator for the "text" field. It is called by the builders before save. TextValidator func(string) error + // DefaultValue holds the default value on creation for the "value" field. + DefaultValue int ) // Status defines the type for the "status" enum field. @@ -186,6 +191,11 @@ func ByCategoryID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCategoryID, opts...).ToFunc() } +// ByValue orders the results by the value field. +func ByValue(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldValue, opts...).ToFunc() +} + // ByParentField orders the results by parent field. func ByParentField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { diff --git a/entgql/internal/todo/ent/todo/where.go b/entgql/internal/todo/ent/todo/where.go index 70eba5527..e878e1ebf 100644 --- a/entgql/internal/todo/ent/todo/where.go +++ b/entgql/internal/todo/ent/todo/where.go @@ -94,6 +94,11 @@ func CategoryID(v int) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldCategoryID, v)) } +// Value applies equality check predicate on the "value" field. It's identical to ValueEQ. +func Value(v int) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldValue, v)) +} + // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldCreatedAt, v)) @@ -369,6 +374,46 @@ func CustompNotNil() predicate.Todo { return predicate.Todo(sql.FieldNotNull(FieldCustomp)) } +// ValueEQ applies the EQ predicate on the "value" field. +func ValueEQ(v int) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldValue, v)) +} + +// ValueNEQ applies the NEQ predicate on the "value" field. +func ValueNEQ(v int) predicate.Todo { + return predicate.Todo(sql.FieldNEQ(FieldValue, v)) +} + +// ValueIn applies the In predicate on the "value" field. +func ValueIn(vs ...int) predicate.Todo { + return predicate.Todo(sql.FieldIn(FieldValue, vs...)) +} + +// ValueNotIn applies the NotIn predicate on the "value" field. +func ValueNotIn(vs ...int) predicate.Todo { + return predicate.Todo(sql.FieldNotIn(FieldValue, vs...)) +} + +// ValueGT applies the GT predicate on the "value" field. +func ValueGT(v int) predicate.Todo { + return predicate.Todo(sql.FieldGT(FieldValue, v)) +} + +// ValueGTE applies the GTE predicate on the "value" field. +func ValueGTE(v int) predicate.Todo { + return predicate.Todo(sql.FieldGTE(FieldValue, v)) +} + +// ValueLT applies the LT predicate on the "value" field. +func ValueLT(v int) predicate.Todo { + return predicate.Todo(sql.FieldLT(FieldValue, v)) +} + +// ValueLTE applies the LTE predicate on the "value" field. +func ValueLTE(v int) predicate.Todo { + return predicate.Todo(sql.FieldLTE(FieldValue, v)) +} + // HasParent applies the HasEdge predicate on the "parent" edge. func HasParent() predicate.Todo { return predicate.Todo(func(s *sql.Selector) { diff --git a/entgql/internal/todo/ent/todo_create.go b/entgql/internal/todo/ent/todo_create.go index 8486dbe26..786717818 100644 --- a/entgql/internal/todo/ent/todo_create.go +++ b/entgql/internal/todo/ent/todo_create.go @@ -115,6 +115,20 @@ func (tc *TodoCreate) SetCustomp(c []*customstruct.Custom) *TodoCreate { return tc } +// SetValue sets the "value" field. +func (tc *TodoCreate) SetValue(i int) *TodoCreate { + tc.mutation.SetValue(i) + return tc +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tc *TodoCreate) SetNillableValue(i *int) *TodoCreate { + if i != nil { + tc.SetValue(*i) + } + return tc +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tc *TodoCreate) SetParentID(id int) *TodoCreate { tc.mutation.SetParentID(id) @@ -216,6 +230,10 @@ func (tc *TodoCreate) defaults() { v := todo.DefaultPriority tc.mutation.SetPriority(v) } + if _, ok := tc.mutation.Value(); !ok { + v := todo.DefaultValue + tc.mutation.SetValue(v) + } } // check runs all checks and user-defined validators on the builder. @@ -242,6 +260,9 @@ func (tc *TodoCreate) check() error { return &ValidationError{Name: "text", err: fmt.Errorf(`ent: validator failed for field "Todo.text": %w`, err)} } } + if _, ok := tc.mutation.Value(); !ok { + return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Todo.value"`)} + } return nil } @@ -300,6 +321,10 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { _spec.SetField(todo.FieldCustomp, field.TypeJSON, value) _node.Customp = value } + if value, ok := tc.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + _node.Value = value + } if nodes := tc.mutation.ParentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entgql/internal/todo/ent/todo_update.go b/entgql/internal/todo/ent/todo_update.go index c1dacd8c0..2af0849af 100644 --- a/entgql/internal/todo/ent/todo_update.go +++ b/entgql/internal/todo/ent/todo_update.go @@ -154,6 +154,27 @@ func (tu *TodoUpdate) ClearCustomp() *TodoUpdate { return tu } +// SetValue sets the "value" field. +func (tu *TodoUpdate) SetValue(i int) *TodoUpdate { + tu.mutation.ResetValue() + tu.mutation.SetValue(i) + return tu +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableValue(i *int) *TodoUpdate { + if i != nil { + tu.SetValue(*i) + } + return tu +} + +// AddValue adds i to the "value" field. +func (tu *TodoUpdate) AddValue(i int) *TodoUpdate { + tu.mutation.AddValue(i) + return tu +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tu *TodoUpdate) SetParentID(id int) *TodoUpdate { tu.mutation.SetParentID(id) @@ -351,6 +372,12 @@ func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) { if tu.mutation.CustompCleared() { _spec.ClearField(todo.FieldCustomp, field.TypeJSON) } + if value, ok := tu.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + } + if value, ok := tu.mutation.AddedValue(); ok { + _spec.AddField(todo.FieldValue, field.TypeInt, value) + } if tu.mutation.ParentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -585,6 +612,27 @@ func (tuo *TodoUpdateOne) ClearCustomp() *TodoUpdateOne { return tuo } +// SetValue sets the "value" field. +func (tuo *TodoUpdateOne) SetValue(i int) *TodoUpdateOne { + tuo.mutation.ResetValue() + tuo.mutation.SetValue(i) + return tuo +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableValue(i *int) *TodoUpdateOne { + if i != nil { + tuo.SetValue(*i) + } + return tuo +} + +// AddValue adds i to the "value" field. +func (tuo *TodoUpdateOne) AddValue(i int) *TodoUpdateOne { + tuo.mutation.AddValue(i) + return tuo +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tuo *TodoUpdateOne) SetParentID(id int) *TodoUpdateOne { tuo.mutation.SetParentID(id) @@ -812,6 +860,12 @@ func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) if tuo.mutation.CustompCleared() { _spec.ClearField(todo.FieldCustomp, field.TypeJSON) } + if value, ok := tuo.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + } + if value, ok := tuo.mutation.AddedValue(); ok { + _spec.AddField(todo.FieldValue, field.TypeInt, value) + } if tuo.mutation.ParentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entgql/internal/todo/generated.go b/entgql/internal/todo/generated.go index 16e714989..ee50c6cf0 100644 --- a/entgql/internal/todo/generated.go +++ b/entgql/internal/todo/generated.go @@ -213,6 +213,7 @@ type ComplexityRoot struct { Priority func(childComplexity int) int Status func(childComplexity int) int Text func(childComplexity int) int + Value func(childComplexity int) int } TodoConnection struct { @@ -1002,6 +1003,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Text(childComplexity), true + case "Todo.value": + if e.complexity.Todo.Value == nil { + break + } + + return e.complexity.Todo.Value(childComplexity), true + case "TodoConnection.edges": if e.complexity.TodoConnection.Edges == nil { break @@ -4444,6 +4452,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -4531,6 +4541,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -6698,6 +6710,50 @@ func (ec *executionContext) fieldContext_Todo_customp(_ context.Context, field g return fc, nil } +func (ec *executionContext) _Todo_value(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_value(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Value, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_value(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Todo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Todo_parent(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Todo_parent(ctx, field) if err != nil { @@ -6756,6 +6812,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -7143,6 +7201,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -10609,7 +10669,7 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "parentID", "childIDs", "categoryID", "secretID"} + fieldsInOrder := [...]string{"status", "priority", "text", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -10644,6 +10704,13 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o return it, err } it.Init = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data case "parentID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parentID")) data, err := ec.unmarshalOID2ᚖint(ctx, v) @@ -11805,7 +11872,7 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "status", "statusNEQ", "statusIn", "statusNotIn", "priority", "priorityNEQ", "priorityIn", "priorityNotIn", "priorityGT", "priorityGTE", "priorityLT", "priorityLTE", "text", "textNEQ", "textIn", "textNotIn", "textGT", "textGTE", "textLT", "textLTE", "textContains", "textHasPrefix", "textHasSuffix", "textEqualFold", "textContainsFold", "categoryID", "categoryIDNEQ", "categoryIDIn", "categoryIDNotIn", "categoryIDIsNil", "categoryIDNotNil", "hasParent", "hasParentWith", "hasChildren", "hasChildrenWith", "hasCategory", "hasCategoryWith", "createdToday"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "status", "statusNEQ", "statusIn", "statusNotIn", "priority", "priorityNEQ", "priorityIn", "priorityNotIn", "priorityGT", "priorityGTE", "priorityLT", "priorityLTE", "text", "textNEQ", "textIn", "textNotIn", "textGT", "textGTE", "textLT", "textLTE", "textContains", "textHasPrefix", "textHasSuffix", "textEqualFold", "textContainsFold", "categoryID", "categoryIDNEQ", "categoryIDIn", "categoryIDNotIn", "categoryIDIsNil", "categoryIDNotNil", "value", "valueNEQ", "valueIn", "valueNotIn", "valueGT", "valueGTE", "valueLT", "valueLTE", "hasParent", "hasParentWith", "hasChildren", "hasChildrenWith", "hasCategory", "hasCategoryWith", "createdToday"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -12162,6 +12229,62 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob return it, err } it.CategoryIDNotNil = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data + case "valueNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueNEQ")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueNEQ = data + case "valueIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueIn")) + data, err := ec.unmarshalOInt2ᚕintᚄ(ctx, v) + if err != nil { + return it, err + } + it.ValueIn = data + case "valueNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueNotIn")) + data, err := ec.unmarshalOInt2ᚕintᚄ(ctx, v) + if err != nil { + return it, err + } + it.ValueNotIn = data + case "valueGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueGT")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueGT = data + case "valueGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueGTE")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueGTE = data + case "valueLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueLT")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueLT = data + case "valueLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueLTE")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueLTE = data case "hasParent": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasParent")) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) @@ -12420,7 +12543,7 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} + fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -12462,6 +12585,13 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o return it, err } it.ClearInit = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data case "parentID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parentID")) data, err := ec.unmarshalOID2ᚖint(ctx, v) @@ -14582,6 +14712,11 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = ec._Todo_custom(ctx, field, obj) case "customp": out.Values[i] = ec._Todo_customp(ctx, field, obj) + case "value": + out.Values[i] = ec._Todo_value(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } case "parent": field := field diff --git a/entgql/internal/todo/todo_test.go b/entgql/internal/todo/todo_test.go index cc21898b4..7e2136c7b 100644 --- a/entgql/internal/todo/todo_test.go +++ b/entgql/internal/todo/todo_test.go @@ -2337,7 +2337,7 @@ func TestReduceQueryComplexity(t *testing.T) { children (first: 5) { edges { node { - text + text } } } @@ -2347,7 +2347,7 @@ func TestReduceQueryComplexity(t *testing.T) { todos (first: 10) { edges { node { - text + text } } } @@ -2382,7 +2382,7 @@ func TestReduceQueryComplexity(t *testing.T) { children (first: 5) { edges { node { - text + text } } } @@ -2392,7 +2392,7 @@ func TestReduceQueryComplexity(t *testing.T) { todos (first: 10) { edges { node { - text + text } } } @@ -2582,7 +2582,7 @@ func TestFieldSelection(t *testing.T) { "SELECT `todos`.`id`, `todos`.`created_at`, `todos`.`status`, " + "`todos`.`priority`, `todos`.`text`, `todos`.`blob`, " + "`todos`.`category_id`, `todos`.`init`, `todos`.`custom`, " + - "`todos`.`customp` FROM `todos` ORDER BY `todos`.`id`", + "`todos`.`customp`, `todos`.`value` FROM `todos` ORDER BY `todos`.`id`", }, rec.queries) rootO2M := ec.OneToMany.CreateBulk( diff --git a/entgql/internal/todogotype/ent/gql_collection.go b/entgql/internal/todogotype/ent/gql_collection.go index 3f597984e..f9518f710 100644 --- a/entgql/internal/todogotype/ent/gql_collection.go +++ b/entgql/internal/todogotype/ent/gql_collection.go @@ -923,6 +923,11 @@ func (t *TodoQuery) collectField(ctx context.Context, oneNode bool, opCtx *graph selectedFields = append(selectedFields, todo.FieldCustomp) fieldSeen[todo.FieldCustomp] = struct{}{} } + case "value": + if _, ok := fieldSeen[todo.FieldValue]; !ok { + selectedFields = append(selectedFields, todo.FieldValue) + fieldSeen[todo.FieldValue] = struct{}{} + } case "categoryID": if _, ok := fieldSeen[todo.FieldCategoryID]; !ok { selectedFields = append(selectedFields, todo.FieldCategoryID) diff --git a/entgql/internal/todogotype/ent/gql_mutation_input.go b/entgql/internal/todogotype/ent/gql_mutation_input.go index 953b0324b..8e8c3bd79 100644 --- a/entgql/internal/todogotype/ent/gql_mutation_input.go +++ b/entgql/internal/todogotype/ent/gql_mutation_input.go @@ -173,6 +173,7 @@ type CreateTodoInput struct { Priority *int Text string Init map[string]interface{} + Value *int ParentID *string ChildIDs []string CategoryID *bigintgql.BigInt @@ -189,6 +190,9 @@ func (i *CreateTodoInput) Mutate(m *TodoMutation) { if v := i.Init; v != nil { m.SetInit(v) } + if v := i.Value; v != nil { + m.SetValue(*v) + } if v := i.ParentID; v != nil { m.SetParentID(*v) } @@ -216,6 +220,7 @@ type UpdateTodoInput struct { Text *string ClearInit bool Init map[string]interface{} + Value *int ClearParent bool ParentID *string ClearChildren bool @@ -242,6 +247,9 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) { if v := i.Init; v != nil { m.SetInit(v) } + if v := i.Value; v != nil { + m.SetValue(*v) + } if i.ClearParent { m.ClearParent() } diff --git a/entgql/internal/todogotype/ent/gql_pagination.go b/entgql/internal/todogotype/ent/gql_pagination.go index 0aebdc670..c2a6b8a08 100644 --- a/entgql/internal/todogotype/ent/gql_pagination.go +++ b/entgql/internal/todogotype/ent/gql_pagination.go @@ -1853,7 +1853,7 @@ var ( // TodoOrderFieldParentStatus orders by PARENT_STATUS. TodoOrderFieldParentStatus = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("parent_status") + return t.GetValue("parent_status") }, column: "parent_status", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1863,7 +1863,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("parent_status") + cv, _ := t.GetValue("parent_status") return Cursor{ ID: t.ID, Value: cv, @@ -1873,7 +1873,7 @@ var ( // TodoOrderFieldChildrenCount orders by CHILDREN_COUNT. TodoOrderFieldChildrenCount = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("children_count") + return t.GetValue("children_count") }, column: "children_count", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1882,7 +1882,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("children_count") + cv, _ := t.GetValue("children_count") return Cursor{ ID: t.ID, Value: cv, @@ -1892,7 +1892,7 @@ var ( // TodoOrderFieldCategoryText orders by CATEGORY_TEXT. TodoOrderFieldCategoryText = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("category_text") + return t.GetValue("category_text") }, column: "category_text", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1902,7 +1902,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("category_text") + cv, _ := t.GetValue("category_text") return Cursor{ ID: t.ID, Value: cv, diff --git a/entgql/internal/todogotype/ent/gql_where_input.go b/entgql/internal/todogotype/ent/gql_where_input.go index be2761a99..afc822e43 100644 --- a/entgql/internal/todogotype/ent/gql_where_input.go +++ b/entgql/internal/todogotype/ent/gql_where_input.go @@ -1438,6 +1438,16 @@ type TodoWhereInput struct { TextEqualFold *string `json:"textEqualFold,omitempty"` TextContainsFold *string `json:"textContainsFold,omitempty"` + // "value" field predicates. + Value *int `json:"value,omitempty"` + ValueNEQ *int `json:"valueNEQ,omitempty"` + ValueIn []int `json:"valueIn,omitempty"` + ValueNotIn []int `json:"valueNotIn,omitempty"` + ValueGT *int `json:"valueGT,omitempty"` + ValueGTE *int `json:"valueGTE,omitempty"` + ValueLT *int `json:"valueLT,omitempty"` + ValueLTE *int `json:"valueLTE,omitempty"` + // "category_id" field predicates. CategoryID *bigintgql.BigInt `json:"categoryID,omitempty"` CategoryIDNEQ *bigintgql.BigInt `json:"categoryIDNEQ,omitempty"` @@ -1668,6 +1678,30 @@ func (i *TodoWhereInput) P() (predicate.Todo, error) { if i.TextContainsFold != nil { predicates = append(predicates, todo.TextContainsFold(*i.TextContainsFold)) } + if i.Value != nil { + predicates = append(predicates, todo.ValueEQ(*i.Value)) + } + if i.ValueNEQ != nil { + predicates = append(predicates, todo.ValueNEQ(*i.ValueNEQ)) + } + if len(i.ValueIn) > 0 { + predicates = append(predicates, todo.ValueIn(i.ValueIn...)) + } + if len(i.ValueNotIn) > 0 { + predicates = append(predicates, todo.ValueNotIn(i.ValueNotIn...)) + } + if i.ValueGT != nil { + predicates = append(predicates, todo.ValueGT(*i.ValueGT)) + } + if i.ValueGTE != nil { + predicates = append(predicates, todo.ValueGTE(*i.ValueGTE)) + } + if i.ValueLT != nil { + predicates = append(predicates, todo.ValueLT(*i.ValueLT)) + } + if i.ValueLTE != nil { + predicates = append(predicates, todo.ValueLTE(*i.ValueLTE)) + } if i.CategoryID != nil { predicates = append(predicates, todo.CategoryIDEQ(*i.CategoryID)) } diff --git a/entgql/internal/todogotype/ent/migrate/schema.go b/entgql/internal/todogotype/ent/migrate/schema.go index 9cda0102e..5de7e7923 100644 --- a/entgql/internal/todogotype/ent/migrate/schema.go +++ b/entgql/internal/todogotype/ent/migrate/schema.go @@ -119,6 +119,7 @@ var ( {Name: "init", Type: field.TypeJSON, Nullable: true}, {Name: "custom", Type: field.TypeJSON, Nullable: true}, {Name: "customp", Type: field.TypeJSON, Nullable: true}, + {Name: "value", Type: field.TypeInt, Default: 0}, {Name: "category_id", Type: field.TypeString, Nullable: true}, {Name: "todo_children", Type: field.TypeString, Nullable: true}, {Name: "todo_secret", Type: field.TypeString, Nullable: true}, @@ -131,19 +132,19 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "todos_categories_todos", - Columns: []*schema.Column{TodosColumns[9]}, + Columns: []*schema.Column{TodosColumns[10]}, RefColumns: []*schema.Column{CategoriesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_todos_children", - Columns: []*schema.Column{TodosColumns[10]}, + Columns: []*schema.Column{TodosColumns[11]}, RefColumns: []*schema.Column{TodosColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_very_secrets_secret", - Columns: []*schema.Column{TodosColumns[11]}, + Columns: []*schema.Column{TodosColumns[12]}, RefColumns: []*schema.Column{VerySecretsColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/entgql/internal/todogotype/ent/mutation.go b/entgql/internal/todogotype/ent/mutation.go index cd6fa8b07..17b942936 100644 --- a/entgql/internal/todogotype/ent/mutation.go +++ b/entgql/internal/todogotype/ent/mutation.go @@ -2855,6 +2855,8 @@ type TodoMutation struct { appendcustom []customstruct.Custom customp *[]*customstruct.Custom appendcustomp []*customstruct.Custom + value *int + addvalue *int clearedFields map[string]struct{} parent *string clearedparent bool @@ -3366,6 +3368,62 @@ func (m *TodoMutation) ResetCustomp() { delete(m.clearedFields, todo.FieldCustomp) } +// SetValue sets the "value" field. +func (m *TodoMutation) SetValue(i int) { + m.value = &i + m.addvalue = nil +} + +// Value returns the value of the "value" field in the mutation. +func (m *TodoMutation) Value() (r int, exists bool) { + v := m.value + if v == nil { + return + } + return *v, true +} + +// OldValue returns the old "value" field's value of the Todo entity. +// If the Todo 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 *TodoMutation) OldValue(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldValue is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldValue requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldValue: %w", err) + } + return oldValue.Value, nil +} + +// AddValue adds i to the "value" field. +func (m *TodoMutation) AddValue(i int) { + if m.addvalue != nil { + *m.addvalue += i + } else { + m.addvalue = &i + } +} + +// AddedValue returns the value that was added to the "value" field in this mutation. +func (m *TodoMutation) AddedValue() (r int, exists bool) { + v := m.addvalue + if v == nil { + return + } + return *v, true +} + +// ResetValue resets all changes to the "value" field. +func (m *TodoMutation) ResetValue() { + m.value = nil + m.addvalue = nil +} + // SetCategoryID sets the "category_id" field. func (m *TodoMutation) SetCategoryID(bi bigintgql.BigInt) { m.category = &bi @@ -3608,7 +3666,7 @@ func (m *TodoMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *TodoMutation) Fields() []string { - fields := make([]string, 0, 9) + fields := make([]string, 0, 10) if m.created_at != nil { fields = append(fields, todo.FieldCreatedAt) } @@ -3633,6 +3691,9 @@ func (m *TodoMutation) Fields() []string { if m.customp != nil { fields = append(fields, todo.FieldCustomp) } + if m.value != nil { + fields = append(fields, todo.FieldValue) + } if m.category != nil { fields = append(fields, todo.FieldCategoryID) } @@ -3660,6 +3721,8 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) { return m.Custom() case todo.FieldCustomp: return m.Customp() + case todo.FieldValue: + return m.Value() case todo.FieldCategoryID: return m.CategoryID() } @@ -3687,6 +3750,8 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldCustom(ctx) case todo.FieldCustomp: return m.OldCustomp(ctx) + case todo.FieldValue: + return m.OldValue(ctx) case todo.FieldCategoryID: return m.OldCategoryID(ctx) } @@ -3754,6 +3819,13 @@ func (m *TodoMutation) SetField(name string, value ent.Value) error { } m.SetCustomp(v) return nil + case todo.FieldValue: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetValue(v) + return nil case todo.FieldCategoryID: v, ok := value.(bigintgql.BigInt) if !ok { @@ -3772,6 +3844,9 @@ func (m *TodoMutation) AddedFields() []string { if m.addpriority != nil { fields = append(fields, todo.FieldPriority) } + if m.addvalue != nil { + fields = append(fields, todo.FieldValue) + } return fields } @@ -3782,6 +3857,8 @@ func (m *TodoMutation) AddedField(name string) (ent.Value, bool) { switch name { case todo.FieldPriority: return m.AddedPriority() + case todo.FieldValue: + return m.AddedValue() } return nil, false } @@ -3798,6 +3875,13 @@ func (m *TodoMutation) AddField(name string, value ent.Value) error { } m.AddPriority(v) return nil + case todo.FieldValue: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddValue(v) + return nil } return fmt.Errorf("unknown Todo numeric field %s", name) } @@ -3882,6 +3966,9 @@ func (m *TodoMutation) ResetField(name string) error { case todo.FieldCustomp: m.ResetCustomp() return nil + case todo.FieldValue: + m.ResetValue() + return nil case todo.FieldCategoryID: m.ResetCategoryID() return nil diff --git a/entgql/internal/todogotype/ent/runtime.go b/entgql/internal/todogotype/ent/runtime.go index 1c13b90f4..231db679f 100644 --- a/entgql/internal/todogotype/ent/runtime.go +++ b/entgql/internal/todogotype/ent/runtime.go @@ -82,6 +82,10 @@ func init() { todoDescText := todoMixinFields0[3].Descriptor() // todo.TextValidator is a validator for the "text" field. It is called by the builders before save. todo.TextValidator = todoDescText.Validators[0].(func(string) error) + // todoDescValue is the schema descriptor for value field. + todoDescValue := todoMixinFields0[8].Descriptor() + // todo.DefaultValue holds the default value on creation for the value field. + todo.DefaultValue = todoDescValue.Default.(int) // todoDescID is the schema descriptor for id field. todoDescID := todoFields[0].Descriptor() // todo.DefaultID holds the default value on creation for the id field. diff --git a/entgql/internal/todogotype/ent/todo.go b/entgql/internal/todogotype/ent/todo.go index bf82d36a2..98a094666 100644 --- a/entgql/internal/todogotype/ent/todo.go +++ b/entgql/internal/todogotype/ent/todo.go @@ -52,6 +52,8 @@ type Todo struct { Custom []customstruct.Custom `json:"custom,omitempty"` // Customp holds the value of the "customp" field. Customp []*customstruct.Custom `json:"customp,omitempty"` + // Value holds the value of the "value" field. + Value int `json:"value,omitempty"` // CategoryID holds the value of the "category_id" field. CategoryID bigintgql.BigInt `json:"category_id,omitempty"` // Edges holds the relations/edges for other nodes in the graph. @@ -132,7 +134,7 @@ func (*Todo) scanValues(columns []string) ([]any, error) { values[i] = new([]byte) case todo.FieldCategoryID: values[i] = new(bigintgql.BigInt) - case todo.FieldPriority: + case todo.FieldPriority, todo.FieldValue: values[i] = new(sql.NullInt64) case todo.FieldID, todo.FieldStatus, todo.FieldText: values[i] = new(sql.NullString) @@ -217,6 +219,12 @@ func (t *Todo) assignValues(columns []string, values []any) error { return fmt.Errorf("unmarshal field customp: %w", err) } } + case todo.FieldValue: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field value", values[i]) + } else if value.Valid { + t.Value = int(value.Int64) + } case todo.FieldCategoryID: if value, ok := values[i].(*bigintgql.BigInt); !ok { return fmt.Errorf("unexpected type %T for field category_id", values[i]) @@ -244,9 +252,9 @@ func (t *Todo) assignValues(columns []string, values []any) error { return nil } -// Value returns the ent.Value that was dynamically selected and assigned to the Todo. +// GetValue returns the ent.Value that was dynamically selected and assigned to the Todo. // This includes values selected through modifiers, order, etc. -func (t *Todo) Value(name string) (ent.Value, error) { +func (t *Todo) GetValue(name string) (ent.Value, error) { return t.selectValues.Get(name) } @@ -317,6 +325,9 @@ func (t *Todo) String() string { builder.WriteString("customp=") builder.WriteString(fmt.Sprintf("%v", t.Customp)) builder.WriteString(", ") + builder.WriteString("value=") + builder.WriteString(fmt.Sprintf("%v", t.Value)) + builder.WriteString(", ") builder.WriteString("category_id=") builder.WriteString(fmt.Sprintf("%v", t.CategoryID)) builder.WriteByte(')') diff --git a/entgql/internal/todogotype/ent/todo/todo.go b/entgql/internal/todogotype/ent/todo/todo.go index ca4324fe3..856aea50c 100644 --- a/entgql/internal/todogotype/ent/todo/todo.go +++ b/entgql/internal/todogotype/ent/todo/todo.go @@ -47,6 +47,8 @@ const ( FieldCustom = "custom" // FieldCustomp holds the string denoting the customp field in the database. FieldCustomp = "customp" + // FieldValue holds the string denoting the value field in the database. + FieldValue = "value" // FieldCategoryID holds the string denoting the category_id field in the database. FieldCategoryID = "category_id" // EdgeParent holds the string denoting the parent edge name in mutations. @@ -94,6 +96,7 @@ var Columns = []string{ FieldInit, FieldCustom, FieldCustomp, + FieldValue, FieldCategoryID, } @@ -126,6 +129,8 @@ var ( DefaultPriority int // TextValidator is a validator for the "text" field. It is called by the builders before save. TextValidator func(string) error + // DefaultValue holds the default value on creation for the "value" field. + DefaultValue int // DefaultID holds the default value on creation for the "id" field. DefaultID string ) @@ -182,6 +187,11 @@ func ByText(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldText, opts...).ToFunc() } +// ByValue orders the results by the value field. +func ByValue(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldValue, opts...).ToFunc() +} + // ByCategoryID orders the results by the category_id field. func ByCategoryID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCategoryID, opts...).ToFunc() diff --git a/entgql/internal/todogotype/ent/todo/where.go b/entgql/internal/todogotype/ent/todo/where.go index d5d0f7b9a..ddb5d15ab 100644 --- a/entgql/internal/todogotype/ent/todo/where.go +++ b/entgql/internal/todogotype/ent/todo/where.go @@ -100,6 +100,11 @@ func Blob(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) } +// Value applies equality check predicate on the "value" field. It's identical to ValueEQ. +func Value(v int) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldValue, v)) +} + // CategoryID applies equality check predicate on the "category_id" field. It's identical to CategoryIDEQ. func CategoryID(v bigintgql.BigInt) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldCategoryID, v)) @@ -350,6 +355,46 @@ func CustompNotNil() predicate.Todo { return predicate.Todo(sql.FieldNotNull(FieldCustomp)) } +// ValueEQ applies the EQ predicate on the "value" field. +func ValueEQ(v int) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldValue, v)) +} + +// ValueNEQ applies the NEQ predicate on the "value" field. +func ValueNEQ(v int) predicate.Todo { + return predicate.Todo(sql.FieldNEQ(FieldValue, v)) +} + +// ValueIn applies the In predicate on the "value" field. +func ValueIn(vs ...int) predicate.Todo { + return predicate.Todo(sql.FieldIn(FieldValue, vs...)) +} + +// ValueNotIn applies the NotIn predicate on the "value" field. +func ValueNotIn(vs ...int) predicate.Todo { + return predicate.Todo(sql.FieldNotIn(FieldValue, vs...)) +} + +// ValueGT applies the GT predicate on the "value" field. +func ValueGT(v int) predicate.Todo { + return predicate.Todo(sql.FieldGT(FieldValue, v)) +} + +// ValueGTE applies the GTE predicate on the "value" field. +func ValueGTE(v int) predicate.Todo { + return predicate.Todo(sql.FieldGTE(FieldValue, v)) +} + +// ValueLT applies the LT predicate on the "value" field. +func ValueLT(v int) predicate.Todo { + return predicate.Todo(sql.FieldLT(FieldValue, v)) +} + +// ValueLTE applies the LTE predicate on the "value" field. +func ValueLTE(v int) predicate.Todo { + return predicate.Todo(sql.FieldLTE(FieldValue, v)) +} + // CategoryIDEQ applies the EQ predicate on the "category_id" field. func CategoryIDEQ(v bigintgql.BigInt) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldCategoryID, v)) diff --git a/entgql/internal/todogotype/ent/todo_create.go b/entgql/internal/todogotype/ent/todo_create.go index 3c4da28f1..8c2824bd5 100644 --- a/entgql/internal/todogotype/ent/todo_create.go +++ b/entgql/internal/todogotype/ent/todo_create.go @@ -102,6 +102,20 @@ func (tc *TodoCreate) SetCustomp(c []*customstruct.Custom) *TodoCreate { return tc } +// SetValue sets the "value" field. +func (tc *TodoCreate) SetValue(i int) *TodoCreate { + tc.mutation.SetValue(i) + return tc +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tc *TodoCreate) SetNillableValue(i *int) *TodoCreate { + if i != nil { + tc.SetValue(*i) + } + return tc +} + // SetCategoryID sets the "category_id" field. func (tc *TodoCreate) SetCategoryID(bi bigintgql.BigInt) *TodoCreate { tc.mutation.SetCategoryID(bi) @@ -231,6 +245,10 @@ func (tc *TodoCreate) defaults() { v := todo.DefaultPriority tc.mutation.SetPriority(v) } + if _, ok := tc.mutation.Value(); !ok { + v := todo.DefaultValue + tc.mutation.SetValue(v) + } if _, ok := tc.mutation.ID(); !ok { v := todo.DefaultID tc.mutation.SetID(v) @@ -261,6 +279,9 @@ func (tc *TodoCreate) check() error { return &ValidationError{Name: "text", err: fmt.Errorf(`ent: validator failed for field "Todo.text": %w`, err)} } } + if _, ok := tc.mutation.Value(); !ok { + return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Todo.value"`)} + } return nil } @@ -328,6 +349,10 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { _spec.SetField(todo.FieldCustomp, field.TypeJSON, value) _node.Customp = value } + if value, ok := tc.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + _node.Value = value + } if nodes := tc.mutation.ParentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entgql/internal/todogotype/ent/todo_update.go b/entgql/internal/todogotype/ent/todo_update.go index ac6f78363..ed65eba73 100644 --- a/entgql/internal/todogotype/ent/todo_update.go +++ b/entgql/internal/todogotype/ent/todo_update.go @@ -153,6 +153,27 @@ func (tu *TodoUpdate) ClearCustomp() *TodoUpdate { return tu } +// SetValue sets the "value" field. +func (tu *TodoUpdate) SetValue(i int) *TodoUpdate { + tu.mutation.ResetValue() + tu.mutation.SetValue(i) + return tu +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableValue(i *int) *TodoUpdate { + if i != nil { + tu.SetValue(*i) + } + return tu +} + +// AddValue adds i to the "value" field. +func (tu *TodoUpdate) AddValue(i int) *TodoUpdate { + tu.mutation.AddValue(i) + return tu +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tu *TodoUpdate) SetParentID(id string) *TodoUpdate { tu.mutation.SetParentID(id) @@ -344,6 +365,12 @@ func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) { if tu.mutation.CustompCleared() { _spec.ClearField(todo.FieldCustomp, field.TypeJSON) } + if value, ok := tu.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + } + if value, ok := tu.mutation.AddedValue(); ok { + _spec.AddField(todo.FieldValue, field.TypeInt, value) + } if tu.mutation.ParentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -576,6 +603,27 @@ func (tuo *TodoUpdateOne) ClearCustomp() *TodoUpdateOne { return tuo } +// SetValue sets the "value" field. +func (tuo *TodoUpdateOne) SetValue(i int) *TodoUpdateOne { + tuo.mutation.ResetValue() + tuo.mutation.SetValue(i) + return tuo +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableValue(i *int) *TodoUpdateOne { + if i != nil { + tuo.SetValue(*i) + } + return tuo +} + +// AddValue adds i to the "value" field. +func (tuo *TodoUpdateOne) AddValue(i int) *TodoUpdateOne { + tuo.mutation.AddValue(i) + return tuo +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tuo *TodoUpdateOne) SetParentID(id string) *TodoUpdateOne { tuo.mutation.SetParentID(id) @@ -797,6 +845,12 @@ func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) if tuo.mutation.CustompCleared() { _spec.ClearField(todo.FieldCustomp, field.TypeJSON) } + if value, ok := tuo.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + } + if value, ok := tuo.mutation.AddedValue(); ok { + _spec.AddField(todo.FieldValue, field.TypeInt, value) + } if tuo.mutation.ParentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entgql/internal/todogotype/generated.go b/entgql/internal/todogotype/generated.go index 1296acb99..50b8e9841 100644 --- a/entgql/internal/todogotype/generated.go +++ b/entgql/internal/todogotype/generated.go @@ -218,6 +218,7 @@ type ComplexityRoot struct { Priority func(childComplexity int) int Status func(childComplexity int) int Text func(childComplexity int) int + Value func(childComplexity int) int } TodoConnection struct { @@ -1048,6 +1049,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Text(childComplexity), true + case "Todo.value": + if e.complexity.Todo.Value == nil { + break + } + + return e.complexity.Todo.Value(childComplexity), true + case "TodoConnection.edges": if e.complexity.TodoConnection.Edges == nil { break @@ -1719,6 +1727,7 @@ input CreateTodoInput { priority: Int text: String! init: Map + value: Int parentID: ID childIDs: [ID!] categoryID: ID @@ -2375,6 +2384,7 @@ type Todo implements Node { init: Map custom: [Custom!] customp: [Custom] + value: Int! parent: Todo children( """ @@ -2546,6 +2556,17 @@ input TodoWhereInput { categoryIDIsNil: Boolean categoryIDNotNil: Boolean """ + value field predicates + """ + value: Int + valueNEQ: Int + valueIn: [Int!] + valueNotIn: [Int!] + valueGT: Int + valueGTE: Int + valueLT: Int + valueLTE: Int + """ parent edge predicates """ hasParent: Boolean @@ -2609,6 +2630,7 @@ input UpdateTodoInput { text: String init: Map clearInit: Boolean + value: Int parentID: ID clearParent: Boolean addChildIDs: [ID!] @@ -5999,6 +6021,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -6086,6 +6110,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -8253,6 +8279,50 @@ func (ec *executionContext) fieldContext_Todo_customp(_ context.Context, field g return fc, nil } +func (ec *executionContext) _Todo_value(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_value(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Value, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_value(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Todo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Todo_parent(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Todo_parent(ctx, field) if err != nil { @@ -8311,6 +8381,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -8698,6 +8770,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -12166,7 +12240,7 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "parentID", "childIDs", "categoryID", "secretID"} + fieldsInOrder := [...]string{"status", "priority", "text", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -12203,6 +12277,13 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o return it, err } it.Init = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data case "parentID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parentID")) data, err := ec.unmarshalOID2ᚖstring(ctx, v) @@ -13364,7 +13445,7 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "status", "statusNEQ", "statusIn", "statusNotIn", "priority", "priorityNEQ", "priorityIn", "priorityNotIn", "priorityGT", "priorityGTE", "priorityLT", "priorityLTE", "text", "textNEQ", "textIn", "textNotIn", "textGT", "textGTE", "textLT", "textLTE", "textContains", "textHasPrefix", "textHasSuffix", "textEqualFold", "textContainsFold", "categoryID", "categoryIDNEQ", "categoryIDIn", "categoryIDNotIn", "categoryIDIsNil", "categoryIDNotNil", "hasParent", "hasParentWith", "hasChildren", "hasChildrenWith", "hasCategory", "hasCategoryWith", "createdToday"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "status", "statusNEQ", "statusIn", "statusNotIn", "priority", "priorityNEQ", "priorityIn", "priorityNotIn", "priorityGT", "priorityGTE", "priorityLT", "priorityLTE", "text", "textNEQ", "textIn", "textNotIn", "textGT", "textGTE", "textLT", "textLTE", "textContains", "textHasPrefix", "textHasSuffix", "textEqualFold", "textContainsFold", "categoryID", "categoryIDNEQ", "categoryIDIn", "categoryIDNotIn", "categoryIDIsNil", "categoryIDNotNil", "value", "valueNEQ", "valueIn", "valueNotIn", "valueGT", "valueGTE", "valueLT", "valueLTE", "hasParent", "hasParentWith", "hasChildren", "hasChildrenWith", "hasCategory", "hasCategoryWith", "createdToday"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -13729,6 +13810,62 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob return it, err } it.CategoryIDNotNil = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data + case "valueNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueNEQ")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueNEQ = data + case "valueIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueIn")) + data, err := ec.unmarshalOInt2ᚕintᚄ(ctx, v) + if err != nil { + return it, err + } + it.ValueIn = data + case "valueNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueNotIn")) + data, err := ec.unmarshalOInt2ᚕintᚄ(ctx, v) + if err != nil { + return it, err + } + it.ValueNotIn = data + case "valueGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueGT")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueGT = data + case "valueGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueGTE")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueGTE = data + case "valueLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueLT")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueLT = data + case "valueLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueLTE")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueLTE = data case "hasParent": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasParent")) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) @@ -13989,7 +14126,7 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} + fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -14033,6 +14170,13 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o return it, err } it.ClearInit = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data case "parentID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parentID")) data, err := ec.unmarshalOID2ᚖstring(ctx, v) @@ -16173,6 +16317,11 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = ec._Todo_custom(ctx, field, obj) case "customp": out.Values[i] = ec._Todo_customp(ctx, field, obj) + case "value": + out.Values[i] = ec._Todo_value(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } case "parent": field := field diff --git a/entgql/internal/todopulid/ent/gql_collection.go b/entgql/internal/todopulid/ent/gql_collection.go index 9209b9cad..37687b177 100644 --- a/entgql/internal/todopulid/ent/gql_collection.go +++ b/entgql/internal/todopulid/ent/gql_collection.go @@ -855,6 +855,11 @@ func (t *TodoQuery) collectField(ctx context.Context, oneNode bool, opCtx *graph selectedFields = append(selectedFields, todo.FieldCustomp) fieldSeen[todo.FieldCustomp] = struct{}{} } + case "value": + if _, ok := fieldSeen[todo.FieldValue]; !ok { + selectedFields = append(selectedFields, todo.FieldValue) + fieldSeen[todo.FieldValue] = struct{}{} + } case "categoryID": if _, ok := fieldSeen[todo.FieldCategoryID]; !ok { selectedFields = append(selectedFields, todo.FieldCategoryID) diff --git a/entgql/internal/todopulid/ent/gql_mutation_input.go b/entgql/internal/todopulid/ent/gql_mutation_input.go index b7a86e8be..d474c7794 100644 --- a/entgql/internal/todopulid/ent/gql_mutation_input.go +++ b/entgql/internal/todopulid/ent/gql_mutation_input.go @@ -174,6 +174,7 @@ type CreateTodoInput struct { Priority *int Text string Init map[string]interface{} + Value *int ParentID *pulid.ID ChildIDs []pulid.ID CategoryID *pulid.ID @@ -190,6 +191,9 @@ func (i *CreateTodoInput) Mutate(m *TodoMutation) { if v := i.Init; v != nil { m.SetInit(v) } + if v := i.Value; v != nil { + m.SetValue(*v) + } if v := i.ParentID; v != nil { m.SetParentID(*v) } @@ -217,6 +221,7 @@ type UpdateTodoInput struct { Text *string ClearInit bool Init map[string]interface{} + Value *int ClearParent bool ParentID *pulid.ID ClearChildren bool @@ -243,6 +248,9 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) { if v := i.Init; v != nil { m.SetInit(v) } + if v := i.Value; v != nil { + m.SetValue(*v) + } if i.ClearParent { m.ClearParent() } diff --git a/entgql/internal/todopulid/ent/gql_pagination.go b/entgql/internal/todopulid/ent/gql_pagination.go index 1455f3a82..287718f9f 100644 --- a/entgql/internal/todopulid/ent/gql_pagination.go +++ b/entgql/internal/todopulid/ent/gql_pagination.go @@ -1640,7 +1640,7 @@ var ( // TodoOrderFieldParentStatus orders by PARENT_STATUS. TodoOrderFieldParentStatus = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("parent_status") + return t.GetValue("parent_status") }, column: "parent_status", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1650,7 +1650,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("parent_status") + cv, _ := t.GetValue("parent_status") return Cursor{ ID: t.ID, Value: cv, @@ -1660,7 +1660,7 @@ var ( // TodoOrderFieldChildrenCount orders by CHILDREN_COUNT. TodoOrderFieldChildrenCount = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("children_count") + return t.GetValue("children_count") }, column: "children_count", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1669,7 +1669,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("children_count") + cv, _ := t.GetValue("children_count") return Cursor{ ID: t.ID, Value: cv, @@ -1679,7 +1679,7 @@ var ( // TodoOrderFieldCategoryText orders by CATEGORY_TEXT. TodoOrderFieldCategoryText = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("category_text") + return t.GetValue("category_text") }, column: "category_text", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1689,7 +1689,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("category_text") + cv, _ := t.GetValue("category_text") return Cursor{ ID: t.ID, Value: cv, diff --git a/entgql/internal/todopulid/ent/gql_where_input.go b/entgql/internal/todopulid/ent/gql_where_input.go index bd31207f3..f366294c5 100644 --- a/entgql/internal/todopulid/ent/gql_where_input.go +++ b/entgql/internal/todopulid/ent/gql_where_input.go @@ -1233,6 +1233,16 @@ type TodoWhereInput struct { TextEqualFold *string `json:"textEqualFold,omitempty"` TextContainsFold *string `json:"textContainsFold,omitempty"` + // "value" field predicates. + Value *int `json:"value,omitempty"` + ValueNEQ *int `json:"valueNEQ,omitempty"` + ValueIn []int `json:"valueIn,omitempty"` + ValueNotIn []int `json:"valueNotIn,omitempty"` + ValueGT *int `json:"valueGT,omitempty"` + ValueGTE *int `json:"valueGTE,omitempty"` + ValueLT *int `json:"valueLT,omitempty"` + ValueLTE *int `json:"valueLTE,omitempty"` + // "category_id" field predicates. CategoryID *pulid.ID `json:"categoryID,omitempty"` CategoryIDNEQ *pulid.ID `json:"categoryIDNEQ,omitempty"` @@ -1457,6 +1467,30 @@ func (i *TodoWhereInput) P() (predicate.Todo, error) { if i.TextContainsFold != nil { predicates = append(predicates, todo.TextContainsFold(*i.TextContainsFold)) } + if i.Value != nil { + predicates = append(predicates, todo.ValueEQ(*i.Value)) + } + if i.ValueNEQ != nil { + predicates = append(predicates, todo.ValueNEQ(*i.ValueNEQ)) + } + if len(i.ValueIn) > 0 { + predicates = append(predicates, todo.ValueIn(i.ValueIn...)) + } + if len(i.ValueNotIn) > 0 { + predicates = append(predicates, todo.ValueNotIn(i.ValueNotIn...)) + } + if i.ValueGT != nil { + predicates = append(predicates, todo.ValueGT(*i.ValueGT)) + } + if i.ValueGTE != nil { + predicates = append(predicates, todo.ValueGTE(*i.ValueGTE)) + } + if i.ValueLT != nil { + predicates = append(predicates, todo.ValueLT(*i.ValueLT)) + } + if i.ValueLTE != nil { + predicates = append(predicates, todo.ValueLTE(*i.ValueLTE)) + } if i.CategoryID != nil { predicates = append(predicates, todo.CategoryIDEQ(*i.CategoryID)) } diff --git a/entgql/internal/todopulid/ent/migrate/schema.go b/entgql/internal/todopulid/ent/migrate/schema.go index 61ba9b39c..32833b914 100644 --- a/entgql/internal/todopulid/ent/migrate/schema.go +++ b/entgql/internal/todopulid/ent/migrate/schema.go @@ -108,6 +108,7 @@ var ( {Name: "init", Type: field.TypeJSON, Nullable: true}, {Name: "custom", Type: field.TypeJSON, Nullable: true}, {Name: "customp", Type: field.TypeJSON, Nullable: true}, + {Name: "value", Type: field.TypeInt, Default: 0}, {Name: "category_id", Type: field.TypeString, Nullable: true}, {Name: "todo_children", Type: field.TypeString, Nullable: true}, {Name: "todo_secret", Type: field.TypeString, Nullable: true}, @@ -120,19 +121,19 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "todos_categories_todos", - Columns: []*schema.Column{TodosColumns[9]}, + Columns: []*schema.Column{TodosColumns[10]}, RefColumns: []*schema.Column{CategoriesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_todos_children", - Columns: []*schema.Column{TodosColumns[10]}, + Columns: []*schema.Column{TodosColumns[11]}, RefColumns: []*schema.Column{TodosColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_very_secrets_secret", - Columns: []*schema.Column{TodosColumns[11]}, + Columns: []*schema.Column{TodosColumns[12]}, RefColumns: []*schema.Column{VerySecretsColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/entgql/internal/todopulid/ent/mutation.go b/entgql/internal/todopulid/ent/mutation.go index 5989c6ff2..59896fbbf 100644 --- a/entgql/internal/todopulid/ent/mutation.go +++ b/entgql/internal/todopulid/ent/mutation.go @@ -2533,6 +2533,8 @@ type TodoMutation struct { appendcustom []customstruct.Custom customp *[]*customstruct.Custom appendcustomp []*customstruct.Custom + value *int + addvalue *int clearedFields map[string]struct{} parent *pulid.ID clearedparent bool @@ -3044,6 +3046,62 @@ func (m *TodoMutation) ResetCustomp() { delete(m.clearedFields, todo.FieldCustomp) } +// SetValue sets the "value" field. +func (m *TodoMutation) SetValue(i int) { + m.value = &i + m.addvalue = nil +} + +// Value returns the value of the "value" field in the mutation. +func (m *TodoMutation) Value() (r int, exists bool) { + v := m.value + if v == nil { + return + } + return *v, true +} + +// OldValue returns the old "value" field's value of the Todo entity. +// If the Todo 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 *TodoMutation) OldValue(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldValue is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldValue requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldValue: %w", err) + } + return oldValue.Value, nil +} + +// AddValue adds i to the "value" field. +func (m *TodoMutation) AddValue(i int) { + if m.addvalue != nil { + *m.addvalue += i + } else { + m.addvalue = &i + } +} + +// AddedValue returns the value that was added to the "value" field in this mutation. +func (m *TodoMutation) AddedValue() (r int, exists bool) { + v := m.addvalue + if v == nil { + return + } + return *v, true +} + +// ResetValue resets all changes to the "value" field. +func (m *TodoMutation) ResetValue() { + m.value = nil + m.addvalue = nil +} + // SetCategoryID sets the "category_id" field. func (m *TodoMutation) SetCategoryID(pu pulid.ID) { m.category = &pu @@ -3286,7 +3344,7 @@ func (m *TodoMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *TodoMutation) Fields() []string { - fields := make([]string, 0, 9) + fields := make([]string, 0, 10) if m.created_at != nil { fields = append(fields, todo.FieldCreatedAt) } @@ -3311,6 +3369,9 @@ func (m *TodoMutation) Fields() []string { if m.customp != nil { fields = append(fields, todo.FieldCustomp) } + if m.value != nil { + fields = append(fields, todo.FieldValue) + } if m.category != nil { fields = append(fields, todo.FieldCategoryID) } @@ -3338,6 +3399,8 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) { return m.Custom() case todo.FieldCustomp: return m.Customp() + case todo.FieldValue: + return m.Value() case todo.FieldCategoryID: return m.CategoryID() } @@ -3365,6 +3428,8 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldCustom(ctx) case todo.FieldCustomp: return m.OldCustomp(ctx) + case todo.FieldValue: + return m.OldValue(ctx) case todo.FieldCategoryID: return m.OldCategoryID(ctx) } @@ -3432,6 +3497,13 @@ func (m *TodoMutation) SetField(name string, value ent.Value) error { } m.SetCustomp(v) return nil + case todo.FieldValue: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetValue(v) + return nil case todo.FieldCategoryID: v, ok := value.(pulid.ID) if !ok { @@ -3450,6 +3522,9 @@ func (m *TodoMutation) AddedFields() []string { if m.addpriority != nil { fields = append(fields, todo.FieldPriority) } + if m.addvalue != nil { + fields = append(fields, todo.FieldValue) + } return fields } @@ -3460,6 +3535,8 @@ func (m *TodoMutation) AddedField(name string) (ent.Value, bool) { switch name { case todo.FieldPriority: return m.AddedPriority() + case todo.FieldValue: + return m.AddedValue() } return nil, false } @@ -3476,6 +3553,13 @@ func (m *TodoMutation) AddField(name string, value ent.Value) error { } m.AddPriority(v) return nil + case todo.FieldValue: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddValue(v) + return nil } return fmt.Errorf("unknown Todo numeric field %s", name) } @@ -3560,6 +3644,9 @@ func (m *TodoMutation) ResetField(name string) error { case todo.FieldCustomp: m.ResetCustomp() return nil + case todo.FieldValue: + m.ResetValue() + return nil case todo.FieldCategoryID: m.ResetCategoryID() return nil diff --git a/entgql/internal/todopulid/ent/runtime.go b/entgql/internal/todopulid/ent/runtime.go index 13d1e9366..cbef20a08 100644 --- a/entgql/internal/todopulid/ent/runtime.go +++ b/entgql/internal/todopulid/ent/runtime.go @@ -106,6 +106,10 @@ func init() { todoDescText := todoMixinFields1[3].Descriptor() // todo.TextValidator is a validator for the "text" field. It is called by the builders before save. todo.TextValidator = todoDescText.Validators[0].(func(string) error) + // todoDescValue is the schema descriptor for value field. + todoDescValue := todoMixinFields1[8].Descriptor() + // todo.DefaultValue holds the default value on creation for the value field. + todo.DefaultValue = todoDescValue.Default.(int) // todoDescID is the schema descriptor for id field. todoDescID := todoMixinFields0[0].Descriptor() // todo.DefaultID holds the default value on creation for the id field. diff --git a/entgql/internal/todopulid/ent/todo.go b/entgql/internal/todopulid/ent/todo.go index a34496884..eba0749a5 100644 --- a/entgql/internal/todopulid/ent/todo.go +++ b/entgql/internal/todopulid/ent/todo.go @@ -52,6 +52,8 @@ type Todo struct { Custom []customstruct.Custom `json:"custom,omitempty"` // Customp holds the value of the "customp" field. Customp []*customstruct.Custom `json:"customp,omitempty"` + // Value holds the value of the "value" field. + Value int `json:"value,omitempty"` // CategoryID holds the value of the "category_id" field. CategoryID pulid.ID `json:"category_id,omitempty"` // Edges holds the relations/edges for other nodes in the graph. @@ -132,7 +134,7 @@ func (*Todo) scanValues(columns []string) ([]any, error) { values[i] = new([]byte) case todo.FieldID, todo.FieldCategoryID: values[i] = new(pulid.ID) - case todo.FieldPriority: + case todo.FieldPriority, todo.FieldValue: values[i] = new(sql.NullInt64) case todo.FieldStatus, todo.FieldText: values[i] = new(sql.NullString) @@ -217,6 +219,12 @@ func (t *Todo) assignValues(columns []string, values []any) error { return fmt.Errorf("unmarshal field customp: %w", err) } } + case todo.FieldValue: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field value", values[i]) + } else if value.Valid { + t.Value = int(value.Int64) + } case todo.FieldCategoryID: if value, ok := values[i].(*pulid.ID); !ok { return fmt.Errorf("unexpected type %T for field category_id", values[i]) @@ -244,9 +252,9 @@ func (t *Todo) assignValues(columns []string, values []any) error { return nil } -// Value returns the ent.Value that was dynamically selected and assigned to the Todo. +// GetValue returns the ent.Value that was dynamically selected and assigned to the Todo. // This includes values selected through modifiers, order, etc. -func (t *Todo) Value(name string) (ent.Value, error) { +func (t *Todo) GetValue(name string) (ent.Value, error) { return t.selectValues.Get(name) } @@ -317,6 +325,9 @@ func (t *Todo) String() string { builder.WriteString("customp=") builder.WriteString(fmt.Sprintf("%v", t.Customp)) builder.WriteString(", ") + builder.WriteString("value=") + builder.WriteString(fmt.Sprintf("%v", t.Value)) + builder.WriteString(", ") builder.WriteString("category_id=") builder.WriteString(fmt.Sprintf("%v", t.CategoryID)) builder.WriteByte(')') diff --git a/entgql/internal/todopulid/ent/todo/todo.go b/entgql/internal/todopulid/ent/todo/todo.go index c88c0217f..b13c53431 100644 --- a/entgql/internal/todopulid/ent/todo/todo.go +++ b/entgql/internal/todopulid/ent/todo/todo.go @@ -48,6 +48,8 @@ const ( FieldCustom = "custom" // FieldCustomp holds the string denoting the customp field in the database. FieldCustomp = "customp" + // FieldValue holds the string denoting the value field in the database. + FieldValue = "value" // FieldCategoryID holds the string denoting the category_id field in the database. FieldCategoryID = "category_id" // EdgeParent holds the string denoting the parent edge name in mutations. @@ -95,6 +97,7 @@ var Columns = []string{ FieldInit, FieldCustom, FieldCustomp, + FieldValue, FieldCategoryID, } @@ -127,6 +130,8 @@ var ( DefaultPriority int // TextValidator is a validator for the "text" field. It is called by the builders before save. TextValidator func(string) error + // DefaultValue holds the default value on creation for the "value" field. + DefaultValue int // DefaultID holds the default value on creation for the "id" field. DefaultID func() pulid.ID ) @@ -183,6 +188,11 @@ func ByText(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldText, opts...).ToFunc() } +// ByValue orders the results by the value field. +func ByValue(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldValue, opts...).ToFunc() +} + // ByCategoryID orders the results by the category_id field. func ByCategoryID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCategoryID, opts...).ToFunc() diff --git a/entgql/internal/todopulid/ent/todo/where.go b/entgql/internal/todopulid/ent/todo/where.go index 305ac1136..aeb83ade5 100644 --- a/entgql/internal/todopulid/ent/todo/where.go +++ b/entgql/internal/todopulid/ent/todo/where.go @@ -90,6 +90,11 @@ func Blob(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) } +// Value applies equality check predicate on the "value" field. It's identical to ValueEQ. +func Value(v int) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldValue, v)) +} + // CategoryID applies equality check predicate on the "category_id" field. It's identical to CategoryIDEQ. func CategoryID(v pulid.ID) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldCategoryID, v)) @@ -340,6 +345,46 @@ func CustompNotNil() predicate.Todo { return predicate.Todo(sql.FieldNotNull(FieldCustomp)) } +// ValueEQ applies the EQ predicate on the "value" field. +func ValueEQ(v int) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldValue, v)) +} + +// ValueNEQ applies the NEQ predicate on the "value" field. +func ValueNEQ(v int) predicate.Todo { + return predicate.Todo(sql.FieldNEQ(FieldValue, v)) +} + +// ValueIn applies the In predicate on the "value" field. +func ValueIn(vs ...int) predicate.Todo { + return predicate.Todo(sql.FieldIn(FieldValue, vs...)) +} + +// ValueNotIn applies the NotIn predicate on the "value" field. +func ValueNotIn(vs ...int) predicate.Todo { + return predicate.Todo(sql.FieldNotIn(FieldValue, vs...)) +} + +// ValueGT applies the GT predicate on the "value" field. +func ValueGT(v int) predicate.Todo { + return predicate.Todo(sql.FieldGT(FieldValue, v)) +} + +// ValueGTE applies the GTE predicate on the "value" field. +func ValueGTE(v int) predicate.Todo { + return predicate.Todo(sql.FieldGTE(FieldValue, v)) +} + +// ValueLT applies the LT predicate on the "value" field. +func ValueLT(v int) predicate.Todo { + return predicate.Todo(sql.FieldLT(FieldValue, v)) +} + +// ValueLTE applies the LTE predicate on the "value" field. +func ValueLTE(v int) predicate.Todo { + return predicate.Todo(sql.FieldLTE(FieldValue, v)) +} + // CategoryIDEQ applies the EQ predicate on the "category_id" field. func CategoryIDEQ(v pulid.ID) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldCategoryID, v)) diff --git a/entgql/internal/todopulid/ent/todo_create.go b/entgql/internal/todopulid/ent/todo_create.go index cfcee90ca..78faad086 100644 --- a/entgql/internal/todopulid/ent/todo_create.go +++ b/entgql/internal/todopulid/ent/todo_create.go @@ -102,6 +102,20 @@ func (tc *TodoCreate) SetCustomp(c []*customstruct.Custom) *TodoCreate { return tc } +// SetValue sets the "value" field. +func (tc *TodoCreate) SetValue(i int) *TodoCreate { + tc.mutation.SetValue(i) + return tc +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tc *TodoCreate) SetNillableValue(i *int) *TodoCreate { + if i != nil { + tc.SetValue(*i) + } + return tc +} + // SetCategoryID sets the "category_id" field. func (tc *TodoCreate) SetCategoryID(pu pulid.ID) *TodoCreate { tc.mutation.SetCategoryID(pu) @@ -231,6 +245,10 @@ func (tc *TodoCreate) defaults() { v := todo.DefaultPriority tc.mutation.SetPriority(v) } + if _, ok := tc.mutation.Value(); !ok { + v := todo.DefaultValue + tc.mutation.SetValue(v) + } if _, ok := tc.mutation.ID(); !ok { v := todo.DefaultID() tc.mutation.SetID(v) @@ -261,6 +279,9 @@ func (tc *TodoCreate) check() error { return &ValidationError{Name: "text", err: fmt.Errorf(`ent: validator failed for field "Todo.text": %w`, err)} } } + if _, ok := tc.mutation.Value(); !ok { + return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Todo.value"`)} + } return nil } @@ -328,6 +349,10 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { _spec.SetField(todo.FieldCustomp, field.TypeJSON, value) _node.Customp = value } + if value, ok := tc.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + _node.Value = value + } if nodes := tc.mutation.ParentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entgql/internal/todopulid/ent/todo_update.go b/entgql/internal/todopulid/ent/todo_update.go index c9932eefa..30aa046a0 100644 --- a/entgql/internal/todopulid/ent/todo_update.go +++ b/entgql/internal/todopulid/ent/todo_update.go @@ -154,6 +154,27 @@ func (tu *TodoUpdate) ClearCustomp() *TodoUpdate { return tu } +// SetValue sets the "value" field. +func (tu *TodoUpdate) SetValue(i int) *TodoUpdate { + tu.mutation.ResetValue() + tu.mutation.SetValue(i) + return tu +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableValue(i *int) *TodoUpdate { + if i != nil { + tu.SetValue(*i) + } + return tu +} + +// AddValue adds i to the "value" field. +func (tu *TodoUpdate) AddValue(i int) *TodoUpdate { + tu.mutation.AddValue(i) + return tu +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tu *TodoUpdate) SetParentID(id pulid.ID) *TodoUpdate { tu.mutation.SetParentID(id) @@ -345,6 +366,12 @@ func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) { if tu.mutation.CustompCleared() { _spec.ClearField(todo.FieldCustomp, field.TypeJSON) } + if value, ok := tu.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + } + if value, ok := tu.mutation.AddedValue(); ok { + _spec.AddField(todo.FieldValue, field.TypeInt, value) + } if tu.mutation.ParentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -577,6 +604,27 @@ func (tuo *TodoUpdateOne) ClearCustomp() *TodoUpdateOne { return tuo } +// SetValue sets the "value" field. +func (tuo *TodoUpdateOne) SetValue(i int) *TodoUpdateOne { + tuo.mutation.ResetValue() + tuo.mutation.SetValue(i) + return tuo +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableValue(i *int) *TodoUpdateOne { + if i != nil { + tuo.SetValue(*i) + } + return tuo +} + +// AddValue adds i to the "value" field. +func (tuo *TodoUpdateOne) AddValue(i int) *TodoUpdateOne { + tuo.mutation.AddValue(i) + return tuo +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tuo *TodoUpdateOne) SetParentID(id pulid.ID) *TodoUpdateOne { tuo.mutation.SetParentID(id) @@ -798,6 +846,12 @@ func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) if tuo.mutation.CustompCleared() { _spec.ClearField(todo.FieldCustomp, field.TypeJSON) } + if value, ok := tuo.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + } + if value, ok := tuo.mutation.AddedValue(); ok { + _spec.AddField(todo.FieldValue, field.TypeInt, value) + } if tuo.mutation.ParentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entgql/internal/todopulid/generated.go b/entgql/internal/todopulid/generated.go index dc1e44ad7..3fc79f20c 100644 --- a/entgql/internal/todopulid/generated.go +++ b/entgql/internal/todopulid/generated.go @@ -220,6 +220,7 @@ type ComplexityRoot struct { Priority func(childComplexity int) int Status func(childComplexity int) int Text func(childComplexity int) int + Value func(childComplexity int) int } TodoConnection struct { @@ -1054,6 +1055,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Text(childComplexity), true + case "Todo.value": + if e.complexity.Todo.Value == nil { + break + } + + return e.complexity.Todo.Value(childComplexity), true + case "TodoConnection.edges": if e.complexity.TodoConnection.Edges == nil { break @@ -1725,6 +1733,7 @@ input CreateTodoInput { priority: Int text: String! init: Map + value: Int parentID: ID childIDs: [ID!] categoryID: ID @@ -2381,6 +2390,7 @@ type Todo implements Node { init: Map custom: [Custom!] customp: [Custom] + value: Int! parent: Todo children( """ @@ -2552,6 +2562,17 @@ input TodoWhereInput { categoryIDIsNil: Boolean categoryIDNotNil: Boolean """ + value field predicates + """ + value: Int + valueNEQ: Int + valueIn: [Int!] + valueNotIn: [Int!] + valueGT: Int + valueGTE: Int + valueLT: Int + valueLTE: Int + """ parent edge predicates """ hasParent: Boolean @@ -2615,6 +2636,7 @@ input UpdateTodoInput { text: String init: Map clearInit: Boolean + value: Int parentID: ID clearParent: Boolean addChildIDs: [ID!] @@ -6005,6 +6027,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -6092,6 +6116,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -8259,6 +8285,50 @@ func (ec *executionContext) fieldContext_Todo_customp(_ context.Context, field g return fc, nil } +func (ec *executionContext) _Todo_value(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_value(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Value, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_value(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Todo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Todo_parent(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Todo_parent(ctx, field) if err != nil { @@ -8317,6 +8387,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -8704,6 +8776,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -12172,7 +12246,7 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "parentID", "childIDs", "categoryID", "secretID"} + fieldsInOrder := [...]string{"status", "priority", "text", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -12209,6 +12283,13 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o return it, err } it.Init = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data case "parentID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parentID")) data, err := ec.unmarshalOID2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚋschemaᚋpulidᚐID(ctx, v) @@ -13372,7 +13453,7 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "status", "statusNEQ", "statusIn", "statusNotIn", "priority", "priorityNEQ", "priorityIn", "priorityNotIn", "priorityGT", "priorityGTE", "priorityLT", "priorityLTE", "text", "textNEQ", "textIn", "textNotIn", "textGT", "textGTE", "textLT", "textLTE", "textContains", "textHasPrefix", "textHasSuffix", "textEqualFold", "textContainsFold", "categoryID", "categoryIDNEQ", "categoryIDIn", "categoryIDNotIn", "categoryIDIsNil", "categoryIDNotNil", "hasParent", "hasParentWith", "hasChildren", "hasChildrenWith", "hasCategory", "hasCategoryWith", "createdToday"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "status", "statusNEQ", "statusIn", "statusNotIn", "priority", "priorityNEQ", "priorityIn", "priorityNotIn", "priorityGT", "priorityGTE", "priorityLT", "priorityLTE", "text", "textNEQ", "textIn", "textNotIn", "textGT", "textGTE", "textLT", "textLTE", "textContains", "textHasPrefix", "textHasSuffix", "textEqualFold", "textContainsFold", "categoryID", "categoryIDNEQ", "categoryIDIn", "categoryIDNotIn", "categoryIDIsNil", "categoryIDNotNil", "value", "valueNEQ", "valueIn", "valueNotIn", "valueGT", "valueGTE", "valueLT", "valueLTE", "hasParent", "hasParentWith", "hasChildren", "hasChildrenWith", "hasCategory", "hasCategoryWith", "createdToday"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -13737,6 +13818,62 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob return it, err } it.CategoryIDNotNil = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data + case "valueNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueNEQ")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueNEQ = data + case "valueIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueIn")) + data, err := ec.unmarshalOInt2ᚕintᚄ(ctx, v) + if err != nil { + return it, err + } + it.ValueIn = data + case "valueNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueNotIn")) + data, err := ec.unmarshalOInt2ᚕintᚄ(ctx, v) + if err != nil { + return it, err + } + it.ValueNotIn = data + case "valueGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueGT")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueGT = data + case "valueGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueGTE")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueGTE = data + case "valueLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueLT")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueLT = data + case "valueLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueLTE")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueLTE = data case "hasParent": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasParent")) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) @@ -13997,7 +14134,7 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} + fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -14041,6 +14178,13 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o return it, err } it.ClearInit = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data case "parentID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parentID")) data, err := ec.unmarshalOID2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚋschemaᚋpulidᚐID(ctx, v) @@ -16183,6 +16327,11 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = ec._Todo_custom(ctx, field, obj) case "customp": out.Values[i] = ec._Todo_customp(ctx, field, obj) + case "value": + out.Values[i] = ec._Todo_value(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } case "parent": field := field diff --git a/entgql/internal/todouuid/ent/gql_collection.go b/entgql/internal/todouuid/ent/gql_collection.go index d9c50523f..80e24f34d 100644 --- a/entgql/internal/todouuid/ent/gql_collection.go +++ b/entgql/internal/todouuid/ent/gql_collection.go @@ -855,6 +855,11 @@ func (t *TodoQuery) collectField(ctx context.Context, oneNode bool, opCtx *graph selectedFields = append(selectedFields, todo.FieldCustomp) fieldSeen[todo.FieldCustomp] = struct{}{} } + case "value": + if _, ok := fieldSeen[todo.FieldValue]; !ok { + selectedFields = append(selectedFields, todo.FieldValue) + fieldSeen[todo.FieldValue] = struct{}{} + } case "categoryID": if _, ok := fieldSeen[todo.FieldCategoryID]; !ok { selectedFields = append(selectedFields, todo.FieldCategoryID) diff --git a/entgql/internal/todouuid/ent/gql_mutation_input.go b/entgql/internal/todouuid/ent/gql_mutation_input.go index 552752b40..c41780213 100644 --- a/entgql/internal/todouuid/ent/gql_mutation_input.go +++ b/entgql/internal/todouuid/ent/gql_mutation_input.go @@ -173,6 +173,7 @@ type CreateTodoInput struct { Priority *int Text string Init map[string]interface{} + Value *int ParentID *uuid.UUID ChildIDs []uuid.UUID CategoryID *uuid.UUID @@ -189,6 +190,9 @@ func (i *CreateTodoInput) Mutate(m *TodoMutation) { if v := i.Init; v != nil { m.SetInit(v) } + if v := i.Value; v != nil { + m.SetValue(*v) + } if v := i.ParentID; v != nil { m.SetParentID(*v) } @@ -216,6 +220,7 @@ type UpdateTodoInput struct { Text *string ClearInit bool Init map[string]interface{} + Value *int ClearParent bool ParentID *uuid.UUID ClearChildren bool @@ -242,6 +247,9 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) { if v := i.Init; v != nil { m.SetInit(v) } + if v := i.Value; v != nil { + m.SetValue(*v) + } if i.ClearParent { m.ClearParent() } diff --git a/entgql/internal/todouuid/ent/gql_pagination.go b/entgql/internal/todouuid/ent/gql_pagination.go index 4b1756f64..0204a0016 100644 --- a/entgql/internal/todouuid/ent/gql_pagination.go +++ b/entgql/internal/todouuid/ent/gql_pagination.go @@ -1640,7 +1640,7 @@ var ( // TodoOrderFieldParentStatus orders by PARENT_STATUS. TodoOrderFieldParentStatus = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("parent_status") + return t.GetValue("parent_status") }, column: "parent_status", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1650,7 +1650,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("parent_status") + cv, _ := t.GetValue("parent_status") return Cursor{ ID: t.ID, Value: cv, @@ -1660,7 +1660,7 @@ var ( // TodoOrderFieldChildrenCount orders by CHILDREN_COUNT. TodoOrderFieldChildrenCount = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("children_count") + return t.GetValue("children_count") }, column: "children_count", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1669,7 +1669,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("children_count") + cv, _ := t.GetValue("children_count") return Cursor{ ID: t.ID, Value: cv, @@ -1679,7 +1679,7 @@ var ( // TodoOrderFieldCategoryText orders by CATEGORY_TEXT. TodoOrderFieldCategoryText = &TodoOrderField{ Value: func(t *Todo) (ent.Value, error) { - return t.Value("category_text") + return t.GetValue("category_text") }, column: "category_text", toTerm: func(opts ...sql.OrderTermOption) todo.OrderOption { @@ -1689,7 +1689,7 @@ var ( ) }, toCursor: func(t *Todo) Cursor { - cv, _ := t.Value("category_text") + cv, _ := t.GetValue("category_text") return Cursor{ ID: t.ID, Value: cv, diff --git a/entgql/internal/todouuid/ent/gql_where_input.go b/entgql/internal/todouuid/ent/gql_where_input.go index 7a0dc5305..c4017e76e 100644 --- a/entgql/internal/todouuid/ent/gql_where_input.go +++ b/entgql/internal/todouuid/ent/gql_where_input.go @@ -1160,6 +1160,16 @@ type TodoWhereInput struct { TextEqualFold *string `json:"textEqualFold,omitempty"` TextContainsFold *string `json:"textContainsFold,omitempty"` + // "value" field predicates. + Value *int `json:"value,omitempty"` + ValueNEQ *int `json:"valueNEQ,omitempty"` + ValueIn []int `json:"valueIn,omitempty"` + ValueNotIn []int `json:"valueNotIn,omitempty"` + ValueGT *int `json:"valueGT,omitempty"` + ValueGTE *int `json:"valueGTE,omitempty"` + ValueLT *int `json:"valueLT,omitempty"` + ValueLTE *int `json:"valueLTE,omitempty"` + // "category_id" field predicates. CategoryID *uuid.UUID `json:"categoryID,omitempty"` CategoryIDNEQ *uuid.UUID `json:"categoryIDNEQ,omitempty"` @@ -1375,6 +1385,30 @@ func (i *TodoWhereInput) P() (predicate.Todo, error) { if i.TextContainsFold != nil { predicates = append(predicates, todo.TextContainsFold(*i.TextContainsFold)) } + if i.Value != nil { + predicates = append(predicates, todo.ValueEQ(*i.Value)) + } + if i.ValueNEQ != nil { + predicates = append(predicates, todo.ValueNEQ(*i.ValueNEQ)) + } + if len(i.ValueIn) > 0 { + predicates = append(predicates, todo.ValueIn(i.ValueIn...)) + } + if len(i.ValueNotIn) > 0 { + predicates = append(predicates, todo.ValueNotIn(i.ValueNotIn...)) + } + if i.ValueGT != nil { + predicates = append(predicates, todo.ValueGT(*i.ValueGT)) + } + if i.ValueGTE != nil { + predicates = append(predicates, todo.ValueGTE(*i.ValueGTE)) + } + if i.ValueLT != nil { + predicates = append(predicates, todo.ValueLT(*i.ValueLT)) + } + if i.ValueLTE != nil { + predicates = append(predicates, todo.ValueLTE(*i.ValueLTE)) + } if i.CategoryID != nil { predicates = append(predicates, todo.CategoryIDEQ(*i.CategoryID)) } diff --git a/entgql/internal/todouuid/ent/migrate/schema.go b/entgql/internal/todouuid/ent/migrate/schema.go index be619361c..83bc90558 100644 --- a/entgql/internal/todouuid/ent/migrate/schema.go +++ b/entgql/internal/todouuid/ent/migrate/schema.go @@ -108,6 +108,7 @@ var ( {Name: "init", Type: field.TypeJSON, Nullable: true}, {Name: "custom", Type: field.TypeJSON, Nullable: true}, {Name: "customp", Type: field.TypeJSON, Nullable: true}, + {Name: "value", Type: field.TypeInt, Default: 0}, {Name: "category_id", Type: field.TypeUUID, Nullable: true}, {Name: "todo_children", Type: field.TypeUUID, Nullable: true}, {Name: "todo_secret", Type: field.TypeUUID, Nullable: true}, @@ -120,19 +121,19 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "todos_categories_todos", - Columns: []*schema.Column{TodosColumns[9]}, + Columns: []*schema.Column{TodosColumns[10]}, RefColumns: []*schema.Column{CategoriesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_todos_children", - Columns: []*schema.Column{TodosColumns[10]}, + Columns: []*schema.Column{TodosColumns[11]}, RefColumns: []*schema.Column{TodosColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_very_secrets_secret", - Columns: []*schema.Column{TodosColumns[11]}, + Columns: []*schema.Column{TodosColumns[12]}, RefColumns: []*schema.Column{VerySecretsColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/entgql/internal/todouuid/ent/mutation.go b/entgql/internal/todouuid/ent/mutation.go index 6ee345ecd..5aab32f23 100644 --- a/entgql/internal/todouuid/ent/mutation.go +++ b/entgql/internal/todouuid/ent/mutation.go @@ -2532,6 +2532,8 @@ type TodoMutation struct { appendcustom []customstruct.Custom customp *[]*customstruct.Custom appendcustomp []*customstruct.Custom + value *int + addvalue *int clearedFields map[string]struct{} parent *uuid.UUID clearedparent bool @@ -3043,6 +3045,62 @@ func (m *TodoMutation) ResetCustomp() { delete(m.clearedFields, todo.FieldCustomp) } +// SetValue sets the "value" field. +func (m *TodoMutation) SetValue(i int) { + m.value = &i + m.addvalue = nil +} + +// Value returns the value of the "value" field in the mutation. +func (m *TodoMutation) Value() (r int, exists bool) { + v := m.value + if v == nil { + return + } + return *v, true +} + +// OldValue returns the old "value" field's value of the Todo entity. +// If the Todo 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 *TodoMutation) OldValue(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldValue is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldValue requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldValue: %w", err) + } + return oldValue.Value, nil +} + +// AddValue adds i to the "value" field. +func (m *TodoMutation) AddValue(i int) { + if m.addvalue != nil { + *m.addvalue += i + } else { + m.addvalue = &i + } +} + +// AddedValue returns the value that was added to the "value" field in this mutation. +func (m *TodoMutation) AddedValue() (r int, exists bool) { + v := m.addvalue + if v == nil { + return + } + return *v, true +} + +// ResetValue resets all changes to the "value" field. +func (m *TodoMutation) ResetValue() { + m.value = nil + m.addvalue = nil +} + // SetCategoryID sets the "category_id" field. func (m *TodoMutation) SetCategoryID(u uuid.UUID) { m.category = &u @@ -3285,7 +3343,7 @@ func (m *TodoMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *TodoMutation) Fields() []string { - fields := make([]string, 0, 9) + fields := make([]string, 0, 10) if m.created_at != nil { fields = append(fields, todo.FieldCreatedAt) } @@ -3310,6 +3368,9 @@ func (m *TodoMutation) Fields() []string { if m.customp != nil { fields = append(fields, todo.FieldCustomp) } + if m.value != nil { + fields = append(fields, todo.FieldValue) + } if m.category != nil { fields = append(fields, todo.FieldCategoryID) } @@ -3337,6 +3398,8 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) { return m.Custom() case todo.FieldCustomp: return m.Customp() + case todo.FieldValue: + return m.Value() case todo.FieldCategoryID: return m.CategoryID() } @@ -3364,6 +3427,8 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldCustom(ctx) case todo.FieldCustomp: return m.OldCustomp(ctx) + case todo.FieldValue: + return m.OldValue(ctx) case todo.FieldCategoryID: return m.OldCategoryID(ctx) } @@ -3431,6 +3496,13 @@ func (m *TodoMutation) SetField(name string, value ent.Value) error { } m.SetCustomp(v) return nil + case todo.FieldValue: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetValue(v) + return nil case todo.FieldCategoryID: v, ok := value.(uuid.UUID) if !ok { @@ -3449,6 +3521,9 @@ func (m *TodoMutation) AddedFields() []string { if m.addpriority != nil { fields = append(fields, todo.FieldPriority) } + if m.addvalue != nil { + fields = append(fields, todo.FieldValue) + } return fields } @@ -3459,6 +3534,8 @@ func (m *TodoMutation) AddedField(name string) (ent.Value, bool) { switch name { case todo.FieldPriority: return m.AddedPriority() + case todo.FieldValue: + return m.AddedValue() } return nil, false } @@ -3475,6 +3552,13 @@ func (m *TodoMutation) AddField(name string, value ent.Value) error { } m.AddPriority(v) return nil + case todo.FieldValue: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddValue(v) + return nil } return fmt.Errorf("unknown Todo numeric field %s", name) } @@ -3559,6 +3643,9 @@ func (m *TodoMutation) ResetField(name string) error { case todo.FieldCustomp: m.ResetCustomp() return nil + case todo.FieldValue: + m.ResetValue() + return nil case todo.FieldCategoryID: m.ResetCategoryID() return nil diff --git a/entgql/internal/todouuid/ent/runtime.go b/entgql/internal/todouuid/ent/runtime.go index 70810b903..8acb160a2 100644 --- a/entgql/internal/todouuid/ent/runtime.go +++ b/entgql/internal/todouuid/ent/runtime.go @@ -93,6 +93,10 @@ func init() { todoDescText := todoMixinFields0[3].Descriptor() // todo.TextValidator is a validator for the "text" field. It is called by the builders before save. todo.TextValidator = todoDescText.Validators[0].(func(string) error) + // todoDescValue is the schema descriptor for value field. + todoDescValue := todoMixinFields0[8].Descriptor() + // todo.DefaultValue holds the default value on creation for the value field. + todo.DefaultValue = todoDescValue.Default.(int) // todoDescID is the schema descriptor for id field. todoDescID := todoFields[0].Descriptor() // todo.DefaultID holds the default value on creation for the id field. diff --git a/entgql/internal/todouuid/ent/todo.go b/entgql/internal/todouuid/ent/todo.go index 527e4ff07..0ec7b7c1f 100644 --- a/entgql/internal/todouuid/ent/todo.go +++ b/entgql/internal/todouuid/ent/todo.go @@ -52,6 +52,8 @@ type Todo struct { Custom []customstruct.Custom `json:"custom,omitempty"` // Customp holds the value of the "customp" field. Customp []*customstruct.Custom `json:"customp,omitempty"` + // Value holds the value of the "value" field. + Value int `json:"value,omitempty"` // CategoryID holds the value of the "category_id" field. CategoryID uuid.UUID `json:"category_id,omitempty"` // Edges holds the relations/edges for other nodes in the graph. @@ -130,7 +132,7 @@ func (*Todo) scanValues(columns []string) ([]any, error) { switch columns[i] { case todo.FieldBlob, todo.FieldInit, todo.FieldCustom, todo.FieldCustomp: values[i] = new([]byte) - case todo.FieldPriority: + case todo.FieldPriority, todo.FieldValue: values[i] = new(sql.NullInt64) case todo.FieldStatus, todo.FieldText: values[i] = new(sql.NullString) @@ -217,6 +219,12 @@ func (t *Todo) assignValues(columns []string, values []any) error { return fmt.Errorf("unmarshal field customp: %w", err) } } + case todo.FieldValue: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field value", values[i]) + } else if value.Valid { + t.Value = int(value.Int64) + } case todo.FieldCategoryID: if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field category_id", values[i]) @@ -244,9 +252,9 @@ func (t *Todo) assignValues(columns []string, values []any) error { return nil } -// Value returns the ent.Value that was dynamically selected and assigned to the Todo. +// GetValue returns the ent.Value that was dynamically selected and assigned to the Todo. // This includes values selected through modifiers, order, etc. -func (t *Todo) Value(name string) (ent.Value, error) { +func (t *Todo) GetValue(name string) (ent.Value, error) { return t.selectValues.Get(name) } @@ -317,6 +325,9 @@ func (t *Todo) String() string { builder.WriteString("customp=") builder.WriteString(fmt.Sprintf("%v", t.Customp)) builder.WriteString(", ") + builder.WriteString("value=") + builder.WriteString(fmt.Sprintf("%v", t.Value)) + builder.WriteString(", ") builder.WriteString("category_id=") builder.WriteString(fmt.Sprintf("%v", t.CategoryID)) builder.WriteByte(')') diff --git a/entgql/internal/todouuid/ent/todo/todo.go b/entgql/internal/todouuid/ent/todo/todo.go index 28ba6082f..3988e4c04 100644 --- a/entgql/internal/todouuid/ent/todo/todo.go +++ b/entgql/internal/todouuid/ent/todo/todo.go @@ -48,6 +48,8 @@ const ( FieldCustom = "custom" // FieldCustomp holds the string denoting the customp field in the database. FieldCustomp = "customp" + // FieldValue holds the string denoting the value field in the database. + FieldValue = "value" // FieldCategoryID holds the string denoting the category_id field in the database. FieldCategoryID = "category_id" // EdgeParent holds the string denoting the parent edge name in mutations. @@ -95,6 +97,7 @@ var Columns = []string{ FieldInit, FieldCustom, FieldCustomp, + FieldValue, FieldCategoryID, } @@ -127,6 +130,8 @@ var ( DefaultPriority int // TextValidator is a validator for the "text" field. It is called by the builders before save. TextValidator func(string) error + // DefaultValue holds the default value on creation for the "value" field. + DefaultValue int // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) @@ -183,6 +188,11 @@ func ByText(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldText, opts...).ToFunc() } +// ByValue orders the results by the value field. +func ByValue(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldValue, opts...).ToFunc() +} + // ByCategoryID orders the results by the category_id field. func ByCategoryID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCategoryID, opts...).ToFunc() diff --git a/entgql/internal/todouuid/ent/todo/where.go b/entgql/internal/todouuid/ent/todo/where.go index 9449e7bbb..217c84831 100644 --- a/entgql/internal/todouuid/ent/todo/where.go +++ b/entgql/internal/todouuid/ent/todo/where.go @@ -90,6 +90,11 @@ func Blob(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) } +// Value applies equality check predicate on the "value" field. It's identical to ValueEQ. +func Value(v int) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldValue, v)) +} + // CategoryID applies equality check predicate on the "category_id" field. It's identical to CategoryIDEQ. func CategoryID(v uuid.UUID) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldCategoryID, v)) @@ -340,6 +345,46 @@ func CustompNotNil() predicate.Todo { return predicate.Todo(sql.FieldNotNull(FieldCustomp)) } +// ValueEQ applies the EQ predicate on the "value" field. +func ValueEQ(v int) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldValue, v)) +} + +// ValueNEQ applies the NEQ predicate on the "value" field. +func ValueNEQ(v int) predicate.Todo { + return predicate.Todo(sql.FieldNEQ(FieldValue, v)) +} + +// ValueIn applies the In predicate on the "value" field. +func ValueIn(vs ...int) predicate.Todo { + return predicate.Todo(sql.FieldIn(FieldValue, vs...)) +} + +// ValueNotIn applies the NotIn predicate on the "value" field. +func ValueNotIn(vs ...int) predicate.Todo { + return predicate.Todo(sql.FieldNotIn(FieldValue, vs...)) +} + +// ValueGT applies the GT predicate on the "value" field. +func ValueGT(v int) predicate.Todo { + return predicate.Todo(sql.FieldGT(FieldValue, v)) +} + +// ValueGTE applies the GTE predicate on the "value" field. +func ValueGTE(v int) predicate.Todo { + return predicate.Todo(sql.FieldGTE(FieldValue, v)) +} + +// ValueLT applies the LT predicate on the "value" field. +func ValueLT(v int) predicate.Todo { + return predicate.Todo(sql.FieldLT(FieldValue, v)) +} + +// ValueLTE applies the LTE predicate on the "value" field. +func ValueLTE(v int) predicate.Todo { + return predicate.Todo(sql.FieldLTE(FieldValue, v)) +} + // CategoryIDEQ applies the EQ predicate on the "category_id" field. func CategoryIDEQ(v uuid.UUID) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldCategoryID, v)) diff --git a/entgql/internal/todouuid/ent/todo_create.go b/entgql/internal/todouuid/ent/todo_create.go index 20a4bda27..6c1bab4bb 100644 --- a/entgql/internal/todouuid/ent/todo_create.go +++ b/entgql/internal/todouuid/ent/todo_create.go @@ -102,6 +102,20 @@ func (tc *TodoCreate) SetCustomp(c []*customstruct.Custom) *TodoCreate { return tc } +// SetValue sets the "value" field. +func (tc *TodoCreate) SetValue(i int) *TodoCreate { + tc.mutation.SetValue(i) + return tc +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tc *TodoCreate) SetNillableValue(i *int) *TodoCreate { + if i != nil { + tc.SetValue(*i) + } + return tc +} + // SetCategoryID sets the "category_id" field. func (tc *TodoCreate) SetCategoryID(u uuid.UUID) *TodoCreate { tc.mutation.SetCategoryID(u) @@ -231,6 +245,10 @@ func (tc *TodoCreate) defaults() { v := todo.DefaultPriority tc.mutation.SetPriority(v) } + if _, ok := tc.mutation.Value(); !ok { + v := todo.DefaultValue + tc.mutation.SetValue(v) + } if _, ok := tc.mutation.ID(); !ok { v := todo.DefaultID() tc.mutation.SetID(v) @@ -261,6 +279,9 @@ func (tc *TodoCreate) check() error { return &ValidationError{Name: "text", err: fmt.Errorf(`ent: validator failed for field "Todo.text": %w`, err)} } } + if _, ok := tc.mutation.Value(); !ok { + return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Todo.value"`)} + } return nil } @@ -328,6 +349,10 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { _spec.SetField(todo.FieldCustomp, field.TypeJSON, value) _node.Customp = value } + if value, ok := tc.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + _node.Value = value + } if nodes := tc.mutation.ParentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entgql/internal/todouuid/ent/todo_update.go b/entgql/internal/todouuid/ent/todo_update.go index 097db002f..2f413aa76 100644 --- a/entgql/internal/todouuid/ent/todo_update.go +++ b/entgql/internal/todouuid/ent/todo_update.go @@ -154,6 +154,27 @@ func (tu *TodoUpdate) ClearCustomp() *TodoUpdate { return tu } +// SetValue sets the "value" field. +func (tu *TodoUpdate) SetValue(i int) *TodoUpdate { + tu.mutation.ResetValue() + tu.mutation.SetValue(i) + return tu +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableValue(i *int) *TodoUpdate { + if i != nil { + tu.SetValue(*i) + } + return tu +} + +// AddValue adds i to the "value" field. +func (tu *TodoUpdate) AddValue(i int) *TodoUpdate { + tu.mutation.AddValue(i) + return tu +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tu *TodoUpdate) SetParentID(id uuid.UUID) *TodoUpdate { tu.mutation.SetParentID(id) @@ -345,6 +366,12 @@ func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) { if tu.mutation.CustompCleared() { _spec.ClearField(todo.FieldCustomp, field.TypeJSON) } + if value, ok := tu.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + } + if value, ok := tu.mutation.AddedValue(); ok { + _spec.AddField(todo.FieldValue, field.TypeInt, value) + } if tu.mutation.ParentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -577,6 +604,27 @@ func (tuo *TodoUpdateOne) ClearCustomp() *TodoUpdateOne { return tuo } +// SetValue sets the "value" field. +func (tuo *TodoUpdateOne) SetValue(i int) *TodoUpdateOne { + tuo.mutation.ResetValue() + tuo.mutation.SetValue(i) + return tuo +} + +// SetNillableValue sets the "value" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableValue(i *int) *TodoUpdateOne { + if i != nil { + tuo.SetValue(*i) + } + return tuo +} + +// AddValue adds i to the "value" field. +func (tuo *TodoUpdateOne) AddValue(i int) *TodoUpdateOne { + tuo.mutation.AddValue(i) + return tuo +} + // SetParentID sets the "parent" edge to the Todo entity by ID. func (tuo *TodoUpdateOne) SetParentID(id uuid.UUID) *TodoUpdateOne { tuo.mutation.SetParentID(id) @@ -798,6 +846,12 @@ func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) if tuo.mutation.CustompCleared() { _spec.ClearField(todo.FieldCustomp, field.TypeJSON) } + if value, ok := tuo.mutation.Value(); ok { + _spec.SetField(todo.FieldValue, field.TypeInt, value) + } + if value, ok := tuo.mutation.AddedValue(); ok { + _spec.AddField(todo.FieldValue, field.TypeInt, value) + } if tuo.mutation.ParentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entgql/internal/todouuid/generated.go b/entgql/internal/todouuid/generated.go index 92795d3d6..e9c2fd16e 100644 --- a/entgql/internal/todouuid/generated.go +++ b/entgql/internal/todouuid/generated.go @@ -221,6 +221,7 @@ type ComplexityRoot struct { Priority func(childComplexity int) int Status func(childComplexity int) int Text func(childComplexity int) int + Value func(childComplexity int) int } TodoConnection struct { @@ -1055,6 +1056,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Text(childComplexity), true + case "Todo.value": + if e.complexity.Todo.Value == nil { + break + } + + return e.complexity.Todo.Value(childComplexity), true + case "TodoConnection.edges": if e.complexity.TodoConnection.Edges == nil { break @@ -1726,6 +1734,7 @@ input CreateTodoInput { priority: Int text: String! init: Map + value: Int parentID: ID childIDs: [ID!] categoryID: ID @@ -2382,6 +2391,7 @@ type Todo implements Node { init: Map custom: [Custom!] customp: [Custom] + value: Int! parent: Todo children( """ @@ -2553,6 +2563,17 @@ input TodoWhereInput { categoryIDIsNil: Boolean categoryIDNotNil: Boolean """ + value field predicates + """ + value: Int + valueNEQ: Int + valueIn: [Int!] + valueNotIn: [Int!] + valueGT: Int + valueGTE: Int + valueLT: Int + valueLTE: Int + """ parent edge predicates """ hasParent: Boolean @@ -2616,6 +2637,7 @@ input UpdateTodoInput { text: String init: Map clearInit: Boolean + value: Int parentID: ID clearParent: Boolean addChildIDs: [ID!] @@ -6006,6 +6028,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -6093,6 +6117,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -8260,6 +8286,50 @@ func (ec *executionContext) fieldContext_Todo_customp(_ context.Context, field g return fc, nil } +func (ec *executionContext) _Todo_value(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_value(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Value, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_value(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Todo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Todo_parent(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Todo_parent(ctx, field) if err != nil { @@ -8318,6 +8388,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -8705,6 +8777,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_custom(ctx, field) case "customp": return ec.fieldContext_Todo_customp(ctx, field) + case "value": + return ec.fieldContext_Todo_value(ctx, field) case "parent": return ec.fieldContext_Todo_parent(ctx, field) case "children": @@ -12173,7 +12247,7 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "parentID", "childIDs", "categoryID", "secretID"} + fieldsInOrder := [...]string{"status", "priority", "text", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -12210,6 +12284,13 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o return it, err } it.Init = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data case "parentID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parentID")) data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) @@ -13373,7 +13454,7 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "status", "statusNEQ", "statusIn", "statusNotIn", "priority", "priorityNEQ", "priorityIn", "priorityNotIn", "priorityGT", "priorityGTE", "priorityLT", "priorityLTE", "text", "textNEQ", "textIn", "textNotIn", "textGT", "textGTE", "textLT", "textLTE", "textContains", "textHasPrefix", "textHasSuffix", "textEqualFold", "textContainsFold", "categoryID", "categoryIDNEQ", "categoryIDIn", "categoryIDNotIn", "categoryIDIsNil", "categoryIDNotNil", "hasParent", "hasParentWith", "hasChildren", "hasChildrenWith", "hasCategory", "hasCategoryWith", "createdToday"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "status", "statusNEQ", "statusIn", "statusNotIn", "priority", "priorityNEQ", "priorityIn", "priorityNotIn", "priorityGT", "priorityGTE", "priorityLT", "priorityLTE", "text", "textNEQ", "textIn", "textNotIn", "textGT", "textGTE", "textLT", "textLTE", "textContains", "textHasPrefix", "textHasSuffix", "textEqualFold", "textContainsFold", "categoryID", "categoryIDNEQ", "categoryIDIn", "categoryIDNotIn", "categoryIDIsNil", "categoryIDNotNil", "value", "valueNEQ", "valueIn", "valueNotIn", "valueGT", "valueGTE", "valueLT", "valueLTE", "hasParent", "hasParentWith", "hasChildren", "hasChildrenWith", "hasCategory", "hasCategoryWith", "createdToday"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -13738,6 +13819,62 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob return it, err } it.CategoryIDNotNil = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data + case "valueNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueNEQ")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueNEQ = data + case "valueIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueIn")) + data, err := ec.unmarshalOInt2ᚕintᚄ(ctx, v) + if err != nil { + return it, err + } + it.ValueIn = data + case "valueNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueNotIn")) + data, err := ec.unmarshalOInt2ᚕintᚄ(ctx, v) + if err != nil { + return it, err + } + it.ValueNotIn = data + case "valueGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueGT")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueGT = data + case "valueGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueGTE")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueGTE = data + case "valueLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueLT")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueLT = data + case "valueLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("valueLTE")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ValueLTE = data case "hasParent": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasParent")) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) @@ -13998,7 +14135,7 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} + fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -14042,6 +14179,13 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o return it, err } it.ClearInit = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Value = data case "parentID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parentID")) data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) @@ -16184,6 +16328,11 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = ec._Todo_custom(ctx, field, obj) case "customp": out.Values[i] = ec._Todo_customp(ctx, field, obj) + case "value": + out.Values[i] = ec._Todo_value(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } case "parent": field := field diff --git a/entgql/template/pagination.tmpl b/entgql/template/pagination.tmpl index 5a9869199..6a7a96a8b 100644 --- a/entgql/template/pagination.tmpl +++ b/entgql/template/pagination.tmpl @@ -484,7 +484,7 @@ func ({{ $r }} *{{ $query }}) Paginate( {{- if $f.IsFieldTerm }} return {{ $r }}.{{ $f.Field.StructField }}, nil {{- else }} - return {{ $r }}.Value({{ $f.VarField }}) + return {{ $r }}.{{ $node.ValueName }}({{ $f.VarField }}) {{- end }} }, {{- if $f.IsFieldTerm }} @@ -515,7 +515,7 @@ func ({{ $r }} *{{ $query }}) Paginate( } {{- else }} {{- /* Unxpected non-selected field error can occur. */}} - cv, _ := {{ $r }}.Value({{ $f.VarField }}) + cv, _ := {{ $r }}.{{ $node.ValueName }}({{ $f.VarField }}) return Cursor{ ID: {{ $r }}.{{ if $marshalID }}marshalID(){{ else }}ID{{ end }}, Value: cv, diff --git a/entgql/testdata/schema.graphql b/entgql/testdata/schema.graphql index 37010fab2..289e579b3 100644 --- a/entgql/testdata/schema.graphql +++ b/entgql/testdata/schema.graphql @@ -71,6 +71,7 @@ input CreateTodoInput { priority: Int text: String! init: Map + value: Int parentID: ID childIDs: [ID!] categoryID: ID @@ -167,6 +168,7 @@ type Todo { init: Map custom: [Custom!] customp: [Custom] + value: Int! parent: Todo children: [Todo!] category: Category @@ -252,6 +254,7 @@ input UpdateTodoInput { text: String init: Map clearInit: Boolean + value: Int parentID: ID clearParent: Boolean addChildIDs: [ID!] diff --git a/entgql/testdata/schema_output.graphql b/entgql/testdata/schema_output.graphql index 37010fab2..289e579b3 100644 --- a/entgql/testdata/schema_output.graphql +++ b/entgql/testdata/schema_output.graphql @@ -71,6 +71,7 @@ input CreateTodoInput { priority: Int text: String! init: Map + value: Int parentID: ID childIDs: [ID!] categoryID: ID @@ -167,6 +168,7 @@ type Todo { init: Map custom: [Custom!] customp: [Custom] + value: Int! parent: Todo children: [Todo!] category: Category @@ -252,6 +254,7 @@ input UpdateTodoInput { text: String init: Map clearInit: Boolean + value: Int parentID: ID clearParent: Boolean addChildIDs: [ID!] diff --git a/entgql/testdata/schema_relay.graphql b/entgql/testdata/schema_relay.graphql index d641fb8ea..8f0d69b91 100644 --- a/entgql/testdata/schema_relay.graphql +++ b/entgql/testdata/schema_relay.graphql @@ -316,6 +316,7 @@ input CreateTodoInput { priority: Int text: String! init: Map + value: Int parentID: ID childIDs: [ID!] categoryID: ID @@ -922,6 +923,7 @@ type Todo implements Node { init: Map custom: [Custom!] customp: [Custom] + value: Int! parent: Todo children( """ @@ -1093,6 +1095,17 @@ input TodoWhereInput { categoryIDIsNil: Boolean categoryIDNotNil: Boolean """ + value field predicates + """ + value: Int + valueNEQ: Int + valueIn: [Int!] + valueNotIn: [Int!] + valueGT: Int + valueGTE: Int + valueLT: Int + valueLTE: Int + """ parent edge predicates """ hasParent: Boolean @@ -1156,6 +1169,7 @@ input UpdateTodoInput { text: String init: Map clearInit: Boolean + value: Int parentID: ID clearParent: Boolean addChildIDs: [ID!] diff --git a/entgql/testdata/schema_relay_output.graphql b/entgql/testdata/schema_relay_output.graphql index d641fb8ea..8f0d69b91 100644 --- a/entgql/testdata/schema_relay_output.graphql +++ b/entgql/testdata/schema_relay_output.graphql @@ -316,6 +316,7 @@ input CreateTodoInput { priority: Int text: String! init: Map + value: Int parentID: ID childIDs: [ID!] categoryID: ID @@ -922,6 +923,7 @@ type Todo implements Node { init: Map custom: [Custom!] customp: [Custom] + value: Int! parent: Todo children( """ @@ -1093,6 +1095,17 @@ input TodoWhereInput { categoryIDIsNil: Boolean categoryIDNotNil: Boolean """ + value field predicates + """ + value: Int + valueNEQ: Int + valueIn: [Int!] + valueNotIn: [Int!] + valueGT: Int + valueGTE: Int + valueLT: Int + valueLTE: Int + """ parent edge predicates """ hasParent: Boolean @@ -1156,6 +1169,7 @@ input UpdateTodoInput { text: String init: Map clearInit: Boolean + value: Int parentID: ID clearParent: Boolean addChildIDs: [ID!]