From 486d070d5f0ddce731829e61d1d598873606920d Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Wed, 19 Nov 2025 21:29:41 +0200 Subject: [PATCH] entgql: add the CollectedFor annotation --- entgql/annotation.go | 23 ++ entgql/internal/todo/ent.graphql | 22 ++ entgql/internal/todo/ent/gql_collection.go | 5 + .../internal/todo/ent/gql_mutation_input.go | 12 + .../internal/todo/ent/gql_node_descriptor.go | 20 +- entgql/internal/todo/ent/gql_where_input.go | 62 ++++ entgql/internal/todo/ent/migrate/schema.go | 9 +- entgql/internal/todo/ent/mutation.go | 75 ++++- entgql/internal/todo/ent/runtime.go | 2 +- entgql/internal/todo/ent/schema/todo.go | 5 + entgql/internal/todo/ent/todo.go | 13 +- entgql/internal/todo/ent/todo/todo.go | 8 + entgql/internal/todo/ent/todo/where.go | 80 +++++ entgql/internal/todo/ent/todo_create.go | 18 + entgql/internal/todo/ent/todo_update.go | 52 +++ entgql/internal/todo/generated.go | 282 +++++++++++++++- entgql/internal/todo/todo.graphql | 1 + entgql/internal/todo/todo.resolvers.go | 7 + entgql/internal/todo/todo_test.go | 35 +- .../internal/todogotype/ent/gql_collection.go | 5 + .../todogotype/ent/gql_mutation_input.go | 12 + .../todogotype/ent/gql_where_input.go | 62 ++++ .../internal/todogotype/ent/migrate/schema.go | 7 +- entgql/internal/todogotype/ent/mutation.go | 75 ++++- entgql/internal/todogotype/ent/runtime.go | 2 +- entgql/internal/todogotype/ent/todo.go | 13 +- entgql/internal/todogotype/ent/todo/todo.go | 8 + entgql/internal/todogotype/ent/todo/where.go | 80 +++++ entgql/internal/todogotype/ent/todo_create.go | 18 + entgql/internal/todogotype/ent/todo_update.go | 52 +++ entgql/internal/todogotype/generated.go | 315 +++++++++++++++++- entgql/internal/todogotype/todo.resolvers.go | 5 + .../internal/todopulid/ent/gql_collection.go | 5 + .../todopulid/ent/gql_mutation_input.go | 12 + .../internal/todopulid/ent/gql_where_input.go | 62 ++++ .../internal/todopulid/ent/migrate/schema.go | 7 +- entgql/internal/todopulid/ent/mutation.go | 75 ++++- entgql/internal/todopulid/ent/runtime.go | 2 +- entgql/internal/todopulid/ent/todo.go | 13 +- entgql/internal/todopulid/ent/todo/todo.go | 8 + entgql/internal/todopulid/ent/todo/where.go | 80 +++++ entgql/internal/todopulid/ent/todo_create.go | 18 + entgql/internal/todopulid/ent/todo_update.go | 52 +++ entgql/internal/todopulid/generated.go | 315 +++++++++++++++++- entgql/internal/todopulid/todo.resolvers.go | 5 + .../internal/todouuid/ent/gql_collection.go | 5 + .../todouuid/ent/gql_mutation_input.go | 12 + .../internal/todouuid/ent/gql_where_input.go | 62 ++++ .../internal/todouuid/ent/migrate/schema.go | 7 +- entgql/internal/todouuid/ent/mutation.go | 75 ++++- entgql/internal/todouuid/ent/runtime.go | 2 +- entgql/internal/todouuid/ent/todo.go | 13 +- entgql/internal/todouuid/ent/todo/todo.go | 8 + entgql/internal/todouuid/ent/todo/where.go | 80 +++++ entgql/internal/todouuid/ent/todo_create.go | 18 + entgql/internal/todouuid/ent/todo_update.go | 52 +++ entgql/internal/todouuid/generated.go | 315 +++++++++++++++++- entgql/internal/todouuid/todo.resolvers.go | 5 + entgql/template.go | 11 + entgql/template/collection.tmpl | 8 +- entgql/testdata/schema.graphql | 4 + entgql/testdata/schema_output.graphql | 4 + entgql/testdata/schema_relay.graphql | 22 ++ entgql/testdata/schema_relay_output.graphql | 22 ++ 64 files changed, 2719 insertions(+), 45 deletions(-) diff --git a/entgql/annotation.go b/entgql/annotation.go index c423e905f..24a29c2c3 100644 --- a/entgql/annotation.go +++ b/entgql/annotation.go @@ -51,6 +51,9 @@ type ( QueryField *FieldConfig `json:"QueryField,omitempty"` // MutationInputs defines the input types for the mutation. MutationInputs []MutationConfig `json:"MutationInputs,omitempty"` + // CollectedFor indicates that this field should be collected when any of the specified GraphQL field names are queried. + // This is useful for resolver fields that depend on this field's value. + CollectedFor []string `json:"CollectedFor,omitempty"` } // Directive to apply on the field/type. @@ -180,6 +183,23 @@ func MapsTo(names ...string) Annotation { } } +// CollectedFor returns an annotation indicating that this field should be collected +// when any of the specified GraphQL field names are queried. This is useful for +// resolver fields that depend on this field's value. +// +// For example, if you have a resolver field `uppercaseName` that depends on the `name` field: +// +// field.String("name"). +// Annotations(entgql.CollectedFor("uppercaseName")) +// +// When `uppercaseName` is queried, the `name` field will be automatically fetched, +// ensuring `unknownSeen` remains false and the field is available in the resolver. +func CollectedFor(names ...string) Annotation { + return Annotation{ + CollectedFor: names, + } +} + // Type returns a type mapping annotation. // The Type() annotation is used to map the underlying // GraphQL type to the type. @@ -482,6 +502,9 @@ func (a Annotation) Merge(other schema.Annotation) schema.Annotation { } a.QueryField.merge(ant.QueryField) } + if len(ant.CollectedFor) > 0 { + a.CollectedFor = append(a.CollectedFor, ant.CollectedFor...) + } return a } diff --git a/entgql/internal/todo/ent.graphql b/entgql/internal/todo/ent.graphql index 03c085a81..8a6056074 100644 --- a/entgql/internal/todo/ent.graphql +++ b/entgql/internal/todo/ent.graphql @@ -317,6 +317,7 @@ input CreateTodoInput { status: TodoStatus! priority: Int text: String! + name: String init: Map value: Int parentID: ID @@ -969,6 +970,7 @@ type Todo implements Node { status: TodoStatus! priorityOrder: Int! @goField(name: "Priority", forceResolver: false) text: String! + name: String categoryID: ID category_id: ID categoryX: ID @goField(name: "CategoryID", forceResolver: false) @@ -1138,6 +1140,24 @@ input TodoWhereInput { textEqualFold: String textContainsFold: String """ + name field predicates + """ + name: String + nameNEQ: String + nameIn: [String!] + nameNotIn: [String!] + nameGT: String + nameGTE: String + nameLT: String + nameLTE: String + nameContains: String + nameHasPrefix: String + nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean + nameEqualFold: String + nameContainsFold: String + """ category_id field predicates """ categoryID: ID @@ -1219,6 +1239,8 @@ input UpdateTodoInput { status: TodoStatus priority: Int text: String + name: String + clearName: Boolean init: Map clearInit: Boolean value: Int diff --git a/entgql/internal/todo/ent/gql_collection.go b/entgql/internal/todo/ent/gql_collection.go index 661eef1fb..7eccb6e76 100644 --- a/entgql/internal/todo/ent/gql_collection.go +++ b/entgql/internal/todo/ent/gql_collection.go @@ -1103,6 +1103,11 @@ func (tq *TodoQuery) collectField(ctx context.Context, oneNode bool, opCtx *grap selectedFields = append(selectedFields, todo.FieldText) fieldSeen[todo.FieldText] = struct{}{} } + case "name", "uppercaseName": + if _, ok := fieldSeen[todo.FieldName]; !ok { + selectedFields = append(selectedFields, todo.FieldName) + fieldSeen[todo.FieldName] = struct{}{} + } case "categoryID", "category_id", "categoryX": if _, ok := fieldSeen[todo.FieldCategoryID]; !ok { selectedFields = append(selectedFields, todo.FieldCategoryID) diff --git a/entgql/internal/todo/ent/gql_mutation_input.go b/entgql/internal/todo/ent/gql_mutation_input.go index 08842e642..931c51f91 100644 --- a/entgql/internal/todo/ent/gql_mutation_input.go +++ b/entgql/internal/todo/ent/gql_mutation_input.go @@ -204,6 +204,7 @@ type CreateTodoInput struct { Status todo.Status Priority *int Text string + Name *string Init map[string]interface{} Value *int ParentID *int @@ -219,6 +220,9 @@ func (i *CreateTodoInput) Mutate(m *TodoMutation) { m.SetPriority(*v) } m.SetText(i.Text) + if v := i.Name; v != nil { + m.SetName(*v) + } if v := i.Init; v != nil { m.SetInit(v) } @@ -250,6 +254,8 @@ type UpdateTodoInput struct { Status *todo.Status Priority *int Text *string + ClearName bool + Name *string ClearInit bool Init map[string]interface{} Value *int @@ -273,6 +279,12 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) { if v := i.Text; v != nil { m.SetText(*v) } + if i.ClearName { + m.ClearName() + } + if v := i.Name; v != nil { + m.SetName(*v) + } if i.ClearInit { m.ClearInit() } diff --git a/entgql/internal/todo/ent/gql_node_descriptor.go b/entgql/internal/todo/ent/gql_node_descriptor.go index fbdf93b28..c8ddbfc4b 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, 9), + Fields: make([]*Field, 10), Edges: make([]*Edge, 3), } var buf []byte @@ -370,10 +370,18 @@ func (t *Todo) Node(ctx context.Context) (node *Node, err error) { Name: "text", Value: string(buf), } - if buf, err = json.Marshal(t.CategoryID); err != nil { + if buf, err = json.Marshal(t.Name); err != nil { return nil, err } node.Fields[4] = &Field{ + Type: "string", + Name: "name", + Value: string(buf), + } + if buf, err = json.Marshal(t.CategoryID); err != nil { + return nil, err + } + node.Fields[5] = &Field{ Type: "int", Name: "category_id", Value: string(buf), @@ -381,7 +389,7 @@ func (t *Todo) Node(ctx context.Context) (node *Node, err error) { if buf, err = json.Marshal(t.Init); err != nil { return nil, err } - node.Fields[5] = &Field{ + node.Fields[6] = &Field{ Type: "map[string]interface {}", Name: "init", Value: string(buf), @@ -389,7 +397,7 @@ func (t *Todo) Node(ctx context.Context) (node *Node, err error) { if buf, err = json.Marshal(t.Custom); err != nil { return nil, err } - node.Fields[6] = &Field{ + node.Fields[7] = &Field{ Type: "[]customstruct.Custom", Name: "custom", Value: string(buf), @@ -397,7 +405,7 @@ func (t *Todo) Node(ctx context.Context) (node *Node, err error) { if buf, err = json.Marshal(t.Customp); err != nil { return nil, err } - node.Fields[7] = &Field{ + node.Fields[8] = &Field{ Type: "[]*customstruct.Custom", Name: "customp", Value: string(buf), @@ -405,7 +413,7 @@ func (t *Todo) Node(ctx context.Context) (node *Node, err error) { if buf, err = json.Marshal(t.Value); err != nil { return nil, err } - node.Fields[8] = &Field{ + node.Fields[9] = &Field{ Type: "int", Name: "value", Value: string(buf), diff --git a/entgql/internal/todo/ent/gql_where_input.go b/entgql/internal/todo/ent/gql_where_input.go index 060d464d6..2ae44febd 100644 --- a/entgql/internal/todo/ent/gql_where_input.go +++ b/entgql/internal/todo/ent/gql_where_input.go @@ -1593,6 +1593,23 @@ type TodoWhereInput struct { TextEqualFold *string `json:"textEqualFold,omitempty"` TextContainsFold *string `json:"textContainsFold,omitempty"` + // "name" field predicates. + Name *string `json:"name,omitempty"` + NameNEQ *string `json:"nameNEQ,omitempty"` + NameIn []string `json:"nameIn,omitempty"` + NameNotIn []string `json:"nameNotIn,omitempty"` + NameGT *string `json:"nameGT,omitempty"` + NameGTE *string `json:"nameGTE,omitempty"` + NameLT *string `json:"nameLT,omitempty"` + NameLTE *string `json:"nameLTE,omitempty"` + NameContains *string `json:"nameContains,omitempty"` + NameHasPrefix *string `json:"nameHasPrefix,omitempty"` + NameHasSuffix *string `json:"nameHasSuffix,omitempty"` + NameIsNil bool `json:"nameIsNil,omitempty"` + NameNotNil bool `json:"nameNotNil,omitempty"` + NameEqualFold *string `json:"nameEqualFold,omitempty"` + NameContainsFold *string `json:"nameContainsFold,omitempty"` + // "category_id" field predicates. CategoryID *int `json:"categoryID,omitempty"` CategoryIDNEQ *int `json:"categoryIDNEQ,omitempty"` @@ -1818,6 +1835,51 @@ func (i *TodoWhereInput) P() (predicate.Todo, error) { if i.TextContainsFold != nil { predicates = append(predicates, todo.TextContainsFold(*i.TextContainsFold)) } + if i.Name != nil { + predicates = append(predicates, todo.NameEQ(*i.Name)) + } + if i.NameNEQ != nil { + predicates = append(predicates, todo.NameNEQ(*i.NameNEQ)) + } + if len(i.NameIn) > 0 { + predicates = append(predicates, todo.NameIn(i.NameIn...)) + } + if len(i.NameNotIn) > 0 { + predicates = append(predicates, todo.NameNotIn(i.NameNotIn...)) + } + if i.NameGT != nil { + predicates = append(predicates, todo.NameGT(*i.NameGT)) + } + if i.NameGTE != nil { + predicates = append(predicates, todo.NameGTE(*i.NameGTE)) + } + if i.NameLT != nil { + predicates = append(predicates, todo.NameLT(*i.NameLT)) + } + if i.NameLTE != nil { + predicates = append(predicates, todo.NameLTE(*i.NameLTE)) + } + if i.NameContains != nil { + predicates = append(predicates, todo.NameContains(*i.NameContains)) + } + if i.NameHasPrefix != nil { + predicates = append(predicates, todo.NameHasPrefix(*i.NameHasPrefix)) + } + if i.NameHasSuffix != nil { + predicates = append(predicates, todo.NameHasSuffix(*i.NameHasSuffix)) + } + if i.NameIsNil { + predicates = append(predicates, todo.NameIsNil()) + } + if i.NameNotNil { + predicates = append(predicates, todo.NameNotNil()) + } + if i.NameEqualFold != nil { + predicates = append(predicates, todo.NameEqualFold(*i.NameEqualFold)) + } + if i.NameContainsFold != nil { + predicates = append(predicates, todo.NameContainsFold(*i.NameContainsFold)) + } if i.CategoryID != nil { predicates = append(predicates, todo.CategoryIDEQ(*i.CategoryID)) } diff --git a/entgql/internal/todo/ent/migrate/schema.go b/entgql/internal/todo/ent/migrate/schema.go index 683b904f3..eac1ff90c 100644 --- a/entgql/internal/todo/ent/migrate/schema.go +++ b/entgql/internal/todo/ent/migrate/schema.go @@ -135,6 +135,7 @@ var ( {Name: "status", Type: field.TypeEnum, Enums: []string{"IN_PROGRESS", "COMPLETED", "PENDING"}}, {Name: "priority", Type: field.TypeInt, Default: 0}, {Name: "text", Type: field.TypeString, Size: 2147483647}, + {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "blob", Type: field.TypeBytes, Nullable: true}, {Name: "init", Type: field.TypeJSON, Nullable: true}, {Name: "custom", Type: field.TypeJSON, Nullable: true}, @@ -153,25 +154,25 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "todos_categories_todos", - Columns: []*schema.Column{TodosColumns[10]}, + Columns: []*schema.Column{TodosColumns[11]}, RefColumns: []*schema.Column{CategoriesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_projects_todos", - Columns: []*schema.Column{TodosColumns[11]}, + Columns: []*schema.Column{TodosColumns[12]}, RefColumns: []*schema.Column{ProjectsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_todos_children", - Columns: []*schema.Column{TodosColumns[12]}, + Columns: []*schema.Column{TodosColumns[13]}, RefColumns: []*schema.Column{TodosColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "todos_very_secrets_secret", - Columns: []*schema.Column{TodosColumns[13]}, + Columns: []*schema.Column{TodosColumns[14]}, 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 563fbb10e..c9194fbb4 100644 --- a/entgql/internal/todo/ent/mutation.go +++ b/entgql/internal/todo/ent/mutation.go @@ -3491,6 +3491,7 @@ type TodoMutation struct { priority *int addpriority *int text *string + name *string blob *[]byte init *map[string]interface{} custom *[]customstruct.Custom @@ -3776,6 +3777,55 @@ func (m *TodoMutation) ResetText() { m.text = nil } +// SetName sets the "name" field. +func (m *TodoMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *TodoMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" 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) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ClearName clears the value of the "name" field. +func (m *TodoMutation) ClearName() { + m.name = nil + m.clearedFields[todo.FieldName] = struct{}{} +} + +// NameCleared returns if the "name" field was cleared in this mutation. +func (m *TodoMutation) NameCleared() bool { + _, ok := m.clearedFields[todo.FieldName] + return ok +} + +// ResetName resets all changes to the "name" field. +func (m *TodoMutation) ResetName() { + m.name = nil + delete(m.clearedFields, todo.FieldName) +} + // SetBlob sets the "blob" field. func (m *TodoMutation) SetBlob(b []byte) { m.blob = &b @@ -4302,7 +4352,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, 10) + fields := make([]string, 0, 11) if m.created_at != nil { fields = append(fields, todo.FieldCreatedAt) } @@ -4315,6 +4365,9 @@ func (m *TodoMutation) Fields() []string { if m.text != nil { fields = append(fields, todo.FieldText) } + if m.name != nil { + fields = append(fields, todo.FieldName) + } if m.blob != nil { fields = append(fields, todo.FieldBlob) } @@ -4349,6 +4402,8 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) { return m.Priority() case todo.FieldText: return m.Text() + case todo.FieldName: + return m.Name() case todo.FieldBlob: return m.Blob() case todo.FieldCategoryID: @@ -4378,6 +4433,8 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldPriority(ctx) case todo.FieldText: return m.OldText(ctx) + case todo.FieldName: + return m.OldName(ctx) case todo.FieldBlob: return m.OldBlob(ctx) case todo.FieldCategoryID: @@ -4427,6 +4484,13 @@ func (m *TodoMutation) SetField(name string, value ent.Value) error { } m.SetText(v) return nil + case todo.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil case todo.FieldBlob: v, ok := value.([]byte) if !ok { @@ -4526,6 +4590,9 @@ func (m *TodoMutation) AddField(name string, value ent.Value) error { // mutation. func (m *TodoMutation) ClearedFields() []string { var fields []string + if m.FieldCleared(todo.FieldName) { + fields = append(fields, todo.FieldName) + } if m.FieldCleared(todo.FieldBlob) { fields = append(fields, todo.FieldBlob) } @@ -4555,6 +4622,9 @@ func (m *TodoMutation) FieldCleared(name string) bool { // error if the field is not defined in the schema. func (m *TodoMutation) ClearField(name string) error { switch name { + case todo.FieldName: + m.ClearName() + return nil case todo.FieldBlob: m.ClearBlob() return nil @@ -4590,6 +4660,9 @@ func (m *TodoMutation) ResetField(name string) error { case todo.FieldText: m.ResetText() return nil + case todo.FieldName: + m.ResetName() + return nil case todo.FieldBlob: m.ResetBlob() return nil diff --git a/entgql/internal/todo/ent/runtime.go b/entgql/internal/todo/ent/runtime.go index 19e24fe28..0d8b602f9 100644 --- a/entgql/internal/todo/ent/runtime.go +++ b/entgql/internal/todo/ent/runtime.go @@ -72,7 +72,7 @@ func init() { // 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() + todoDescValue := todoFields[10].Descriptor() // todo.DefaultValue holds the default value on creation for the value field. todo.DefaultValue = todoDescValue.Default.(int) userFields := schema.User{}.Fields() diff --git a/entgql/internal/todo/ent/schema/todo.go b/entgql/internal/todo/ent/schema/todo.go index a0c6bca71..f7a0228ec 100644 --- a/entgql/internal/todo/ent/schema/todo.go +++ b/entgql/internal/todo/ent/schema/todo.go @@ -60,6 +60,11 @@ func (Todo) Fields() []ent.Field { Annotations( entgql.OrderField("TEXT"), ), + field.String("name"). + Optional(). + Annotations( + entgql.CollectedFor("uppercaseName"), + ), field.Bytes("blob"). Annotations( entgql.Skip(), diff --git a/entgql/internal/todo/ent/todo.go b/entgql/internal/todo/ent/todo.go index fe352ab24..a68640ecf 100644 --- a/entgql/internal/todo/ent/todo.go +++ b/entgql/internal/todo/ent/todo.go @@ -43,6 +43,8 @@ type Todo struct { Priority int `json:"priority,omitempty"` // Text holds the value of the "text" field. Text string `json:"text,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` // Blob holds the value of the "blob" field. Blob []byte `json:"blob,omitempty"` // CategoryID holds the value of the "category_id" field. @@ -134,7 +136,7 @@ func (*Todo) scanValues(columns []string) ([]any, error) { values[i] = new([]byte) case todo.FieldID, todo.FieldPriority, todo.FieldCategoryID, todo.FieldValue: values[i] = new(sql.NullInt64) - case todo.FieldStatus, todo.FieldText: + case todo.FieldStatus, todo.FieldText, todo.FieldName: values[i] = new(sql.NullString) case todo.FieldCreatedAt: values[i] = new(sql.NullTime) @@ -189,6 +191,12 @@ func (t *Todo) assignValues(columns []string, values []any) error { } else if value.Valid { t.Text = value.String } + case todo.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + t.Name = value.String + } case todo.FieldBlob: if value, ok := values[i].(*[]byte); !ok { return fmt.Errorf("unexpected type %T for field blob", values[i]) @@ -320,6 +328,9 @@ func (t *Todo) String() string { builder.WriteString("text=") builder.WriteString(t.Text) builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(t.Name) + builder.WriteString(", ") builder.WriteString("blob=") builder.WriteString(fmt.Sprintf("%v", t.Blob)) builder.WriteString(", ") diff --git a/entgql/internal/todo/ent/todo/todo.go b/entgql/internal/todo/ent/todo/todo.go index e386089d8..9ddc0f7cb 100644 --- a/entgql/internal/todo/ent/todo/todo.go +++ b/entgql/internal/todo/ent/todo/todo.go @@ -39,6 +39,8 @@ const ( FieldPriority = "priority" // FieldText holds the string denoting the text field in the database. FieldText = "text" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" // FieldBlob holds the string denoting the blob field in the database. FieldBlob = "blob" // FieldCategoryID holds the string denoting the category_id field in the database. @@ -92,6 +94,7 @@ var Columns = []string{ FieldStatus, FieldPriority, FieldText, + FieldName, FieldBlob, FieldCategoryID, FieldInit, @@ -186,6 +189,11 @@ func ByText(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldText, opts...).ToFunc() } +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, 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/todo/ent/todo/where.go b/entgql/internal/todo/ent/todo/where.go index e878e1ebf..f2e364459 100644 --- a/entgql/internal/todo/ent/todo/where.go +++ b/entgql/internal/todo/ent/todo/where.go @@ -84,6 +84,11 @@ func Text(v string) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldText, v)) } +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldName, v)) +} + // Blob applies equality check predicate on the "blob" field. It's identical to BlobEQ. func Blob(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) @@ -264,6 +269,81 @@ func TextContainsFold(v string) predicate.Todo { return predicate.Todo(sql.FieldContainsFold(FieldText, v)) } +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Todo { + return predicate.Todo(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Todo { + return predicate.Todo(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Todo { + return predicate.Todo(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Todo { + return predicate.Todo(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Todo { + return predicate.Todo(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Todo { + return predicate.Todo(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Todo { + return predicate.Todo(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Todo { + return predicate.Todo(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Todo { + return predicate.Todo(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Todo { + return predicate.Todo(sql.FieldHasSuffix(FieldName, v)) +} + +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.Todo { + return predicate.Todo(sql.FieldIsNull(FieldName)) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.Todo { + return predicate.Todo(sql.FieldNotNull(FieldName)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Todo { + return predicate.Todo(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Todo { + return predicate.Todo(sql.FieldContainsFold(FieldName, v)) +} + // BlobEQ applies the EQ predicate on the "blob" field. func BlobEQ(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) diff --git a/entgql/internal/todo/ent/todo_create.go b/entgql/internal/todo/ent/todo_create.go index 786717818..1e49c2bc5 100644 --- a/entgql/internal/todo/ent/todo_create.go +++ b/entgql/internal/todo/ent/todo_create.go @@ -77,6 +77,20 @@ func (tc *TodoCreate) SetText(s string) *TodoCreate { return tc } +// SetName sets the "name" field. +func (tc *TodoCreate) SetName(s string) *TodoCreate { + tc.mutation.SetName(s) + return tc +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tc *TodoCreate) SetNillableName(s *string) *TodoCreate { + if s != nil { + tc.SetName(*s) + } + return tc +} + // SetBlob sets the "blob" field. func (tc *TodoCreate) SetBlob(b []byte) *TodoCreate { tc.mutation.SetBlob(b) @@ -305,6 +319,10 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { _spec.SetField(todo.FieldText, field.TypeString, value) _node.Text = value } + if value, ok := tc.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + _node.Name = value + } if value, ok := tc.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) _node.Blob = value diff --git a/entgql/internal/todo/ent/todo_update.go b/entgql/internal/todo/ent/todo_update.go index 2af0849af..7bd0e72f2 100644 --- a/entgql/internal/todo/ent/todo_update.go +++ b/entgql/internal/todo/ent/todo_update.go @@ -94,6 +94,26 @@ func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { return tu } +// SetName sets the "name" field. +func (tu *TodoUpdate) SetName(s string) *TodoUpdate { + tu.mutation.SetName(s) + return tu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableName(s *string) *TodoUpdate { + if s != nil { + tu.SetName(*s) + } + return tu +} + +// ClearName clears the value of the "name" field. +func (tu *TodoUpdate) ClearName() *TodoUpdate { + tu.mutation.ClearName() + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -338,6 +358,12 @@ func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := tu.mutation.Text(); ok { _spec.SetField(todo.FieldText, field.TypeString, value) } + if value, ok := tu.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + } + if tu.mutation.NameCleared() { + _spec.ClearField(todo.FieldName, field.TypeString) + } if value, ok := tu.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) } @@ -552,6 +578,26 @@ func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { return tuo } +// SetName sets the "name" field. +func (tuo *TodoUpdateOne) SetName(s string) *TodoUpdateOne { + tuo.mutation.SetName(s) + return tuo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableName(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetName(*s) + } + return tuo +} + +// ClearName clears the value of the "name" field. +func (tuo *TodoUpdateOne) ClearName() *TodoUpdateOne { + tuo.mutation.ClearName() + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -826,6 +872,12 @@ func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) if value, ok := tuo.mutation.Text(); ok { _spec.SetField(todo.FieldText, field.TypeString, value) } + if value, ok := tuo.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + } + if tuo.mutation.NameCleared() { + _spec.ClearField(todo.FieldName, field.TypeString) + } if value, ok := tuo.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) } diff --git a/entgql/internal/todo/generated.go b/entgql/internal/todo/generated.go index d929674ac..59d8cf89b 100644 --- a/entgql/internal/todo/generated.go +++ b/entgql/internal/todo/generated.go @@ -209,10 +209,12 @@ type ComplexityRoot struct { ExtendedField func(childComplexity int) int ID func(childComplexity int) int Init func(childComplexity int) int + Name func(childComplexity int) int Parent func(childComplexity int) int Priority func(childComplexity int) int Status func(childComplexity int) int Text func(childComplexity int) int + UppercaseName func(childComplexity int) int Value func(childComplexity int) int } @@ -274,6 +276,7 @@ type QueryResolver interface { } type TodoResolver interface { ExtendedField(ctx context.Context, obj *ent.Todo) (*string, error) + UppercaseName(ctx context.Context, obj *ent.Todo) (*string, error) } type CreateCategoryInputResolver interface { @@ -975,6 +978,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Init(childComplexity), true + case "Todo.name": + if e.complexity.Todo.Name == nil { + break + } + + return e.complexity.Todo.Name(childComplexity), true + case "Todo.parent": if e.complexity.Todo.Parent == nil { break @@ -1003,6 +1013,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Text(childComplexity), true + case "Todo.uppercaseName": + if e.complexity.Todo.UppercaseName == nil { + break + } + + return e.complexity.Todo.UppercaseName(childComplexity), true + case "Todo.value": if e.complexity.Todo.Value == nil { break @@ -5777,6 +5794,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -5799,6 +5818,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -5866,6 +5887,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -5888,6 +5911,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -7795,6 +7820,47 @@ func (ec *executionContext) fieldContext_Todo_text(_ context.Context, field grap return fc, nil } +func (ec *executionContext) _Todo_name(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_name(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_name(_ 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 String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Todo_categoryID(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Todo_categoryID(ctx, field) if err != nil { @@ -8139,6 +8205,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -8161,6 +8229,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -8337,6 +8407,47 @@ func (ec *executionContext) fieldContext_Todo_extendedField(_ context.Context, f return fc, nil } +func (ec *executionContext) _Todo_uppercaseName(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_uppercaseName(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Todo().UppercaseName(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_uppercaseName(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Todo", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _TodoConnection_edges(ctx context.Context, field graphql.CollectedField, obj *ent.TodoConnection) (ret graphql.Marshaler) { fc, err := ec.fieldContext_TodoConnection_edges(ctx, field) if err != nil { @@ -8528,6 +8639,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -8550,6 +8663,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -12186,7 +12301,7 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} + fieldsInOrder := [...]string{"status", "priority", "text", "name", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -12214,6 +12329,13 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o return it, err } it.Text = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data case "init": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("init")) data, err := ec.unmarshalOMap2map(ctx, v) @@ -13389,7 +13511,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", "value", "valueNEQ", "valueIn", "valueNotIn", "valueGT", "valueGTE", "valueLT", "valueLTE", "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", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameIsNil", "nameNotNil", "nameEqualFold", "nameContainsFold", "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 { @@ -13704,6 +13826,111 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob return it, err } it.TextContainsFold = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "nameNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameNEQ = data + case "nameIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.NameIn = data + case "nameNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.NameNotIn = data + case "nameGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameGT = data + case "nameGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameGTE = data + case "nameLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameLT = data + case "nameLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameLTE = data + case "nameContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameContains = data + case "nameHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameHasPrefix = data + case "nameHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameHasSuffix = data + case "nameIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameIsNil = data + case "nameNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameNotNil = data + case "nameEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameEqualFold = data + case "nameContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameContainsFold = data case "categoryID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("categoryID")) data, err := ec.unmarshalOID2ᚖint(ctx, v) @@ -14060,7 +14287,7 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} + fieldsInOrder := [...]string{"status", "priority", "text", "name", "clearName", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -14088,6 +14315,20 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o return it, err } it.Text = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "clearName": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearName")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearName = data case "init": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("init")) data, err := ec.unmarshalOMap2map(ctx, v) @@ -16217,6 +16458,8 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&out.Invalids, 1) } + case "name": + out.Values[i] = ec._Todo_name(ctx, field, obj) case "categoryID": out.Values[i] = ec._Todo_categoryID(ctx, field, obj) case "category_id": @@ -16368,6 +16611,39 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj continue } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "uppercaseName": + field := field + + innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Todo_uppercaseName(ctx, field, obj) + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) diff --git a/entgql/internal/todo/todo.graphql b/entgql/internal/todo/todo.graphql index 12d192821..9b6cf17b5 100644 --- a/entgql/internal/todo/todo.graphql +++ b/entgql/internal/todo/todo.graphql @@ -32,6 +32,7 @@ extend type Category { extend type Todo { extendedField: String + uppercaseName: String } extend type Query { diff --git a/entgql/internal/todo/todo.resolvers.go b/entgql/internal/todo/todo.resolvers.go index c86a21d18..e5e272c28 100644 --- a/entgql/internal/todo/todo.resolvers.go +++ b/entgql/internal/todo/todo.resolvers.go @@ -20,6 +20,7 @@ package todo import ( "context" + "strings" "time" "entgo.io/contrib/entgql" @@ -107,6 +108,12 @@ func (r *todoResolver) ExtendedField(ctx context.Context, obj *ent.Todo) (*strin return &obj.Text, nil } +// UppercaseName is the resolver for the uppercaseName field. +func (r *todoResolver) UppercaseName(ctx context.Context, obj *ent.Todo) (*string, error) { + v := strings.ToUpper(obj.Name) + return &v, nil +} + // CreateTodos is the resolver for the createTodos field. func (r *createCategoryInputResolver) CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error { e := ent.FromContext(ctx) diff --git a/entgql/internal/todo/todo_test.go b/entgql/internal/todo/todo_test.go index 7e2136c7b..57dc78858 100644 --- a/entgql/internal/todo/todo_test.go +++ b/entgql/internal/todo/todo_test.go @@ -2580,7 +2580,7 @@ func TestFieldSelection(t *testing.T) { require.Equal(t, []string{ // Unknown fields enforce query all columns. "SELECT `todos`.`id`, `todos`.`created_at`, `todos`.`status`, " + - "`todos`.`priority`, `todos`.`text`, `todos`.`blob`, " + + "`todos`.`priority`, `todos`.`text`, `todos`.`name`, `todos`.`blob`, " + "`todos`.`category_id`, `todos`.`init`, `todos`.`custom`, " + "`todos`.`customp`, `todos`.`value` FROM `todos` ORDER BY `todos`.`id`", }, rec.queries) @@ -2632,6 +2632,39 @@ func TestFieldSelection(t *testing.T) { "SELECT `one_to_manies`.`id`, `one_to_manies`.`name` FROM `one_to_manies` ORDER BY `one_to_manies`.`id`", "SELECT `one_to_manies`.`id`, `one_to_manies`.`name`, `one_to_manies`.`parent_id` FROM `one_to_manies` WHERE `one_to_manies`.`parent_id` IN (?, ?, ?, ?, ?, ?)", }, rec.queries) + + // Test the CollectedFor annotation. + ec.Todo.Create().SetText("test").SetName("hello").SetStatus(todo.StatusCompleted).SaveX(ctx) + var ( + // language=GraphQL + query5 = `query { + todos (where: {name: "hello"}) { + edges { + node { + uppercaseName + } + } + } + }` + rsp5 struct { + Todos struct { + Edges []struct { + Node struct { + UppercaseName *string + } + } + } + } + ) + rec.reset() + client.New(handler.NewDefaultServer(gen.NewSchema(ec))). + MustPost(query5, &rsp5) + require.Equal(t, []string{ + "SELECT `todos`.`id`, `todos`.`name` FROM `todos` WHERE `todos`.`name` = ? ORDER BY `todos`.`id`", + }, rec.queries) + require.Len(t, rsp5.Todos.Edges, 1) + require.NotNil(t, rsp5.Todos.Edges[0].Node.UppercaseName) + require.Equal(t, "HELLO", *rsp5.Todos.Edges[0].Node.UppercaseName) } func TestOrderByEdgeCount(t *testing.T) { diff --git a/entgql/internal/todogotype/ent/gql_collection.go b/entgql/internal/todogotype/ent/gql_collection.go index c83416444..623b23347 100644 --- a/entgql/internal/todogotype/ent/gql_collection.go +++ b/entgql/internal/todogotype/ent/gql_collection.go @@ -908,6 +908,11 @@ func (tq *TodoQuery) collectField(ctx context.Context, oneNode bool, opCtx *grap selectedFields = append(selectedFields, todo.FieldText) fieldSeen[todo.FieldText] = struct{}{} } + case "name", "uppercaseName": + if _, ok := fieldSeen[todo.FieldName]; !ok { + selectedFields = append(selectedFields, todo.FieldName) + fieldSeen[todo.FieldName] = struct{}{} + } case "init": if _, ok := fieldSeen[todo.FieldInit]; !ok { selectedFields = append(selectedFields, todo.FieldInit) diff --git a/entgql/internal/todogotype/ent/gql_mutation_input.go b/entgql/internal/todogotype/ent/gql_mutation_input.go index 8e8c3bd79..8eaef15e0 100644 --- a/entgql/internal/todogotype/ent/gql_mutation_input.go +++ b/entgql/internal/todogotype/ent/gql_mutation_input.go @@ -172,6 +172,7 @@ type CreateTodoInput struct { Status todo.Status Priority *int Text string + Name *string Init map[string]interface{} Value *int ParentID *string @@ -187,6 +188,9 @@ func (i *CreateTodoInput) Mutate(m *TodoMutation) { m.SetPriority(*v) } m.SetText(i.Text) + if v := i.Name; v != nil { + m.SetName(*v) + } if v := i.Init; v != nil { m.SetInit(v) } @@ -218,6 +222,8 @@ type UpdateTodoInput struct { Status *todo.Status Priority *int Text *string + ClearName bool + Name *string ClearInit bool Init map[string]interface{} Value *int @@ -241,6 +247,12 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) { if v := i.Text; v != nil { m.SetText(*v) } + if i.ClearName { + m.ClearName() + } + if v := i.Name; v != nil { + m.SetName(*v) + } if i.ClearInit { m.ClearInit() } diff --git a/entgql/internal/todogotype/ent/gql_where_input.go b/entgql/internal/todogotype/ent/gql_where_input.go index afc822e43..c90e163c1 100644 --- a/entgql/internal/todogotype/ent/gql_where_input.go +++ b/entgql/internal/todogotype/ent/gql_where_input.go @@ -1438,6 +1438,23 @@ type TodoWhereInput struct { TextEqualFold *string `json:"textEqualFold,omitempty"` TextContainsFold *string `json:"textContainsFold,omitempty"` + // "name" field predicates. + Name *string `json:"name,omitempty"` + NameNEQ *string `json:"nameNEQ,omitempty"` + NameIn []string `json:"nameIn,omitempty"` + NameNotIn []string `json:"nameNotIn,omitempty"` + NameGT *string `json:"nameGT,omitempty"` + NameGTE *string `json:"nameGTE,omitempty"` + NameLT *string `json:"nameLT,omitempty"` + NameLTE *string `json:"nameLTE,omitempty"` + NameContains *string `json:"nameContains,omitempty"` + NameHasPrefix *string `json:"nameHasPrefix,omitempty"` + NameHasSuffix *string `json:"nameHasSuffix,omitempty"` + NameIsNil bool `json:"nameIsNil,omitempty"` + NameNotNil bool `json:"nameNotNil,omitempty"` + NameEqualFold *string `json:"nameEqualFold,omitempty"` + NameContainsFold *string `json:"nameContainsFold,omitempty"` + // "value" field predicates. Value *int `json:"value,omitempty"` ValueNEQ *int `json:"valueNEQ,omitempty"` @@ -1678,6 +1695,51 @@ func (i *TodoWhereInput) P() (predicate.Todo, error) { if i.TextContainsFold != nil { predicates = append(predicates, todo.TextContainsFold(*i.TextContainsFold)) } + if i.Name != nil { + predicates = append(predicates, todo.NameEQ(*i.Name)) + } + if i.NameNEQ != nil { + predicates = append(predicates, todo.NameNEQ(*i.NameNEQ)) + } + if len(i.NameIn) > 0 { + predicates = append(predicates, todo.NameIn(i.NameIn...)) + } + if len(i.NameNotIn) > 0 { + predicates = append(predicates, todo.NameNotIn(i.NameNotIn...)) + } + if i.NameGT != nil { + predicates = append(predicates, todo.NameGT(*i.NameGT)) + } + if i.NameGTE != nil { + predicates = append(predicates, todo.NameGTE(*i.NameGTE)) + } + if i.NameLT != nil { + predicates = append(predicates, todo.NameLT(*i.NameLT)) + } + if i.NameLTE != nil { + predicates = append(predicates, todo.NameLTE(*i.NameLTE)) + } + if i.NameContains != nil { + predicates = append(predicates, todo.NameContains(*i.NameContains)) + } + if i.NameHasPrefix != nil { + predicates = append(predicates, todo.NameHasPrefix(*i.NameHasPrefix)) + } + if i.NameHasSuffix != nil { + predicates = append(predicates, todo.NameHasSuffix(*i.NameHasSuffix)) + } + if i.NameIsNil { + predicates = append(predicates, todo.NameIsNil()) + } + if i.NameNotNil { + predicates = append(predicates, todo.NameNotNil()) + } + if i.NameEqualFold != nil { + predicates = append(predicates, todo.NameEqualFold(*i.NameEqualFold)) + } + if i.NameContainsFold != nil { + predicates = append(predicates, todo.NameContainsFold(*i.NameContainsFold)) + } if i.Value != nil { predicates = append(predicates, todo.ValueEQ(*i.Value)) } diff --git a/entgql/internal/todogotype/ent/migrate/schema.go b/entgql/internal/todogotype/ent/migrate/schema.go index 5de7e7923..de6be0511 100644 --- a/entgql/internal/todogotype/ent/migrate/schema.go +++ b/entgql/internal/todogotype/ent/migrate/schema.go @@ -115,6 +115,7 @@ var ( {Name: "status", Type: field.TypeEnum, Enums: []string{"IN_PROGRESS", "COMPLETED", "PENDING"}}, {Name: "priority", Type: field.TypeInt, Default: 0}, {Name: "text", Type: field.TypeString, Size: 2147483647}, + {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "blob", Type: field.TypeBytes, Nullable: true}, {Name: "init", Type: field.TypeJSON, Nullable: true}, {Name: "custom", Type: field.TypeJSON, Nullable: true}, @@ -132,19 +133,19 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "todos_categories_todos", - Columns: []*schema.Column{TodosColumns[10]}, + Columns: []*schema.Column{TodosColumns[11]}, RefColumns: []*schema.Column{CategoriesColumns[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/todogotype/ent/mutation.go b/entgql/internal/todogotype/ent/mutation.go index 17b942936..e36a7b433 100644 --- a/entgql/internal/todogotype/ent/mutation.go +++ b/entgql/internal/todogotype/ent/mutation.go @@ -2849,6 +2849,7 @@ type TodoMutation struct { priority *int addpriority *int text *string + name *string blob *[]byte init *map[string]interface{} custom *[]customstruct.Custom @@ -3140,6 +3141,55 @@ func (m *TodoMutation) ResetText() { m.text = nil } +// SetName sets the "name" field. +func (m *TodoMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *TodoMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" 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) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ClearName clears the value of the "name" field. +func (m *TodoMutation) ClearName() { + m.name = nil + m.clearedFields[todo.FieldName] = struct{}{} +} + +// NameCleared returns if the "name" field was cleared in this mutation. +func (m *TodoMutation) NameCleared() bool { + _, ok := m.clearedFields[todo.FieldName] + return ok +} + +// ResetName resets all changes to the "name" field. +func (m *TodoMutation) ResetName() { + m.name = nil + delete(m.clearedFields, todo.FieldName) +} + // SetBlob sets the "blob" field. func (m *TodoMutation) SetBlob(b []byte) { m.blob = &b @@ -3666,7 +3716,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, 10) + fields := make([]string, 0, 11) if m.created_at != nil { fields = append(fields, todo.FieldCreatedAt) } @@ -3679,6 +3729,9 @@ func (m *TodoMutation) Fields() []string { if m.text != nil { fields = append(fields, todo.FieldText) } + if m.name != nil { + fields = append(fields, todo.FieldName) + } if m.blob != nil { fields = append(fields, todo.FieldBlob) } @@ -3713,6 +3766,8 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) { return m.Priority() case todo.FieldText: return m.Text() + case todo.FieldName: + return m.Name() case todo.FieldBlob: return m.Blob() case todo.FieldInit: @@ -3742,6 +3797,8 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldPriority(ctx) case todo.FieldText: return m.OldText(ctx) + case todo.FieldName: + return m.OldName(ctx) case todo.FieldBlob: return m.OldBlob(ctx) case todo.FieldInit: @@ -3791,6 +3848,13 @@ func (m *TodoMutation) SetField(name string, value ent.Value) error { } m.SetText(v) return nil + case todo.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil case todo.FieldBlob: v, ok := value.([]byte) if !ok { @@ -3890,6 +3954,9 @@ func (m *TodoMutation) AddField(name string, value ent.Value) error { // mutation. func (m *TodoMutation) ClearedFields() []string { var fields []string + if m.FieldCleared(todo.FieldName) { + fields = append(fields, todo.FieldName) + } if m.FieldCleared(todo.FieldBlob) { fields = append(fields, todo.FieldBlob) } @@ -3919,6 +3986,9 @@ func (m *TodoMutation) FieldCleared(name string) bool { // error if the field is not defined in the schema. func (m *TodoMutation) ClearField(name string) error { switch name { + case todo.FieldName: + m.ClearName() + return nil case todo.FieldBlob: m.ClearBlob() return nil @@ -3954,6 +4024,9 @@ func (m *TodoMutation) ResetField(name string) error { case todo.FieldText: m.ResetText() return nil + case todo.FieldName: + m.ResetName() + return nil case todo.FieldBlob: m.ResetBlob() return nil diff --git a/entgql/internal/todogotype/ent/runtime.go b/entgql/internal/todogotype/ent/runtime.go index 231db679f..009049a48 100644 --- a/entgql/internal/todogotype/ent/runtime.go +++ b/entgql/internal/todogotype/ent/runtime.go @@ -83,7 +83,7 @@ func init() { // 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() + todoDescValue := todoMixinFields0[9].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. diff --git a/entgql/internal/todogotype/ent/todo.go b/entgql/internal/todogotype/ent/todo.go index 98a094666..00f4e28f9 100644 --- a/entgql/internal/todogotype/ent/todo.go +++ b/entgql/internal/todogotype/ent/todo.go @@ -44,6 +44,8 @@ type Todo struct { Priority int `json:"priority,omitempty"` // Text holds the value of the "text" field. Text string `json:"text,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` // Blob holds the value of the "blob" field. Blob []byte `json:"blob,omitempty"` // Init holds the value of the "init" field. @@ -136,7 +138,7 @@ func (*Todo) scanValues(columns []string) ([]any, error) { values[i] = new(bigintgql.BigInt) case todo.FieldPriority, todo.FieldValue: values[i] = new(sql.NullInt64) - case todo.FieldID, todo.FieldStatus, todo.FieldText: + case todo.FieldID, todo.FieldStatus, todo.FieldText, todo.FieldName: values[i] = new(sql.NullString) case todo.FieldCreatedAt: values[i] = new(sql.NullTime) @@ -189,6 +191,12 @@ func (t *Todo) assignValues(columns []string, values []any) error { } else if value.Valid { t.Text = value.String } + case todo.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + t.Name = value.String + } case todo.FieldBlob: if value, ok := values[i].(*[]byte); !ok { return fmt.Errorf("unexpected type %T for field blob", values[i]) @@ -313,6 +321,9 @@ func (t *Todo) String() string { builder.WriteString("text=") builder.WriteString(t.Text) builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(t.Name) + builder.WriteString(", ") builder.WriteString("blob=") builder.WriteString(fmt.Sprintf("%v", t.Blob)) builder.WriteString(", ") diff --git a/entgql/internal/todogotype/ent/todo/todo.go b/entgql/internal/todogotype/ent/todo/todo.go index 856aea50c..18ee86b07 100644 --- a/entgql/internal/todogotype/ent/todo/todo.go +++ b/entgql/internal/todogotype/ent/todo/todo.go @@ -39,6 +39,8 @@ const ( FieldPriority = "priority" // FieldText holds the string denoting the text field in the database. FieldText = "text" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" // FieldBlob holds the string denoting the blob field in the database. FieldBlob = "blob" // FieldInit holds the string denoting the init field in the database. @@ -92,6 +94,7 @@ var Columns = []string{ FieldStatus, FieldPriority, FieldText, + FieldName, FieldBlob, FieldInit, FieldCustom, @@ -187,6 +190,11 @@ func ByText(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldText, opts...).ToFunc() } +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + // ByValue orders the results by the value field. func ByValue(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldValue, opts...).ToFunc() diff --git a/entgql/internal/todogotype/ent/todo/where.go b/entgql/internal/todogotype/ent/todo/where.go index ddb5d15ab..dc555c758 100644 --- a/entgql/internal/todogotype/ent/todo/where.go +++ b/entgql/internal/todogotype/ent/todo/where.go @@ -95,6 +95,11 @@ func Text(v string) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldText, v)) } +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldName, v)) +} + // Blob applies equality check predicate on the "blob" field. It's identical to BlobEQ. func Blob(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) @@ -275,6 +280,81 @@ func TextContainsFold(v string) predicate.Todo { return predicate.Todo(sql.FieldContainsFold(FieldText, v)) } +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Todo { + return predicate.Todo(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Todo { + return predicate.Todo(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Todo { + return predicate.Todo(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Todo { + return predicate.Todo(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Todo { + return predicate.Todo(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Todo { + return predicate.Todo(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Todo { + return predicate.Todo(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Todo { + return predicate.Todo(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Todo { + return predicate.Todo(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Todo { + return predicate.Todo(sql.FieldHasSuffix(FieldName, v)) +} + +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.Todo { + return predicate.Todo(sql.FieldIsNull(FieldName)) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.Todo { + return predicate.Todo(sql.FieldNotNull(FieldName)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Todo { + return predicate.Todo(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Todo { + return predicate.Todo(sql.FieldContainsFold(FieldName, v)) +} + // BlobEQ applies the EQ predicate on the "blob" field. func BlobEQ(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) diff --git a/entgql/internal/todogotype/ent/todo_create.go b/entgql/internal/todogotype/ent/todo_create.go index 8c2824bd5..8e24d35d9 100644 --- a/entgql/internal/todogotype/ent/todo_create.go +++ b/entgql/internal/todogotype/ent/todo_create.go @@ -78,6 +78,20 @@ func (tc *TodoCreate) SetText(s string) *TodoCreate { return tc } +// SetName sets the "name" field. +func (tc *TodoCreate) SetName(s string) *TodoCreate { + tc.mutation.SetName(s) + return tc +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tc *TodoCreate) SetNillableName(s *string) *TodoCreate { + if s != nil { + tc.SetName(*s) + } + return tc +} + // SetBlob sets the "blob" field. func (tc *TodoCreate) SetBlob(b []byte) *TodoCreate { tc.mutation.SetBlob(b) @@ -333,6 +347,10 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { _spec.SetField(todo.FieldText, field.TypeString, value) _node.Text = value } + if value, ok := tc.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + _node.Name = value + } if value, ok := tc.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) _node.Blob = value diff --git a/entgql/internal/todogotype/ent/todo_update.go b/entgql/internal/todogotype/ent/todo_update.go index ed65eba73..5267a4a5d 100644 --- a/entgql/internal/todogotype/ent/todo_update.go +++ b/entgql/internal/todogotype/ent/todo_update.go @@ -93,6 +93,26 @@ func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { return tu } +// SetName sets the "name" field. +func (tu *TodoUpdate) SetName(s string) *TodoUpdate { + tu.mutation.SetName(s) + return tu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableName(s *string) *TodoUpdate { + if s != nil { + tu.SetName(*s) + } + return tu +} + +// ClearName clears the value of the "name" field. +func (tu *TodoUpdate) ClearName() *TodoUpdate { + tu.mutation.ClearName() + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -331,6 +351,12 @@ func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := tu.mutation.Text(); ok { _spec.SetField(todo.FieldText, field.TypeString, value) } + if value, ok := tu.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + } + if tu.mutation.NameCleared() { + _spec.ClearField(todo.FieldName, field.TypeString) + } if value, ok := tu.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) } @@ -543,6 +569,26 @@ func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { return tuo } +// SetName sets the "name" field. +func (tuo *TodoUpdateOne) SetName(s string) *TodoUpdateOne { + tuo.mutation.SetName(s) + return tuo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableName(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetName(*s) + } + return tuo +} + +// ClearName clears the value of the "name" field. +func (tuo *TodoUpdateOne) ClearName() *TodoUpdateOne { + tuo.mutation.ClearName() + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -811,6 +857,12 @@ func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) if value, ok := tuo.mutation.Text(); ok { _spec.SetField(todo.FieldText, field.TypeString, value) } + if value, ok := tuo.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + } + if tuo.mutation.NameCleared() { + _spec.ClearField(todo.FieldName, field.TypeString) + } if value, ok := tuo.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) } diff --git a/entgql/internal/todogotype/generated.go b/entgql/internal/todogotype/generated.go index 7b7091bad..8a3b8cfa2 100644 --- a/entgql/internal/todogotype/generated.go +++ b/entgql/internal/todogotype/generated.go @@ -214,10 +214,12 @@ type ComplexityRoot struct { ExtendedField func(childComplexity int) int ID func(childComplexity int) int Init func(childComplexity int) int + Name func(childComplexity int) int Parent func(childComplexity int) int Priority func(childComplexity int) int Status func(childComplexity int) int Text func(childComplexity int) int + UppercaseName func(childComplexity int) int Value func(childComplexity int) int } @@ -286,6 +288,7 @@ type TodoResolver interface { Status(ctx context.Context, obj *ent.Todo) (todo.Status, error) ExtendedField(ctx context.Context, obj *ent.Todo) (*string, error) + UppercaseName(ctx context.Context, obj *ent.Todo) (*string, error) } type UserResolver interface { Username(ctx context.Context, obj *ent.User) (string, error) @@ -1021,6 +1024,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Init(childComplexity), true + case "Todo.name": + if e.complexity.Todo.Name == nil { + break + } + + return e.complexity.Todo.Name(childComplexity), true + case "Todo.parent": if e.complexity.Todo.Parent == nil { break @@ -1049,6 +1059,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Text(childComplexity), true + case "Todo.uppercaseName": + if e.complexity.Todo.UppercaseName == nil { + break + } + + return e.complexity.Todo.UppercaseName(childComplexity), true + case "Todo.value": if e.complexity.Todo.Value == nil { break @@ -1358,6 +1375,7 @@ extend type Category { extend type Todo { extendedField: String + uppercaseName: String } extend type Query { @@ -1726,6 +1744,7 @@ input CreateTodoInput { status: TodoStatus! priority: Int text: String! + name: String init: Map value: Int parentID: ID @@ -2378,6 +2397,7 @@ type Todo implements Node { status: TodoStatus! priorityOrder: Int! @goField(name: "Priority", forceResolver: false) text: String! + name: String categoryID: ID category_id: ID categoryX: ID @goField(name: "CategoryID", forceResolver: false) @@ -2547,6 +2567,24 @@ input TodoWhereInput { textEqualFold: String textContainsFold: String """ + name field predicates + """ + name: String + nameNEQ: String + nameIn: [String!] + nameNotIn: [String!] + nameGT: String + nameGTE: String + nameLT: String + nameLTE: String + nameContains: String + nameHasPrefix: String + nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean + nameEqualFold: String + nameContainsFold: String + """ category_id field predicates """ categoryID: ID @@ -2628,6 +2666,8 @@ input UpdateTodoInput { status: TodoStatus priority: Int text: String + name: String + clearName: Boolean init: Map clearInit: Boolean value: Int @@ -7346,6 +7386,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -7368,6 +7410,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -7435,6 +7479,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -7457,6 +7503,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -9364,6 +9412,47 @@ func (ec *executionContext) fieldContext_Todo_text(_ context.Context, field grap return fc, nil } +func (ec *executionContext) _Todo_name(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_name(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_name(_ 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 String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Todo_categoryID(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Todo_categoryID(ctx, field) if err != nil { @@ -9708,6 +9797,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -9730,6 +9821,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -9906,6 +9999,47 @@ func (ec *executionContext) fieldContext_Todo_extendedField(_ context.Context, f return fc, nil } +func (ec *executionContext) _Todo_uppercaseName(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_uppercaseName(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Todo().UppercaseName(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_uppercaseName(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Todo", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _TodoConnection_edges(ctx context.Context, field graphql.CollectedField, obj *ent.TodoConnection) (ret graphql.Marshaler) { fc, err := ec.fieldContext_TodoConnection_edges(ctx, field) if err != nil { @@ -10097,6 +10231,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -10119,6 +10255,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -13757,7 +13895,7 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} + fieldsInOrder := [...]string{"status", "priority", "text", "name", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -13787,6 +13925,13 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o return it, err } it.Text = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data case "init": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("init")) data, err := ec.unmarshalOMap2map(ctx, v) @@ -14962,7 +15107,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", "value", "valueNEQ", "valueIn", "valueNotIn", "valueGT", "valueGTE", "valueLT", "valueLTE", "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", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameIsNil", "nameNotNil", "nameEqualFold", "nameContainsFold", "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 { @@ -15285,6 +15430,111 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob return it, err } it.TextContainsFold = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "nameNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameNEQ = data + case "nameIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.NameIn = data + case "nameNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.NameNotIn = data + case "nameGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameGT = data + case "nameGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameGTE = data + case "nameLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameLT = data + case "nameLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameLTE = data + case "nameContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameContains = data + case "nameHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameHasPrefix = data + case "nameHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameHasSuffix = data + case "nameIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameIsNil = data + case "nameNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameNotNil = data + case "nameEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameEqualFold = data + case "nameContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameContainsFold = data case "categoryID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("categoryID")) data, err := ec.unmarshalOID2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚋschemaᚋbigintgqlᚐBigInt(ctx, v) @@ -15643,7 +15893,7 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} + fieldsInOrder := [...]string{"status", "priority", "text", "name", "clearName", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -15673,6 +15923,20 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o return it, err } it.Text = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "clearName": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearName")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearName = data case "init": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("init")) data, err := ec.unmarshalOMap2map(ctx, v) @@ -17822,6 +18086,8 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&out.Invalids, 1) } + case "name": + out.Values[i] = ec._Todo_name(ctx, field, obj) case "categoryID": out.Values[i] = ec._Todo_categoryID(ctx, field, obj) case "category_id": @@ -17973,6 +18239,39 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj continue } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "uppercaseName": + field := field + + innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Todo_uppercaseName(ctx, field, obj) + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) @@ -20684,6 +20983,16 @@ func (ec *executionContext) unmarshalOProjectWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v any) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + return res +} + func (ec *executionContext) unmarshalOString2ᚕstringᚄ(ctx context.Context, v any) ([]string, error) { if v == nil { return nil, nil diff --git a/entgql/internal/todogotype/todo.resolvers.go b/entgql/internal/todogotype/todo.resolvers.go index c39368d3b..adc52564a 100644 --- a/entgql/internal/todogotype/todo.resolvers.go +++ b/entgql/internal/todogotype/todo.resolvers.go @@ -71,6 +71,11 @@ func (r *todoResolver) ExtendedField(ctx context.Context, obj *ent.Todo) (*strin panic(fmt.Errorf("not implemented")) } +// UppercaseName is the resolver for the uppercaseName field. +func (r *todoResolver) UppercaseName(ctx context.Context, obj *ent.Todo) (*string, error) { + panic(fmt.Errorf("not implemented: UppercaseName - uppercaseName")) +} + // CreateTodos is the resolver for the createTodos field. func (r *createCategoryInputResolver) CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error { panic(fmt.Errorf("not implemented")) diff --git a/entgql/internal/todopulid/ent/gql_collection.go b/entgql/internal/todopulid/ent/gql_collection.go index 22d5fdf20..902886edc 100644 --- a/entgql/internal/todopulid/ent/gql_collection.go +++ b/entgql/internal/todopulid/ent/gql_collection.go @@ -840,6 +840,11 @@ func (tq *TodoQuery) collectField(ctx context.Context, oneNode bool, opCtx *grap selectedFields = append(selectedFields, todo.FieldText) fieldSeen[todo.FieldText] = struct{}{} } + case "name", "uppercaseName": + if _, ok := fieldSeen[todo.FieldName]; !ok { + selectedFields = append(selectedFields, todo.FieldName) + fieldSeen[todo.FieldName] = struct{}{} + } case "init": if _, ok := fieldSeen[todo.FieldInit]; !ok { selectedFields = append(selectedFields, todo.FieldInit) diff --git a/entgql/internal/todopulid/ent/gql_mutation_input.go b/entgql/internal/todopulid/ent/gql_mutation_input.go index d474c7794..2871d3157 100644 --- a/entgql/internal/todopulid/ent/gql_mutation_input.go +++ b/entgql/internal/todopulid/ent/gql_mutation_input.go @@ -173,6 +173,7 @@ type CreateTodoInput struct { Status todo.Status Priority *int Text string + Name *string Init map[string]interface{} Value *int ParentID *pulid.ID @@ -188,6 +189,9 @@ func (i *CreateTodoInput) Mutate(m *TodoMutation) { m.SetPriority(*v) } m.SetText(i.Text) + if v := i.Name; v != nil { + m.SetName(*v) + } if v := i.Init; v != nil { m.SetInit(v) } @@ -219,6 +223,8 @@ type UpdateTodoInput struct { Status *todo.Status Priority *int Text *string + ClearName bool + Name *string ClearInit bool Init map[string]interface{} Value *int @@ -242,6 +248,12 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) { if v := i.Text; v != nil { m.SetText(*v) } + if i.ClearName { + m.ClearName() + } + if v := i.Name; v != nil { + m.SetName(*v) + } if i.ClearInit { m.ClearInit() } diff --git a/entgql/internal/todopulid/ent/gql_where_input.go b/entgql/internal/todopulid/ent/gql_where_input.go index f366294c5..9b365ff6d 100644 --- a/entgql/internal/todopulid/ent/gql_where_input.go +++ b/entgql/internal/todopulid/ent/gql_where_input.go @@ -1233,6 +1233,23 @@ type TodoWhereInput struct { TextEqualFold *string `json:"textEqualFold,omitempty"` TextContainsFold *string `json:"textContainsFold,omitempty"` + // "name" field predicates. + Name *string `json:"name,omitempty"` + NameNEQ *string `json:"nameNEQ,omitempty"` + NameIn []string `json:"nameIn,omitempty"` + NameNotIn []string `json:"nameNotIn,omitempty"` + NameGT *string `json:"nameGT,omitempty"` + NameGTE *string `json:"nameGTE,omitempty"` + NameLT *string `json:"nameLT,omitempty"` + NameLTE *string `json:"nameLTE,omitempty"` + NameContains *string `json:"nameContains,omitempty"` + NameHasPrefix *string `json:"nameHasPrefix,omitempty"` + NameHasSuffix *string `json:"nameHasSuffix,omitempty"` + NameIsNil bool `json:"nameIsNil,omitempty"` + NameNotNil bool `json:"nameNotNil,omitempty"` + NameEqualFold *string `json:"nameEqualFold,omitempty"` + NameContainsFold *string `json:"nameContainsFold,omitempty"` + // "value" field predicates. Value *int `json:"value,omitempty"` ValueNEQ *int `json:"valueNEQ,omitempty"` @@ -1467,6 +1484,51 @@ func (i *TodoWhereInput) P() (predicate.Todo, error) { if i.TextContainsFold != nil { predicates = append(predicates, todo.TextContainsFold(*i.TextContainsFold)) } + if i.Name != nil { + predicates = append(predicates, todo.NameEQ(*i.Name)) + } + if i.NameNEQ != nil { + predicates = append(predicates, todo.NameNEQ(*i.NameNEQ)) + } + if len(i.NameIn) > 0 { + predicates = append(predicates, todo.NameIn(i.NameIn...)) + } + if len(i.NameNotIn) > 0 { + predicates = append(predicates, todo.NameNotIn(i.NameNotIn...)) + } + if i.NameGT != nil { + predicates = append(predicates, todo.NameGT(*i.NameGT)) + } + if i.NameGTE != nil { + predicates = append(predicates, todo.NameGTE(*i.NameGTE)) + } + if i.NameLT != nil { + predicates = append(predicates, todo.NameLT(*i.NameLT)) + } + if i.NameLTE != nil { + predicates = append(predicates, todo.NameLTE(*i.NameLTE)) + } + if i.NameContains != nil { + predicates = append(predicates, todo.NameContains(*i.NameContains)) + } + if i.NameHasPrefix != nil { + predicates = append(predicates, todo.NameHasPrefix(*i.NameHasPrefix)) + } + if i.NameHasSuffix != nil { + predicates = append(predicates, todo.NameHasSuffix(*i.NameHasSuffix)) + } + if i.NameIsNil { + predicates = append(predicates, todo.NameIsNil()) + } + if i.NameNotNil { + predicates = append(predicates, todo.NameNotNil()) + } + if i.NameEqualFold != nil { + predicates = append(predicates, todo.NameEqualFold(*i.NameEqualFold)) + } + if i.NameContainsFold != nil { + predicates = append(predicates, todo.NameContainsFold(*i.NameContainsFold)) + } if i.Value != nil { predicates = append(predicates, todo.ValueEQ(*i.Value)) } diff --git a/entgql/internal/todopulid/ent/migrate/schema.go b/entgql/internal/todopulid/ent/migrate/schema.go index 32833b914..5353cd32c 100644 --- a/entgql/internal/todopulid/ent/migrate/schema.go +++ b/entgql/internal/todopulid/ent/migrate/schema.go @@ -104,6 +104,7 @@ var ( {Name: "status", Type: field.TypeEnum, Enums: []string{"IN_PROGRESS", "COMPLETED", "PENDING"}}, {Name: "priority", Type: field.TypeInt, Default: 0}, {Name: "text", Type: field.TypeString, Size: 2147483647}, + {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "blob", Type: field.TypeBytes, Nullable: true}, {Name: "init", Type: field.TypeJSON, Nullable: true}, {Name: "custom", Type: field.TypeJSON, Nullable: true}, @@ -121,19 +122,19 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "todos_categories_todos", - Columns: []*schema.Column{TodosColumns[10]}, + Columns: []*schema.Column{TodosColumns[11]}, RefColumns: []*schema.Column{CategoriesColumns[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/todopulid/ent/mutation.go b/entgql/internal/todopulid/ent/mutation.go index 59896fbbf..48d4f0cb5 100644 --- a/entgql/internal/todopulid/ent/mutation.go +++ b/entgql/internal/todopulid/ent/mutation.go @@ -2527,6 +2527,7 @@ type TodoMutation struct { priority *int addpriority *int text *string + name *string blob *[]byte init *map[string]interface{} custom *[]customstruct.Custom @@ -2818,6 +2819,55 @@ func (m *TodoMutation) ResetText() { m.text = nil } +// SetName sets the "name" field. +func (m *TodoMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *TodoMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" 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) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ClearName clears the value of the "name" field. +func (m *TodoMutation) ClearName() { + m.name = nil + m.clearedFields[todo.FieldName] = struct{}{} +} + +// NameCleared returns if the "name" field was cleared in this mutation. +func (m *TodoMutation) NameCleared() bool { + _, ok := m.clearedFields[todo.FieldName] + return ok +} + +// ResetName resets all changes to the "name" field. +func (m *TodoMutation) ResetName() { + m.name = nil + delete(m.clearedFields, todo.FieldName) +} + // SetBlob sets the "blob" field. func (m *TodoMutation) SetBlob(b []byte) { m.blob = &b @@ -3344,7 +3394,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, 10) + fields := make([]string, 0, 11) if m.created_at != nil { fields = append(fields, todo.FieldCreatedAt) } @@ -3357,6 +3407,9 @@ func (m *TodoMutation) Fields() []string { if m.text != nil { fields = append(fields, todo.FieldText) } + if m.name != nil { + fields = append(fields, todo.FieldName) + } if m.blob != nil { fields = append(fields, todo.FieldBlob) } @@ -3391,6 +3444,8 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) { return m.Priority() case todo.FieldText: return m.Text() + case todo.FieldName: + return m.Name() case todo.FieldBlob: return m.Blob() case todo.FieldInit: @@ -3420,6 +3475,8 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldPriority(ctx) case todo.FieldText: return m.OldText(ctx) + case todo.FieldName: + return m.OldName(ctx) case todo.FieldBlob: return m.OldBlob(ctx) case todo.FieldInit: @@ -3469,6 +3526,13 @@ func (m *TodoMutation) SetField(name string, value ent.Value) error { } m.SetText(v) return nil + case todo.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil case todo.FieldBlob: v, ok := value.([]byte) if !ok { @@ -3568,6 +3632,9 @@ func (m *TodoMutation) AddField(name string, value ent.Value) error { // mutation. func (m *TodoMutation) ClearedFields() []string { var fields []string + if m.FieldCleared(todo.FieldName) { + fields = append(fields, todo.FieldName) + } if m.FieldCleared(todo.FieldBlob) { fields = append(fields, todo.FieldBlob) } @@ -3597,6 +3664,9 @@ func (m *TodoMutation) FieldCleared(name string) bool { // error if the field is not defined in the schema. func (m *TodoMutation) ClearField(name string) error { switch name { + case todo.FieldName: + m.ClearName() + return nil case todo.FieldBlob: m.ClearBlob() return nil @@ -3632,6 +3702,9 @@ func (m *TodoMutation) ResetField(name string) error { case todo.FieldText: m.ResetText() return nil + case todo.FieldName: + m.ResetName() + return nil case todo.FieldBlob: m.ResetBlob() return nil diff --git a/entgql/internal/todopulid/ent/runtime.go b/entgql/internal/todopulid/ent/runtime.go index cbef20a08..9ae5a29e0 100644 --- a/entgql/internal/todopulid/ent/runtime.go +++ b/entgql/internal/todopulid/ent/runtime.go @@ -107,7 +107,7 @@ func init() { // 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() + todoDescValue := todoMixinFields1[9].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. diff --git a/entgql/internal/todopulid/ent/todo.go b/entgql/internal/todopulid/ent/todo.go index eba0749a5..fa3e0b37a 100644 --- a/entgql/internal/todopulid/ent/todo.go +++ b/entgql/internal/todopulid/ent/todo.go @@ -44,6 +44,8 @@ type Todo struct { Priority int `json:"priority,omitempty"` // Text holds the value of the "text" field. Text string `json:"text,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` // Blob holds the value of the "blob" field. Blob []byte `json:"blob,omitempty"` // Init holds the value of the "init" field. @@ -136,7 +138,7 @@ func (*Todo) scanValues(columns []string) ([]any, error) { values[i] = new(pulid.ID) case todo.FieldPriority, todo.FieldValue: values[i] = new(sql.NullInt64) - case todo.FieldStatus, todo.FieldText: + case todo.FieldStatus, todo.FieldText, todo.FieldName: values[i] = new(sql.NullString) case todo.FieldCreatedAt: values[i] = new(sql.NullTime) @@ -189,6 +191,12 @@ func (t *Todo) assignValues(columns []string, values []any) error { } else if value.Valid { t.Text = value.String } + case todo.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + t.Name = value.String + } case todo.FieldBlob: if value, ok := values[i].(*[]byte); !ok { return fmt.Errorf("unexpected type %T for field blob", values[i]) @@ -313,6 +321,9 @@ func (t *Todo) String() string { builder.WriteString("text=") builder.WriteString(t.Text) builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(t.Name) + builder.WriteString(", ") builder.WriteString("blob=") builder.WriteString(fmt.Sprintf("%v", t.Blob)) builder.WriteString(", ") diff --git a/entgql/internal/todopulid/ent/todo/todo.go b/entgql/internal/todopulid/ent/todo/todo.go index b13c53431..c5904449c 100644 --- a/entgql/internal/todopulid/ent/todo/todo.go +++ b/entgql/internal/todopulid/ent/todo/todo.go @@ -40,6 +40,8 @@ const ( FieldPriority = "priority" // FieldText holds the string denoting the text field in the database. FieldText = "text" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" // FieldBlob holds the string denoting the blob field in the database. FieldBlob = "blob" // FieldInit holds the string denoting the init field in the database. @@ -93,6 +95,7 @@ var Columns = []string{ FieldStatus, FieldPriority, FieldText, + FieldName, FieldBlob, FieldInit, FieldCustom, @@ -188,6 +191,11 @@ func ByText(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldText, opts...).ToFunc() } +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + // ByValue orders the results by the value field. func ByValue(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldValue, opts...).ToFunc() diff --git a/entgql/internal/todopulid/ent/todo/where.go b/entgql/internal/todopulid/ent/todo/where.go index aeb83ade5..e298a33ac 100644 --- a/entgql/internal/todopulid/ent/todo/where.go +++ b/entgql/internal/todopulid/ent/todo/where.go @@ -85,6 +85,11 @@ func Text(v string) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldText, v)) } +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldName, v)) +} + // Blob applies equality check predicate on the "blob" field. It's identical to BlobEQ. func Blob(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) @@ -265,6 +270,81 @@ func TextContainsFold(v string) predicate.Todo { return predicate.Todo(sql.FieldContainsFold(FieldText, v)) } +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Todo { + return predicate.Todo(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Todo { + return predicate.Todo(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Todo { + return predicate.Todo(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Todo { + return predicate.Todo(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Todo { + return predicate.Todo(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Todo { + return predicate.Todo(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Todo { + return predicate.Todo(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Todo { + return predicate.Todo(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Todo { + return predicate.Todo(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Todo { + return predicate.Todo(sql.FieldHasSuffix(FieldName, v)) +} + +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.Todo { + return predicate.Todo(sql.FieldIsNull(FieldName)) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.Todo { + return predicate.Todo(sql.FieldNotNull(FieldName)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Todo { + return predicate.Todo(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Todo { + return predicate.Todo(sql.FieldContainsFold(FieldName, v)) +} + // BlobEQ applies the EQ predicate on the "blob" field. func BlobEQ(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) diff --git a/entgql/internal/todopulid/ent/todo_create.go b/entgql/internal/todopulid/ent/todo_create.go index 78faad086..e60cb7267 100644 --- a/entgql/internal/todopulid/ent/todo_create.go +++ b/entgql/internal/todopulid/ent/todo_create.go @@ -78,6 +78,20 @@ func (tc *TodoCreate) SetText(s string) *TodoCreate { return tc } +// SetName sets the "name" field. +func (tc *TodoCreate) SetName(s string) *TodoCreate { + tc.mutation.SetName(s) + return tc +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tc *TodoCreate) SetNillableName(s *string) *TodoCreate { + if s != nil { + tc.SetName(*s) + } + return tc +} + // SetBlob sets the "blob" field. func (tc *TodoCreate) SetBlob(b []byte) *TodoCreate { tc.mutation.SetBlob(b) @@ -333,6 +347,10 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { _spec.SetField(todo.FieldText, field.TypeString, value) _node.Text = value } + if value, ok := tc.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + _node.Name = value + } if value, ok := tc.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) _node.Blob = value diff --git a/entgql/internal/todopulid/ent/todo_update.go b/entgql/internal/todopulid/ent/todo_update.go index 30aa046a0..2923832f1 100644 --- a/entgql/internal/todopulid/ent/todo_update.go +++ b/entgql/internal/todopulid/ent/todo_update.go @@ -94,6 +94,26 @@ func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { return tu } +// SetName sets the "name" field. +func (tu *TodoUpdate) SetName(s string) *TodoUpdate { + tu.mutation.SetName(s) + return tu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableName(s *string) *TodoUpdate { + if s != nil { + tu.SetName(*s) + } + return tu +} + +// ClearName clears the value of the "name" field. +func (tu *TodoUpdate) ClearName() *TodoUpdate { + tu.mutation.ClearName() + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -332,6 +352,12 @@ func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := tu.mutation.Text(); ok { _spec.SetField(todo.FieldText, field.TypeString, value) } + if value, ok := tu.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + } + if tu.mutation.NameCleared() { + _spec.ClearField(todo.FieldName, field.TypeString) + } if value, ok := tu.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) } @@ -544,6 +570,26 @@ func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { return tuo } +// SetName sets the "name" field. +func (tuo *TodoUpdateOne) SetName(s string) *TodoUpdateOne { + tuo.mutation.SetName(s) + return tuo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableName(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetName(*s) + } + return tuo +} + +// ClearName clears the value of the "name" field. +func (tuo *TodoUpdateOne) ClearName() *TodoUpdateOne { + tuo.mutation.ClearName() + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -812,6 +858,12 @@ func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) if value, ok := tuo.mutation.Text(); ok { _spec.SetField(todo.FieldText, field.TypeString, value) } + if value, ok := tuo.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + } + if tuo.mutation.NameCleared() { + _spec.ClearField(todo.FieldName, field.TypeString) + } if value, ok := tuo.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) } diff --git a/entgql/internal/todopulid/generated.go b/entgql/internal/todopulid/generated.go index 356ba9d63..d6556aa89 100644 --- a/entgql/internal/todopulid/generated.go +++ b/entgql/internal/todopulid/generated.go @@ -216,10 +216,12 @@ type ComplexityRoot struct { ExtendedField func(childComplexity int) int ID func(childComplexity int) int Init func(childComplexity int) int + Name func(childComplexity int) int Parent func(childComplexity int) int Priority func(childComplexity int) int Status func(childComplexity int) int Text func(childComplexity int) int + UppercaseName func(childComplexity int) int Value func(childComplexity int) int } @@ -288,6 +290,7 @@ type TodoResolver interface { Status(ctx context.Context, obj *ent.Todo) (todo.Status, error) ExtendedField(ctx context.Context, obj *ent.Todo) (*string, error) + UppercaseName(ctx context.Context, obj *ent.Todo) (*string, error) } type UserResolver interface { Username(ctx context.Context, obj *ent.User) (string, error) @@ -1027,6 +1030,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Init(childComplexity), true + case "Todo.name": + if e.complexity.Todo.Name == nil { + break + } + + return e.complexity.Todo.Name(childComplexity), true + case "Todo.parent": if e.complexity.Todo.Parent == nil { break @@ -1055,6 +1065,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Text(childComplexity), true + case "Todo.uppercaseName": + if e.complexity.Todo.UppercaseName == nil { + break + } + + return e.complexity.Todo.UppercaseName(childComplexity), true + case "Todo.value": if e.complexity.Todo.Value == nil { break @@ -1364,6 +1381,7 @@ extend type Category { extend type Todo { extendedField: String + uppercaseName: String } extend type Query { @@ -1732,6 +1750,7 @@ input CreateTodoInput { status: TodoStatus! priority: Int text: String! + name: String init: Map value: Int parentID: ID @@ -2384,6 +2403,7 @@ type Todo implements Node { status: TodoStatus! priorityOrder: Int! @goField(name: "Priority", forceResolver: false) text: String! + name: String categoryID: ID category_id: ID categoryX: ID @goField(name: "CategoryID", forceResolver: false) @@ -2553,6 +2573,24 @@ input TodoWhereInput { textEqualFold: String textContainsFold: String """ + name field predicates + """ + name: String + nameNEQ: String + nameIn: [String!] + nameNotIn: [String!] + nameGT: String + nameGTE: String + nameLT: String + nameLTE: String + nameContains: String + nameHasPrefix: String + nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean + nameEqualFold: String + nameContainsFold: String + """ category_id field predicates """ categoryID: ID @@ -2634,6 +2672,8 @@ input UpdateTodoInput { status: TodoStatus priority: Int text: String + name: String + clearName: Boolean init: Map clearInit: Boolean value: Int @@ -7352,6 +7392,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -7374,6 +7416,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -7441,6 +7485,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -7463,6 +7509,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -9370,6 +9418,47 @@ func (ec *executionContext) fieldContext_Todo_text(_ context.Context, field grap return fc, nil } +func (ec *executionContext) _Todo_name(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_name(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_name(_ 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 String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Todo_categoryID(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Todo_categoryID(ctx, field) if err != nil { @@ -9714,6 +9803,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -9736,6 +9827,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -9912,6 +10005,47 @@ func (ec *executionContext) fieldContext_Todo_extendedField(_ context.Context, f return fc, nil } +func (ec *executionContext) _Todo_uppercaseName(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_uppercaseName(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Todo().UppercaseName(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_uppercaseName(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Todo", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _TodoConnection_edges(ctx context.Context, field graphql.CollectedField, obj *ent.TodoConnection) (ret graphql.Marshaler) { fc, err := ec.fieldContext_TodoConnection_edges(ctx, field) if err != nil { @@ -10103,6 +10237,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -10125,6 +10261,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -13763,7 +13901,7 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} + fieldsInOrder := [...]string{"status", "priority", "text", "name", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -13793,6 +13931,13 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o return it, err } it.Text = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data case "init": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("init")) data, err := ec.unmarshalOMap2map(ctx, v) @@ -14970,7 +15115,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", "value", "valueNEQ", "valueIn", "valueNotIn", "valueGT", "valueGTE", "valueLT", "valueLTE", "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", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameIsNil", "nameNotNil", "nameEqualFold", "nameContainsFold", "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 { @@ -15293,6 +15438,111 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob return it, err } it.TextContainsFold = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "nameNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameNEQ = data + case "nameIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.NameIn = data + case "nameNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.NameNotIn = data + case "nameGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameGT = data + case "nameGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameGTE = data + case "nameLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameLT = data + case "nameLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameLTE = data + case "nameContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameContains = data + case "nameHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameHasPrefix = data + case "nameHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameHasSuffix = data + case "nameIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameIsNil = data + case "nameNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameNotNil = data + case "nameEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameEqualFold = data + case "nameContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameContainsFold = data case "categoryID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("categoryID")) data, err := ec.unmarshalOID2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚋschemaᚋpulidᚐID(ctx, v) @@ -15651,7 +15901,7 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} + fieldsInOrder := [...]string{"status", "priority", "text", "name", "clearName", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -15681,6 +15931,20 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o return it, err } it.Text = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "clearName": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearName")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearName = data case "init": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("init")) data, err := ec.unmarshalOMap2map(ctx, v) @@ -17832,6 +18096,8 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&out.Invalids, 1) } + case "name": + out.Values[i] = ec._Todo_name(ctx, field, obj) case "categoryID": out.Values[i] = ec._Todo_categoryID(ctx, field, obj) case "category_id": @@ -17983,6 +18249,39 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj continue } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "uppercaseName": + field := field + + innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Todo_uppercaseName(ctx, field, obj) + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) @@ -20565,6 +20864,16 @@ func (ec *executionContext) unmarshalOProjectWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v any) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + return res +} + func (ec *executionContext) unmarshalOString2ᚕstringᚄ(ctx context.Context, v any) ([]string, error) { if v == nil { return nil, nil diff --git a/entgql/internal/todopulid/todo.resolvers.go b/entgql/internal/todopulid/todo.resolvers.go index 257589389..ef06aff93 100644 --- a/entgql/internal/todopulid/todo.resolvers.go +++ b/entgql/internal/todopulid/todo.resolvers.go @@ -80,6 +80,11 @@ func (r *todoResolver) ExtendedField(ctx context.Context, obj *ent.Todo) (*strin panic(fmt.Errorf("not implemented")) } +// UppercaseName is the resolver for the uppercaseName field. +func (r *todoResolver) UppercaseName(ctx context.Context, obj *ent.Todo) (*string, error) { + panic(fmt.Errorf("not implemented: UppercaseName - uppercaseName")) +} + // CreateTodos is the resolver for the createTodos field. func (r *createCategoryInputResolver) CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error { panic(fmt.Errorf("not implemented")) diff --git a/entgql/internal/todouuid/ent/gql_collection.go b/entgql/internal/todouuid/ent/gql_collection.go index 31967c7e5..2c3ea0182 100644 --- a/entgql/internal/todouuid/ent/gql_collection.go +++ b/entgql/internal/todouuid/ent/gql_collection.go @@ -840,6 +840,11 @@ func (tq *TodoQuery) collectField(ctx context.Context, oneNode bool, opCtx *grap selectedFields = append(selectedFields, todo.FieldText) fieldSeen[todo.FieldText] = struct{}{} } + case "name", "uppercaseName": + if _, ok := fieldSeen[todo.FieldName]; !ok { + selectedFields = append(selectedFields, todo.FieldName) + fieldSeen[todo.FieldName] = struct{}{} + } case "init": if _, ok := fieldSeen[todo.FieldInit]; !ok { selectedFields = append(selectedFields, todo.FieldInit) diff --git a/entgql/internal/todouuid/ent/gql_mutation_input.go b/entgql/internal/todouuid/ent/gql_mutation_input.go index c41780213..958628233 100644 --- a/entgql/internal/todouuid/ent/gql_mutation_input.go +++ b/entgql/internal/todouuid/ent/gql_mutation_input.go @@ -172,6 +172,7 @@ type CreateTodoInput struct { Status todo.Status Priority *int Text string + Name *string Init map[string]interface{} Value *int ParentID *uuid.UUID @@ -187,6 +188,9 @@ func (i *CreateTodoInput) Mutate(m *TodoMutation) { m.SetPriority(*v) } m.SetText(i.Text) + if v := i.Name; v != nil { + m.SetName(*v) + } if v := i.Init; v != nil { m.SetInit(v) } @@ -218,6 +222,8 @@ type UpdateTodoInput struct { Status *todo.Status Priority *int Text *string + ClearName bool + Name *string ClearInit bool Init map[string]interface{} Value *int @@ -241,6 +247,12 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) { if v := i.Text; v != nil { m.SetText(*v) } + if i.ClearName { + m.ClearName() + } + if v := i.Name; v != nil { + m.SetName(*v) + } if i.ClearInit { m.ClearInit() } diff --git a/entgql/internal/todouuid/ent/gql_where_input.go b/entgql/internal/todouuid/ent/gql_where_input.go index c4017e76e..9e76f7f8e 100644 --- a/entgql/internal/todouuid/ent/gql_where_input.go +++ b/entgql/internal/todouuid/ent/gql_where_input.go @@ -1160,6 +1160,23 @@ type TodoWhereInput struct { TextEqualFold *string `json:"textEqualFold,omitempty"` TextContainsFold *string `json:"textContainsFold,omitempty"` + // "name" field predicates. + Name *string `json:"name,omitempty"` + NameNEQ *string `json:"nameNEQ,omitempty"` + NameIn []string `json:"nameIn,omitempty"` + NameNotIn []string `json:"nameNotIn,omitempty"` + NameGT *string `json:"nameGT,omitempty"` + NameGTE *string `json:"nameGTE,omitempty"` + NameLT *string `json:"nameLT,omitempty"` + NameLTE *string `json:"nameLTE,omitempty"` + NameContains *string `json:"nameContains,omitempty"` + NameHasPrefix *string `json:"nameHasPrefix,omitempty"` + NameHasSuffix *string `json:"nameHasSuffix,omitempty"` + NameIsNil bool `json:"nameIsNil,omitempty"` + NameNotNil bool `json:"nameNotNil,omitempty"` + NameEqualFold *string `json:"nameEqualFold,omitempty"` + NameContainsFold *string `json:"nameContainsFold,omitempty"` + // "value" field predicates. Value *int `json:"value,omitempty"` ValueNEQ *int `json:"valueNEQ,omitempty"` @@ -1385,6 +1402,51 @@ func (i *TodoWhereInput) P() (predicate.Todo, error) { if i.TextContainsFold != nil { predicates = append(predicates, todo.TextContainsFold(*i.TextContainsFold)) } + if i.Name != nil { + predicates = append(predicates, todo.NameEQ(*i.Name)) + } + if i.NameNEQ != nil { + predicates = append(predicates, todo.NameNEQ(*i.NameNEQ)) + } + if len(i.NameIn) > 0 { + predicates = append(predicates, todo.NameIn(i.NameIn...)) + } + if len(i.NameNotIn) > 0 { + predicates = append(predicates, todo.NameNotIn(i.NameNotIn...)) + } + if i.NameGT != nil { + predicates = append(predicates, todo.NameGT(*i.NameGT)) + } + if i.NameGTE != nil { + predicates = append(predicates, todo.NameGTE(*i.NameGTE)) + } + if i.NameLT != nil { + predicates = append(predicates, todo.NameLT(*i.NameLT)) + } + if i.NameLTE != nil { + predicates = append(predicates, todo.NameLTE(*i.NameLTE)) + } + if i.NameContains != nil { + predicates = append(predicates, todo.NameContains(*i.NameContains)) + } + if i.NameHasPrefix != nil { + predicates = append(predicates, todo.NameHasPrefix(*i.NameHasPrefix)) + } + if i.NameHasSuffix != nil { + predicates = append(predicates, todo.NameHasSuffix(*i.NameHasSuffix)) + } + if i.NameIsNil { + predicates = append(predicates, todo.NameIsNil()) + } + if i.NameNotNil { + predicates = append(predicates, todo.NameNotNil()) + } + if i.NameEqualFold != nil { + predicates = append(predicates, todo.NameEqualFold(*i.NameEqualFold)) + } + if i.NameContainsFold != nil { + predicates = append(predicates, todo.NameContainsFold(*i.NameContainsFold)) + } if i.Value != nil { predicates = append(predicates, todo.ValueEQ(*i.Value)) } diff --git a/entgql/internal/todouuid/ent/migrate/schema.go b/entgql/internal/todouuid/ent/migrate/schema.go index 83bc90558..1db029868 100644 --- a/entgql/internal/todouuid/ent/migrate/schema.go +++ b/entgql/internal/todouuid/ent/migrate/schema.go @@ -104,6 +104,7 @@ var ( {Name: "status", Type: field.TypeEnum, Enums: []string{"IN_PROGRESS", "COMPLETED", "PENDING"}}, {Name: "priority", Type: field.TypeInt, Default: 0}, {Name: "text", Type: field.TypeString, Size: 2147483647}, + {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "blob", Type: field.TypeBytes, Nullable: true}, {Name: "init", Type: field.TypeJSON, Nullable: true}, {Name: "custom", Type: field.TypeJSON, Nullable: true}, @@ -121,19 +122,19 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "todos_categories_todos", - Columns: []*schema.Column{TodosColumns[10]}, + Columns: []*schema.Column{TodosColumns[11]}, RefColumns: []*schema.Column{CategoriesColumns[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/todouuid/ent/mutation.go b/entgql/internal/todouuid/ent/mutation.go index 5aab32f23..8a240b80c 100644 --- a/entgql/internal/todouuid/ent/mutation.go +++ b/entgql/internal/todouuid/ent/mutation.go @@ -2526,6 +2526,7 @@ type TodoMutation struct { priority *int addpriority *int text *string + name *string blob *[]byte init *map[string]interface{} custom *[]customstruct.Custom @@ -2817,6 +2818,55 @@ func (m *TodoMutation) ResetText() { m.text = nil } +// SetName sets the "name" field. +func (m *TodoMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *TodoMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" 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) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ClearName clears the value of the "name" field. +func (m *TodoMutation) ClearName() { + m.name = nil + m.clearedFields[todo.FieldName] = struct{}{} +} + +// NameCleared returns if the "name" field was cleared in this mutation. +func (m *TodoMutation) NameCleared() bool { + _, ok := m.clearedFields[todo.FieldName] + return ok +} + +// ResetName resets all changes to the "name" field. +func (m *TodoMutation) ResetName() { + m.name = nil + delete(m.clearedFields, todo.FieldName) +} + // SetBlob sets the "blob" field. func (m *TodoMutation) SetBlob(b []byte) { m.blob = &b @@ -3343,7 +3393,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, 10) + fields := make([]string, 0, 11) if m.created_at != nil { fields = append(fields, todo.FieldCreatedAt) } @@ -3356,6 +3406,9 @@ func (m *TodoMutation) Fields() []string { if m.text != nil { fields = append(fields, todo.FieldText) } + if m.name != nil { + fields = append(fields, todo.FieldName) + } if m.blob != nil { fields = append(fields, todo.FieldBlob) } @@ -3390,6 +3443,8 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) { return m.Priority() case todo.FieldText: return m.Text() + case todo.FieldName: + return m.Name() case todo.FieldBlob: return m.Blob() case todo.FieldInit: @@ -3419,6 +3474,8 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldPriority(ctx) case todo.FieldText: return m.OldText(ctx) + case todo.FieldName: + return m.OldName(ctx) case todo.FieldBlob: return m.OldBlob(ctx) case todo.FieldInit: @@ -3468,6 +3525,13 @@ func (m *TodoMutation) SetField(name string, value ent.Value) error { } m.SetText(v) return nil + case todo.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil case todo.FieldBlob: v, ok := value.([]byte) if !ok { @@ -3567,6 +3631,9 @@ func (m *TodoMutation) AddField(name string, value ent.Value) error { // mutation. func (m *TodoMutation) ClearedFields() []string { var fields []string + if m.FieldCleared(todo.FieldName) { + fields = append(fields, todo.FieldName) + } if m.FieldCleared(todo.FieldBlob) { fields = append(fields, todo.FieldBlob) } @@ -3596,6 +3663,9 @@ func (m *TodoMutation) FieldCleared(name string) bool { // error if the field is not defined in the schema. func (m *TodoMutation) ClearField(name string) error { switch name { + case todo.FieldName: + m.ClearName() + return nil case todo.FieldBlob: m.ClearBlob() return nil @@ -3631,6 +3701,9 @@ func (m *TodoMutation) ResetField(name string) error { case todo.FieldText: m.ResetText() return nil + case todo.FieldName: + m.ResetName() + return nil case todo.FieldBlob: m.ResetBlob() return nil diff --git a/entgql/internal/todouuid/ent/runtime.go b/entgql/internal/todouuid/ent/runtime.go index 8acb160a2..4849f7515 100644 --- a/entgql/internal/todouuid/ent/runtime.go +++ b/entgql/internal/todouuid/ent/runtime.go @@ -94,7 +94,7 @@ func init() { // 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() + todoDescValue := todoMixinFields0[9].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. diff --git a/entgql/internal/todouuid/ent/todo.go b/entgql/internal/todouuid/ent/todo.go index 0ec7b7c1f..eb51468e7 100644 --- a/entgql/internal/todouuid/ent/todo.go +++ b/entgql/internal/todouuid/ent/todo.go @@ -44,6 +44,8 @@ type Todo struct { Priority int `json:"priority,omitempty"` // Text holds the value of the "text" field. Text string `json:"text,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` // Blob holds the value of the "blob" field. Blob []byte `json:"blob,omitempty"` // Init holds the value of the "init" field. @@ -134,7 +136,7 @@ func (*Todo) scanValues(columns []string) ([]any, error) { values[i] = new([]byte) case todo.FieldPriority, todo.FieldValue: values[i] = new(sql.NullInt64) - case todo.FieldStatus, todo.FieldText: + case todo.FieldStatus, todo.FieldText, todo.FieldName: values[i] = new(sql.NullString) case todo.FieldCreatedAt: values[i] = new(sql.NullTime) @@ -189,6 +191,12 @@ func (t *Todo) assignValues(columns []string, values []any) error { } else if value.Valid { t.Text = value.String } + case todo.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + t.Name = value.String + } case todo.FieldBlob: if value, ok := values[i].(*[]byte); !ok { return fmt.Errorf("unexpected type %T for field blob", values[i]) @@ -313,6 +321,9 @@ func (t *Todo) String() string { builder.WriteString("text=") builder.WriteString(t.Text) builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(t.Name) + builder.WriteString(", ") builder.WriteString("blob=") builder.WriteString(fmt.Sprintf("%v", t.Blob)) builder.WriteString(", ") diff --git a/entgql/internal/todouuid/ent/todo/todo.go b/entgql/internal/todouuid/ent/todo/todo.go index 3988e4c04..ecfc5d86a 100644 --- a/entgql/internal/todouuid/ent/todo/todo.go +++ b/entgql/internal/todouuid/ent/todo/todo.go @@ -40,6 +40,8 @@ const ( FieldPriority = "priority" // FieldText holds the string denoting the text field in the database. FieldText = "text" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" // FieldBlob holds the string denoting the blob field in the database. FieldBlob = "blob" // FieldInit holds the string denoting the init field in the database. @@ -93,6 +95,7 @@ var Columns = []string{ FieldStatus, FieldPriority, FieldText, + FieldName, FieldBlob, FieldInit, FieldCustom, @@ -188,6 +191,11 @@ func ByText(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldText, opts...).ToFunc() } +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + // ByValue orders the results by the value field. func ByValue(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldValue, opts...).ToFunc() diff --git a/entgql/internal/todouuid/ent/todo/where.go b/entgql/internal/todouuid/ent/todo/where.go index 217c84831..c977b84c0 100644 --- a/entgql/internal/todouuid/ent/todo/where.go +++ b/entgql/internal/todouuid/ent/todo/where.go @@ -85,6 +85,11 @@ func Text(v string) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldText, v)) } +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldName, v)) +} + // Blob applies equality check predicate on the "blob" field. It's identical to BlobEQ. func Blob(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) @@ -265,6 +270,81 @@ func TextContainsFold(v string) predicate.Todo { return predicate.Todo(sql.FieldContainsFold(FieldText, v)) } +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Todo { + return predicate.Todo(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Todo { + return predicate.Todo(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Todo { + return predicate.Todo(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Todo { + return predicate.Todo(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Todo { + return predicate.Todo(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Todo { + return predicate.Todo(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Todo { + return predicate.Todo(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Todo { + return predicate.Todo(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Todo { + return predicate.Todo(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Todo { + return predicate.Todo(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Todo { + return predicate.Todo(sql.FieldHasSuffix(FieldName, v)) +} + +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.Todo { + return predicate.Todo(sql.FieldIsNull(FieldName)) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.Todo { + return predicate.Todo(sql.FieldNotNull(FieldName)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Todo { + return predicate.Todo(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Todo { + return predicate.Todo(sql.FieldContainsFold(FieldName, v)) +} + // BlobEQ applies the EQ predicate on the "blob" field. func BlobEQ(v []byte) predicate.Todo { return predicate.Todo(sql.FieldEQ(FieldBlob, v)) diff --git a/entgql/internal/todouuid/ent/todo_create.go b/entgql/internal/todouuid/ent/todo_create.go index 6c1bab4bb..3e3187a23 100644 --- a/entgql/internal/todouuid/ent/todo_create.go +++ b/entgql/internal/todouuid/ent/todo_create.go @@ -78,6 +78,20 @@ func (tc *TodoCreate) SetText(s string) *TodoCreate { return tc } +// SetName sets the "name" field. +func (tc *TodoCreate) SetName(s string) *TodoCreate { + tc.mutation.SetName(s) + return tc +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tc *TodoCreate) SetNillableName(s *string) *TodoCreate { + if s != nil { + tc.SetName(*s) + } + return tc +} + // SetBlob sets the "blob" field. func (tc *TodoCreate) SetBlob(b []byte) *TodoCreate { tc.mutation.SetBlob(b) @@ -333,6 +347,10 @@ func (tc *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { _spec.SetField(todo.FieldText, field.TypeString, value) _node.Text = value } + if value, ok := tc.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + _node.Name = value + } if value, ok := tc.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) _node.Blob = value diff --git a/entgql/internal/todouuid/ent/todo_update.go b/entgql/internal/todouuid/ent/todo_update.go index 2f413aa76..1981e2f43 100644 --- a/entgql/internal/todouuid/ent/todo_update.go +++ b/entgql/internal/todouuid/ent/todo_update.go @@ -94,6 +94,26 @@ func (tu *TodoUpdate) SetNillableText(s *string) *TodoUpdate { return tu } +// SetName sets the "name" field. +func (tu *TodoUpdate) SetName(s string) *TodoUpdate { + tu.mutation.SetName(s) + return tu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tu *TodoUpdate) SetNillableName(s *string) *TodoUpdate { + if s != nil { + tu.SetName(*s) + } + return tu +} + +// ClearName clears the value of the "name" field. +func (tu *TodoUpdate) ClearName() *TodoUpdate { + tu.mutation.ClearName() + return tu +} + // SetBlob sets the "blob" field. func (tu *TodoUpdate) SetBlob(b []byte) *TodoUpdate { tu.mutation.SetBlob(b) @@ -332,6 +352,12 @@ func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := tu.mutation.Text(); ok { _spec.SetField(todo.FieldText, field.TypeString, value) } + if value, ok := tu.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + } + if tu.mutation.NameCleared() { + _spec.ClearField(todo.FieldName, field.TypeString) + } if value, ok := tu.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) } @@ -544,6 +570,26 @@ func (tuo *TodoUpdateOne) SetNillableText(s *string) *TodoUpdateOne { return tuo } +// SetName sets the "name" field. +func (tuo *TodoUpdateOne) SetName(s string) *TodoUpdateOne { + tuo.mutation.SetName(s) + return tuo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (tuo *TodoUpdateOne) SetNillableName(s *string) *TodoUpdateOne { + if s != nil { + tuo.SetName(*s) + } + return tuo +} + +// ClearName clears the value of the "name" field. +func (tuo *TodoUpdateOne) ClearName() *TodoUpdateOne { + tuo.mutation.ClearName() + return tuo +} + // SetBlob sets the "blob" field. func (tuo *TodoUpdateOne) SetBlob(b []byte) *TodoUpdateOne { tuo.mutation.SetBlob(b) @@ -812,6 +858,12 @@ func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) if value, ok := tuo.mutation.Text(); ok { _spec.SetField(todo.FieldText, field.TypeString, value) } + if value, ok := tuo.mutation.Name(); ok { + _spec.SetField(todo.FieldName, field.TypeString, value) + } + if tuo.mutation.NameCleared() { + _spec.ClearField(todo.FieldName, field.TypeString) + } if value, ok := tuo.mutation.Blob(); ok { _spec.SetField(todo.FieldBlob, field.TypeBytes, value) } diff --git a/entgql/internal/todouuid/generated.go b/entgql/internal/todouuid/generated.go index 8ebf13494..193749067 100644 --- a/entgql/internal/todouuid/generated.go +++ b/entgql/internal/todouuid/generated.go @@ -217,10 +217,12 @@ type ComplexityRoot struct { ExtendedField func(childComplexity int) int ID func(childComplexity int) int Init func(childComplexity int) int + Name func(childComplexity int) int Parent func(childComplexity int) int Priority func(childComplexity int) int Status func(childComplexity int) int Text func(childComplexity int) int + UppercaseName func(childComplexity int) int Value func(childComplexity int) int } @@ -289,6 +291,7 @@ type TodoResolver interface { Status(ctx context.Context, obj *ent.Todo) (todo.Status, error) ExtendedField(ctx context.Context, obj *ent.Todo) (*string, error) + UppercaseName(ctx context.Context, obj *ent.Todo) (*string, error) } type UserResolver interface { Username(ctx context.Context, obj *ent.User) (string, error) @@ -1028,6 +1031,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Init(childComplexity), true + case "Todo.name": + if e.complexity.Todo.Name == nil { + break + } + + return e.complexity.Todo.Name(childComplexity), true + case "Todo.parent": if e.complexity.Todo.Parent == nil { break @@ -1056,6 +1066,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Text(childComplexity), true + case "Todo.uppercaseName": + if e.complexity.Todo.UppercaseName == nil { + break + } + + return e.complexity.Todo.UppercaseName(childComplexity), true + case "Todo.value": if e.complexity.Todo.Value == nil { break @@ -1365,6 +1382,7 @@ extend type Category { extend type Todo { extendedField: String + uppercaseName: String } extend type Query { @@ -1733,6 +1751,7 @@ input CreateTodoInput { status: TodoStatus! priority: Int text: String! + name: String init: Map value: Int parentID: ID @@ -2385,6 +2404,7 @@ type Todo implements Node { status: TodoStatus! priorityOrder: Int! @goField(name: "Priority", forceResolver: false) text: String! + name: String categoryID: ID category_id: ID categoryX: ID @goField(name: "CategoryID", forceResolver: false) @@ -2554,6 +2574,24 @@ input TodoWhereInput { textEqualFold: String textContainsFold: String """ + name field predicates + """ + name: String + nameNEQ: String + nameIn: [String!] + nameNotIn: [String!] + nameGT: String + nameGTE: String + nameLT: String + nameLTE: String + nameContains: String + nameHasPrefix: String + nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean + nameEqualFold: String + nameContainsFold: String + """ category_id field predicates """ categoryID: ID @@ -2635,6 +2673,8 @@ input UpdateTodoInput { status: TodoStatus priority: Int text: String + name: String + clearName: Boolean init: Map clearInit: Boolean value: Int @@ -7353,6 +7393,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -7375,6 +7417,8 @@ func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -7442,6 +7486,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -7464,6 +7510,8 @@ func (ec *executionContext) fieldContext_Mutation_updateTodo(ctx context.Context return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -9371,6 +9419,47 @@ func (ec *executionContext) fieldContext_Todo_text(_ context.Context, field grap return fc, nil } +func (ec *executionContext) _Todo_name(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_name(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_name(_ 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 String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Todo_categoryID(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Todo_categoryID(ctx, field) if err != nil { @@ -9715,6 +9804,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -9737,6 +9828,8 @@ func (ec *executionContext) fieldContext_Todo_parent(_ context.Context, field gr return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -9913,6 +10006,47 @@ func (ec *executionContext) fieldContext_Todo_extendedField(_ context.Context, f return fc, nil } +func (ec *executionContext) _Todo_uppercaseName(ctx context.Context, field graphql.CollectedField, obj *ent.Todo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Todo_uppercaseName(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Todo().UppercaseName(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Todo_uppercaseName(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Todo", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _TodoConnection_edges(ctx context.Context, field graphql.CollectedField, obj *ent.TodoConnection) (ret graphql.Marshaler) { fc, err := ec.fieldContext_TodoConnection_edges(ctx, field) if err != nil { @@ -10104,6 +10238,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_priorityOrder(ctx, field) case "text": return ec.fieldContext_Todo_text(ctx, field) + case "name": + return ec.fieldContext_Todo_name(ctx, field) case "categoryID": return ec.fieldContext_Todo_categoryID(ctx, field) case "category_id": @@ -10126,6 +10262,8 @@ func (ec *executionContext) fieldContext_TodoEdge_node(_ context.Context, field return ec.fieldContext_Todo_category(ctx, field) case "extendedField": return ec.fieldContext_Todo_extendedField(ctx, field) + case "uppercaseName": + return ec.fieldContext_Todo_uppercaseName(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Todo", field.Name) }, @@ -13764,7 +13902,7 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} + fieldsInOrder := [...]string{"status", "priority", "text", "name", "init", "value", "parentID", "childIDs", "categoryID", "secretID"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -13794,6 +13932,13 @@ func (ec *executionContext) unmarshalInputCreateTodoInput(ctx context.Context, o return it, err } it.Text = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data case "init": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("init")) data, err := ec.unmarshalOMap2map(ctx, v) @@ -14971,7 +15116,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", "value", "valueNEQ", "valueIn", "valueNotIn", "valueGT", "valueGTE", "valueLT", "valueLTE", "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", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameIsNil", "nameNotNil", "nameEqualFold", "nameContainsFold", "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 { @@ -15294,6 +15439,111 @@ func (ec *executionContext) unmarshalInputTodoWhereInput(ctx context.Context, ob return it, err } it.TextContainsFold = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "nameNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameNEQ = data + case "nameIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.NameIn = data + case "nameNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.NameNotIn = data + case "nameGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameGT = data + case "nameGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameGTE = data + case "nameLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameLT = data + case "nameLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameLTE = data + case "nameContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameContains = data + case "nameHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameHasPrefix = data + case "nameHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameHasSuffix = data + case "nameIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameIsNil = data + case "nameNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameNotNil = data + case "nameEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameEqualFold = data + case "nameContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.NameContainsFold = data case "categoryID": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("categoryID")) data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) @@ -15652,7 +15902,7 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"status", "priority", "text", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} + fieldsInOrder := [...]string{"status", "priority", "text", "name", "clearName", "init", "clearInit", "value", "parentID", "clearParent", "addChildIDs", "removeChildIDs", "clearChildren", "secretID", "clearSecret"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -15682,6 +15932,20 @@ func (ec *executionContext) unmarshalInputUpdateTodoInput(ctx context.Context, o return it, err } it.Text = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "clearName": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearName")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearName = data case "init": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("init")) data, err := ec.unmarshalOMap2map(ctx, v) @@ -17833,6 +18097,8 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&out.Invalids, 1) } + case "name": + out.Values[i] = ec._Todo_name(ctx, field, obj) case "categoryID": out.Values[i] = ec._Todo_categoryID(ctx, field, obj) case "category_id": @@ -17984,6 +18250,39 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj continue } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "uppercaseName": + field := field + + innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Todo_uppercaseName(ctx, field, obj) + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) @@ -20571,6 +20870,16 @@ func (ec *executionContext) unmarshalOProjectWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v any) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + return res +} + func (ec *executionContext) unmarshalOString2ᚕstringᚄ(ctx context.Context, v any) ([]string, error) { if v == nil { return nil, nil diff --git a/entgql/internal/todouuid/todo.resolvers.go b/entgql/internal/todouuid/todo.resolvers.go index 88cf32e3b..a4838a196 100644 --- a/entgql/internal/todouuid/todo.resolvers.go +++ b/entgql/internal/todouuid/todo.resolvers.go @@ -80,6 +80,11 @@ func (r *todoResolver) ExtendedField(ctx context.Context, obj *ent.Todo) (*strin panic(fmt.Errorf("not implemented")) } +// UppercaseName is the resolver for the uppercaseName field. +func (r *todoResolver) UppercaseName(ctx context.Context, obj *ent.Todo) (*string, error) { + panic(fmt.Errorf("not implemented: UppercaseName - uppercaseName")) +} + // CreateTodos is the resolver for the createTodos field. func (r *createCategoryInputResolver) CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error { panic(fmt.Errorf("not implemented")) diff --git a/entgql/template.go b/entgql/template.go index 69f20dc3d..5ec7a9c65 100644 --- a/entgql/template.go +++ b/entgql/template.go @@ -79,6 +79,7 @@ var ( TemplateFuncs = template.FuncMap{ "fieldCollections": fieldCollections, "fieldMapping": fieldMapping, + "fieldCollectedFor": fieldCollectedFor, "filterEdges": filterEdges, "filterFields": filterFields, "filterNodes": filterNodes, @@ -369,6 +370,16 @@ func filterFields(fields []*gen.Field, skip SkipMode) ([]*gen.Field, error) { return filteredFields, nil } +// fieldCollectedFor returns all fields that should be collected when the given GraphQL field name is queried. +// This checks the CollectedFor annotation on all fields. +func fieldCollectedFor(f *gen.Field) ([]string, error) { + ant, err := annotation(f.Annotations) + if err != nil || ant.Skip.Is(SkipType) || f.Sensitive() { + return nil, err + } + return ant.CollectedFor, nil +} + // OrderTerm is a struct that represents a single GraphQL order term. type OrderTerm struct { // The type that owns the order field. diff --git a/entgql/template/collection.tmpl b/entgql/template/collection.tmpl index 1901de025..6d373b15d 100644 --- a/entgql/template/collection.tmpl +++ b/entgql/template/collection.tmpl @@ -152,7 +152,13 @@ func ({{ $receiver }} *{{ $query }}) collectField(ctx context.Context, oneNode b {{- end }} {{- end }} {{- range $f := $fields }} - {{- with fieldMapping $f }} + {{- $mapping := fieldMapping $f }} + {{- range fieldCollectedFor $f }} + {{- if eq (indexOf $mapping .) -1 }} + {{- $mapping = append $mapping . }} + {{- end }} + {{- end }} + {{- with $mapping }} case {{ range $i, $m := . }}{{ if $i }}, {{ end }}"{{ $m }}"{{ end }}: if _, ok := fieldSeen[{{ $node.Package }}.{{ $f.Constant }}]; !ok { selectedFields = append(selectedFields, {{ $node.Package }}.{{ $f.Constant }}) diff --git a/entgql/testdata/schema.graphql b/entgql/testdata/schema.graphql index 289e579b3..1a75adaf1 100644 --- a/entgql/testdata/schema.graphql +++ b/entgql/testdata/schema.graphql @@ -70,6 +70,7 @@ input CreateTodoInput { status: TodoStatus! priority: Int text: String! + name: String init: Map value: Int parentID: ID @@ -162,6 +163,7 @@ type Todo { status: TodoStatus! priorityOrder: Int! @goField(name: "Priority", forceResolver: false) text: String! + name: String categoryID: ID category_id: ID categoryX: ID @goField(name: "CategoryID", forceResolver: false) @@ -252,6 +254,8 @@ input UpdateTodoInput { status: TodoStatus priority: Int text: String + name: String + clearName: Boolean init: Map clearInit: Boolean value: Int diff --git a/entgql/testdata/schema_output.graphql b/entgql/testdata/schema_output.graphql index 289e579b3..1a75adaf1 100644 --- a/entgql/testdata/schema_output.graphql +++ b/entgql/testdata/schema_output.graphql @@ -70,6 +70,7 @@ input CreateTodoInput { status: TodoStatus! priority: Int text: String! + name: String init: Map value: Int parentID: ID @@ -162,6 +163,7 @@ type Todo { status: TodoStatus! priorityOrder: Int! @goField(name: "Priority", forceResolver: false) text: String! + name: String categoryID: ID category_id: ID categoryX: ID @goField(name: "CategoryID", forceResolver: false) @@ -252,6 +254,8 @@ input UpdateTodoInput { status: TodoStatus priority: Int text: String + name: String + clearName: Boolean init: Map clearInit: Boolean value: Int diff --git a/entgql/testdata/schema_relay.graphql b/entgql/testdata/schema_relay.graphql index 8f0d69b91..d3fec27cd 100644 --- a/entgql/testdata/schema_relay.graphql +++ b/entgql/testdata/schema_relay.graphql @@ -315,6 +315,7 @@ input CreateTodoInput { status: TodoStatus! priority: Int text: String! + name: String init: Map value: Int parentID: ID @@ -917,6 +918,7 @@ type Todo implements Node { status: TodoStatus! priorityOrder: Int! @goField(name: "Priority", forceResolver: false) text: String! + name: String categoryID: ID category_id: ID categoryX: ID @goField(name: "CategoryID", forceResolver: false) @@ -1086,6 +1088,24 @@ input TodoWhereInput { textEqualFold: String textContainsFold: String """ + name field predicates + """ + name: String + nameNEQ: String + nameIn: [String!] + nameNotIn: [String!] + nameGT: String + nameGTE: String + nameLT: String + nameLTE: String + nameContains: String + nameHasPrefix: String + nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean + nameEqualFold: String + nameContainsFold: String + """ category_id field predicates """ categoryID: ID @@ -1167,6 +1187,8 @@ input UpdateTodoInput { status: TodoStatus priority: Int text: String + name: String + clearName: Boolean init: Map clearInit: Boolean value: Int diff --git a/entgql/testdata/schema_relay_output.graphql b/entgql/testdata/schema_relay_output.graphql index 8f0d69b91..d3fec27cd 100644 --- a/entgql/testdata/schema_relay_output.graphql +++ b/entgql/testdata/schema_relay_output.graphql @@ -315,6 +315,7 @@ input CreateTodoInput { status: TodoStatus! priority: Int text: String! + name: String init: Map value: Int parentID: ID @@ -917,6 +918,7 @@ type Todo implements Node { status: TodoStatus! priorityOrder: Int! @goField(name: "Priority", forceResolver: false) text: String! + name: String categoryID: ID category_id: ID categoryX: ID @goField(name: "CategoryID", forceResolver: false) @@ -1086,6 +1088,24 @@ input TodoWhereInput { textEqualFold: String textContainsFold: String """ + name field predicates + """ + name: String + nameNEQ: String + nameIn: [String!] + nameNotIn: [String!] + nameGT: String + nameGTE: String + nameLT: String + nameLTE: String + nameContains: String + nameHasPrefix: String + nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean + nameEqualFold: String + nameContainsFold: String + """ category_id field predicates """ categoryID: ID @@ -1167,6 +1187,8 @@ input UpdateTodoInput { status: TodoStatus priority: Int text: String + name: String + clearName: Boolean init: Map clearInit: Boolean value: Int