From 18654f241a1b8e35f7d211922a4ef74386774908 Mon Sep 17 00:00:00 2001 From: Darko Luketic Date: Fri, 4 Oct 2024 20:22:25 +0200 Subject: [PATCH] ka.graphql missing and mutations --- ent.graphql | 785 +++ ent/category.go | 194 + ent/category/category.go | 118 + ent/category/where.go | 345 ++ ent/category_create.go | 316 ++ ent/category_delete.go | 88 + ent/category_query.go | 643 +++ ent/category_update.go | 506 ++ ent/client.go | 692 +++ ent/ent.go | 612 +++ ent/entc.go | 4 +- ent/entql.go | 380 ++ ent/enttest/enttest.go | 84 + ent/gql_collection.go | 611 +++ ent/gql_edge.go | 67 + ent/gql_mutation_input.go | 301 ++ ent/gql_node.go | 248 + ent/gql_pagination.go | 1126 +++++ ent/gql_transaction.go | 30 + ent/gql_where_input.go | 1165 +++++ ent/hook/hook.go | 223 + ent/internal/schema.go | 9 + ent/migrate/migrate.go | 64 + ent/migrate/schema.go | 83 + ent/mutation.go | 2150 ++++++++ ent/post.go | 237 + ent/post/post.go | 166 + ent/post/where.go | 428 ++ ent/post_create.go | 401 ++ ent/post_delete.go | 88 + ent/post_query.go | 703 +++ ent/post_update.go | 639 +++ ent/predicate/predicate.go | 16 + ent/privacy/privacy.go | 243 + ent/profile.go | 205 + ent/profile/profile.go | 124 + ent/profile/where.go | 435 ++ ent/profile_create.go | 334 ++ ent/profile_delete.go | 88 + ent/profile_query.go | 643 +++ ent/profile_update.go | 550 +++ ent/runtime.go | 83 + ent/runtime/runtime.go | 10 + ent/tx.go | 216 + go.mod | 40 +- go.sum | 106 +- gqlgen.yml | 5 +- graph/ent.resolvers.go | 44 + graph/generated/ent.generated.go | 6749 ++++++++++++++++++++++++++ graph/generated/prelude.generated.go | 2971 ++++++++++++ graph/generated/root_.generated.go | 1390 ++++++ graph/resolver.go | 21 + 52 files changed, 27713 insertions(+), 66 deletions(-) create mode 100644 ent.graphql create mode 100644 ent/category.go create mode 100644 ent/category/category.go create mode 100644 ent/category/where.go create mode 100644 ent/category_create.go create mode 100644 ent/category_delete.go create mode 100644 ent/category_query.go create mode 100644 ent/category_update.go create mode 100644 ent/client.go create mode 100644 ent/ent.go create mode 100644 ent/entql.go create mode 100644 ent/enttest/enttest.go create mode 100644 ent/gql_collection.go create mode 100644 ent/gql_edge.go create mode 100644 ent/gql_mutation_input.go create mode 100644 ent/gql_node.go create mode 100644 ent/gql_pagination.go create mode 100644 ent/gql_transaction.go create mode 100644 ent/gql_where_input.go create mode 100644 ent/hook/hook.go create mode 100644 ent/internal/schema.go create mode 100644 ent/migrate/migrate.go create mode 100644 ent/migrate/schema.go create mode 100644 ent/mutation.go create mode 100644 ent/post.go create mode 100644 ent/post/post.go create mode 100644 ent/post/where.go create mode 100644 ent/post_create.go create mode 100644 ent/post_delete.go create mode 100644 ent/post_query.go create mode 100644 ent/post_update.go create mode 100644 ent/predicate/predicate.go create mode 100644 ent/privacy/privacy.go create mode 100644 ent/profile.go create mode 100644 ent/profile/profile.go create mode 100644 ent/profile/where.go create mode 100644 ent/profile_create.go create mode 100644 ent/profile_delete.go create mode 100644 ent/profile_query.go create mode 100644 ent/profile_update.go create mode 100644 ent/runtime.go create mode 100644 ent/runtime/runtime.go create mode 100644 ent/tx.go create mode 100644 graph/ent.resolvers.go create mode 100644 graph/generated/ent.generated.go create mode 100644 graph/generated/prelude.generated.go create mode 100644 graph/generated/root_.generated.go create mode 100644 graph/resolver.go diff --git a/ent.graphql b/ent.graphql new file mode 100644 index 0000000..c70eae0 --- /dev/null +++ b/ent.graphql @@ -0,0 +1,785 @@ +directive @goField(forceResolver: Boolean, name: String, omittable: Boolean) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION +directive @goModel(model: String, models: [String!], forceGenerate: Boolean) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION +type Category implements Node { + id: ID! + createdAt: Time! + updatedAt: Time + title: String! + description: String + posts( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Posts returned from the connection. + """ + orderBy: PostOrder + + """ + Filtering options for Posts returned from the connection. + """ + where: PostWhereInput + ): PostConnection! +} +""" +A connection to a list of items. +""" +type CategoryConnection { + """ + A list of edges. + """ + edges: [CategoryEdge] + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! + """ + Identifies the total count of items in the connection. + """ + totalCount: Int! +} +""" +An edge in a connection. +""" +type CategoryEdge { + """ + The item at the end of the edge. + """ + node: Category + """ + A cursor for use in pagination. + """ + cursor: Cursor! +} +""" +Ordering options for Category connections +""" +input CategoryOrder { + """ + The ordering direction. + """ + direction: OrderDirection! = ASC + """ + The field by which to order Categories. + """ + field: CategoryOrderField! +} +""" +Properties by which Category connections can be ordered. +""" +enum CategoryOrderField { + CREATED_AT + UPDATED_AT + POSTS_COUNT +} +""" +CategoryWhereInput is used for filtering Category objects. +Input was generated by ent. +""" +input CategoryWhereInput { + not: CategoryWhereInput + and: [CategoryWhereInput!] + or: [CategoryWhereInput!] + """ + id field predicates + """ + id: ID + idNEQ: ID + idIn: [ID!] + idNotIn: [ID!] + idGT: ID + idGTE: ID + idLT: ID + idLTE: ID + """ + created_at field predicates + """ + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """ + updated_at field predicates + """ + updatedAt: Time + updatedAtNEQ: Time + updatedAtIn: [Time!] + updatedAtNotIn: [Time!] + updatedAtGT: Time + updatedAtGTE: Time + updatedAtLT: Time + updatedAtLTE: Time + updatedAtIsNil: Boolean + updatedAtNotNil: Boolean + """ + title field predicates + """ + title: String + titleNEQ: String + titleIn: [String!] + titleNotIn: [String!] + titleGT: String + titleGTE: String + titleLT: String + titleLTE: String + titleContains: String + titleHasPrefix: String + titleHasSuffix: String + titleEqualFold: String + titleContainsFold: String + """ + description field predicates + """ + description: String + descriptionNEQ: String + descriptionIn: [String!] + descriptionNotIn: [String!] + descriptionGT: String + descriptionGTE: String + descriptionLT: String + descriptionLTE: String + descriptionContains: String + descriptionHasPrefix: String + descriptionHasSuffix: String + descriptionIsNil: Boolean + descriptionNotNil: Boolean + descriptionEqualFold: String + descriptionContainsFold: String + """ + posts edge predicates + """ + hasPosts: Boolean + hasPostsWith: [PostWhereInput!] +} +""" +CreateCategoryInput is used for create Category object. +Input was generated by ent. +""" +input CreateCategoryInput { + createdAt: Time + updatedAt: Time + title: String! + description: String + postIDs: [ID!] +} +""" +CreatePostInput is used for create Post object. +Input was generated by ent. +""" +input CreatePostInput { + createdAt: Time + updatedAt: Time + expires: Boolean + expireTime: Time + title: String! + body: String! + categoryID: ID + profileID: ID +} +""" +CreateProfileInput is used for create Profile object. +Input was generated by ent. +""" +input CreateProfileInput { + createdAt: Time + updatedAt: Time + name: String + address: String + phone: String + postIDs: [ID!] +} +""" +Define a Relay Cursor type: +https://relay.dev/graphql/connections.htm#sec-Cursor +""" +scalar Cursor +""" +An object with an ID. +Follows the [Relay Global Object Identification Specification](https://relay.dev/graphql/objectidentification.htm) +""" +interface Node @goModel(model: "code.icod.de/dalu/ka/ent.Noder") { + """ + The id of the object. + """ + id: ID! +} +""" +Possible directions in which to order a list of items when provided an `orderBy` argument. +""" +enum OrderDirection { + """ + Specifies an ascending order for a given `orderBy` argument. + """ + ASC + """ + Specifies a descending order for a given `orderBy` argument. + """ + DESC +} +""" +Information about pagination in a connection. +https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo +""" +type PageInfo { + """ + When paginating forwards, are there more items? + """ + hasNextPage: Boolean! + """ + When paginating backwards, are there more items? + """ + hasPreviousPage: Boolean! + """ + When paginating backwards, the cursor to continue. + """ + startCursor: Cursor + """ + When paginating forwards, the cursor to continue. + """ + endCursor: Cursor +} +type Post implements Node { + id: ID! + createdAt: Time! + updatedAt: Time + expires: Boolean! + expireTime: Time + title: String! + body: String! + category: Category + profile: Profile +} +""" +A connection to a list of items. +""" +type PostConnection { + """ + A list of edges. + """ + edges: [PostEdge] + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! + """ + Identifies the total count of items in the connection. + """ + totalCount: Int! +} +""" +An edge in a connection. +""" +type PostEdge { + """ + The item at the end of the edge. + """ + node: Post + """ + A cursor for use in pagination. + """ + cursor: Cursor! +} +""" +Ordering options for Post connections +""" +input PostOrder { + """ + The ordering direction. + """ + direction: OrderDirection! = ASC + """ + The field by which to order Posts. + """ + field: PostOrderField! +} +""" +Properties by which Post connections can be ordered. +""" +enum PostOrderField { + CREATED_AT + UPDATED_AT + EXPIRE_TIME +} +""" +PostWhereInput is used for filtering Post objects. +Input was generated by ent. +""" +input PostWhereInput { + not: PostWhereInput + and: [PostWhereInput!] + or: [PostWhereInput!] + """ + id field predicates + """ + id: ID + idNEQ: ID + idIn: [ID!] + idNotIn: [ID!] + idGT: ID + idGTE: ID + idLT: ID + idLTE: ID + """ + created_at field predicates + """ + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """ + updated_at field predicates + """ + updatedAt: Time + updatedAtNEQ: Time + updatedAtIn: [Time!] + updatedAtNotIn: [Time!] + updatedAtGT: Time + updatedAtGTE: Time + updatedAtLT: Time + updatedAtLTE: Time + updatedAtIsNil: Boolean + updatedAtNotNil: Boolean + """ + expires field predicates + """ + expires: Boolean + expiresNEQ: Boolean + """ + expire_time field predicates + """ + expireTime: Time + expireTimeNEQ: Time + expireTimeIn: [Time!] + expireTimeNotIn: [Time!] + expireTimeGT: Time + expireTimeGTE: Time + expireTimeLT: Time + expireTimeLTE: Time + expireTimeIsNil: Boolean + expireTimeNotNil: Boolean + """ + title field predicates + """ + title: String + titleNEQ: String + titleIn: [String!] + titleNotIn: [String!] + titleGT: String + titleGTE: String + titleLT: String + titleLTE: String + titleContains: String + titleHasPrefix: String + titleHasSuffix: String + titleEqualFold: String + titleContainsFold: String + """ + body field predicates + """ + body: String + bodyNEQ: String + bodyIn: [String!] + bodyNotIn: [String!] + bodyGT: String + bodyGTE: String + bodyLT: String + bodyLTE: String + bodyContains: String + bodyHasPrefix: String + bodyHasSuffix: String + bodyEqualFold: String + bodyContainsFold: String + """ + category edge predicates + """ + hasCategory: Boolean + hasCategoryWith: [CategoryWhereInput!] + """ + profile edge predicates + """ + hasProfile: Boolean + hasProfileWith: [ProfileWhereInput!] +} +type Profile implements Node { + id: ID! + createdAt: Time! + updatedAt: Time + name: String + address: String + phone: String + posts( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Posts returned from the connection. + """ + orderBy: PostOrder + + """ + Filtering options for Posts returned from the connection. + """ + where: PostWhereInput + ): PostConnection! +} +""" +A connection to a list of items. +""" +type ProfileConnection { + """ + A list of edges. + """ + edges: [ProfileEdge] + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! + """ + Identifies the total count of items in the connection. + """ + totalCount: Int! +} +""" +An edge in a connection. +""" +type ProfileEdge { + """ + The item at the end of the edge. + """ + node: Profile + """ + A cursor for use in pagination. + """ + cursor: Cursor! +} +""" +Ordering options for Profile connections +""" +input ProfileOrder { + """ + The ordering direction. + """ + direction: OrderDirection! = ASC + """ + The field by which to order Profiles. + """ + field: ProfileOrderField! +} +""" +Properties by which Profile connections can be ordered. +""" +enum ProfileOrderField { + CREATED_AT + UPDATED_AT + POSTS_COUNT +} +""" +ProfileWhereInput is used for filtering Profile objects. +Input was generated by ent. +""" +input ProfileWhereInput { + not: ProfileWhereInput + and: [ProfileWhereInput!] + or: [ProfileWhereInput!] + """ + id field predicates + """ + id: ID + idNEQ: ID + idIn: [ID!] + idNotIn: [ID!] + idGT: ID + idGTE: ID + idLT: ID + idLTE: ID + """ + created_at field predicates + """ + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """ + updated_at field predicates + """ + updatedAt: Time + updatedAtNEQ: Time + updatedAtIn: [Time!] + updatedAtNotIn: [Time!] + updatedAtGT: Time + updatedAtGTE: Time + updatedAtLT: Time + updatedAtLTE: Time + updatedAtIsNil: Boolean + updatedAtNotNil: Boolean + """ + 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 + """ + address field predicates + """ + address: String + addressNEQ: String + addressIn: [String!] + addressNotIn: [String!] + addressGT: String + addressGTE: String + addressLT: String + addressLTE: String + addressContains: String + addressHasPrefix: String + addressHasSuffix: String + addressIsNil: Boolean + addressNotNil: Boolean + addressEqualFold: String + addressContainsFold: String + """ + phone field predicates + """ + phone: String + phoneNEQ: String + phoneIn: [String!] + phoneNotIn: [String!] + phoneGT: String + phoneGTE: String + phoneLT: String + phoneLTE: String + phoneContains: String + phoneHasPrefix: String + phoneHasSuffix: String + phoneIsNil: Boolean + phoneNotNil: Boolean + phoneEqualFold: String + phoneContainsFold: String + """ + posts edge predicates + """ + hasPosts: Boolean + hasPostsWith: [PostWhereInput!] +} +type Query { + """ + Fetches an object given its ID. + """ + node( + """ + ID of the object. + """ + id: ID! + ): Node + """ + Lookup nodes by a list of IDs. + """ + nodes( + """ + The list of node IDs. + """ + ids: [ID!]! + ): [Node]! + categories( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Categories returned from the connection. + """ + orderBy: CategoryOrder + + """ + Filtering options for Categories returned from the connection. + """ + where: CategoryWhereInput + ): CategoryConnection! + posts( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Posts returned from the connection. + """ + orderBy: PostOrder + + """ + Filtering options for Posts returned from the connection. + """ + where: PostWhereInput + ): PostConnection! + profiles( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Profiles returned from the connection. + """ + orderBy: ProfileOrder + + """ + Filtering options for Profiles returned from the connection. + """ + where: ProfileWhereInput + ): ProfileConnection! +} +""" +The builtin Time type +""" +scalar Time +""" +UpdateCategoryInput is used for update Category object. +Input was generated by ent. +""" +input UpdateCategoryInput { + updatedAt: Time + clearUpdatedAt: Boolean + title: String + description: String + clearDescription: Boolean + addPostIDs: [ID!] + removePostIDs: [ID!] + clearPosts: Boolean +} +""" +UpdatePostInput is used for update Post object. +Input was generated by ent. +""" +input UpdatePostInput { + updatedAt: Time + clearUpdatedAt: Boolean + expires: Boolean + expireTime: Time + clearExpireTime: Boolean + title: String + body: String + categoryID: ID + clearCategory: Boolean + profileID: ID + clearProfile: Boolean +} +""" +UpdateProfileInput is used for update Profile object. +Input was generated by ent. +""" +input UpdateProfileInput { + updatedAt: Time + clearUpdatedAt: Boolean + name: String + clearName: Boolean + address: String + clearAddress: Boolean + phone: String + clearPhone: Boolean + addPostIDs: [ID!] + removePostIDs: [ID!] + clearPosts: Boolean +} diff --git a/ent/category.go b/ent/category.go new file mode 100644 index 0000000..8015c40 --- /dev/null +++ b/ent/category.go @@ -0,0 +1,194 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "code.icod.de/dalu/ka/ent/category" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" +) + +// Category is the model entity for the Category schema. +type Category struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Title holds the value of the "title" field. + Title string `json:"title,omitempty"` + // Description holds the value of the "description" field. + Description string `json:"description,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the CategoryQuery when eager-loading is set. + Edges CategoryEdges `json:"edges"` + selectValues sql.SelectValues +} + +// CategoryEdges holds the relations/edges for other nodes in the graph. +type CategoryEdges struct { + // Posts holds the value of the posts edge. + Posts []*Post `json:"posts,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool + // totalCount holds the count of the edges above. + totalCount [1]map[string]int + + namedPosts map[string][]*Post +} + +// PostsOrErr returns the Posts value or an error if the edge +// was not loaded in eager-loading. +func (e CategoryEdges) PostsOrErr() ([]*Post, error) { + if e.loadedTypes[0] { + return e.Posts, nil + } + return nil, &NotLoadedError{edge: "posts"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Category) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case category.FieldTitle, category.FieldDescription: + values[i] = new(sql.NullString) + case category.FieldCreatedAt, category.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case category.FieldID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Category fields. +func (c *Category) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case category.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + c.ID = *value + } + case category.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + c.CreatedAt = value.Time + } + case category.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + c.UpdatedAt = value.Time + } + case category.FieldTitle: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field title", values[i]) + } else if value.Valid { + c.Title = value.String + } + case category.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + c.Description = value.String + } + default: + c.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Category. +// This includes values selected through modifiers, order, etc. +func (c *Category) Value(name string) (ent.Value, error) { + return c.selectValues.Get(name) +} + +// QueryPosts queries the "posts" edge of the Category entity. +func (c *Category) QueryPosts() *PostQuery { + return NewCategoryClient(c.config).QueryPosts(c) +} + +// Update returns a builder for updating this Category. +// Note that you need to call Category.Unwrap() before calling this method if this Category +// was returned from a transaction, and the transaction was committed or rolled back. +func (c *Category) Update() *CategoryUpdateOne { + return NewCategoryClient(c.config).UpdateOne(c) +} + +// Unwrap unwraps the Category entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (c *Category) Unwrap() *Category { + _tx, ok := c.config.driver.(*txDriver) + if !ok { + panic("ent: Category is not a transactional entity") + } + c.config.driver = _tx.drv + return c +} + +// String implements the fmt.Stringer. +func (c *Category) String() string { + var builder strings.Builder + builder.WriteString("Category(") + builder.WriteString(fmt.Sprintf("id=%v, ", c.ID)) + builder.WriteString("created_at=") + builder.WriteString(c.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(c.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("title=") + builder.WriteString(c.Title) + builder.WriteString(", ") + builder.WriteString("description=") + builder.WriteString(c.Description) + builder.WriteByte(')') + return builder.String() +} + +// NamedPosts returns the Posts named value or an error if the edge was not +// loaded in eager-loading with this name. +func (c *Category) NamedPosts(name string) ([]*Post, error) { + if c.Edges.namedPosts == nil { + return nil, &NotLoadedError{edge: name} + } + nodes, ok := c.Edges.namedPosts[name] + if !ok { + return nil, &NotLoadedError{edge: name} + } + return nodes, nil +} + +func (c *Category) appendNamedPosts(name string, edges ...*Post) { + if c.Edges.namedPosts == nil { + c.Edges.namedPosts = make(map[string][]*Post) + } + if len(edges) == 0 { + c.Edges.namedPosts[name] = []*Post{} + } else { + c.Edges.namedPosts[name] = append(c.Edges.namedPosts[name], edges...) + } +} + +// Categories is a parsable slice of Category. +type Categories []*Category diff --git a/ent/category/category.go b/ent/category/category.go new file mode 100644 index 0000000..b323f6a --- /dev/null +++ b/ent/category/category.go @@ -0,0 +1,118 @@ +// Code generated by ent, DO NOT EDIT. + +package category + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the category type in the database. + Label = "category" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldTitle holds the string denoting the title field in the database. + FieldTitle = "title" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // EdgePosts holds the string denoting the posts edge name in mutations. + EdgePosts = "posts" + // Table holds the table name of the category in the database. + Table = "categories" + // PostsTable is the table that holds the posts relation/edge. + PostsTable = "posts" + // PostsInverseTable is the table name for the Post entity. + // It exists in this package in order to avoid circular dependency with the "post" package. + PostsInverseTable = "posts" + // PostsColumn is the table column denoting the posts relation/edge. + PostsColumn = "category_posts" +) + +// Columns holds all SQL columns for category fields. +var Columns = []string{ + FieldID, + FieldCreatedAt, + FieldUpdatedAt, + FieldTitle, + FieldDescription, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // TitleValidator is a validator for the "title" field. It is called by the builders before save. + TitleValidator func(string) error + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the Category queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByTitle orders the results by the title field. +func ByTitle(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTitle, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByPostsCount orders the results by posts count. +func ByPostsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newPostsStep(), opts...) + } +} + +// ByPosts orders the results by posts terms. +func ByPosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newPostsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newPostsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(PostsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, PostsTable, PostsColumn), + ) +} diff --git a/ent/category/where.go b/ent/category/where.go new file mode 100644 index 0000000..f388fb5 --- /dev/null +++ b/ent/category/where.go @@ -0,0 +1,345 @@ +// Code generated by ent, DO NOT EDIT. + +package category + +import ( + "time" + + "code.icod.de/dalu/ka/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Category { + return predicate.Category(sql.FieldLTE(FieldID, id)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// Title applies equality check predicate on the "title" field. It's identical to TitleEQ. +func Title(v string) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldTitle, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldDescription, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Category { + return predicate.Category(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Category { + return predicate.Category(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Category { + return predicate.Category(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Category { + return predicate.Category(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Category { + return predicate.Category(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Category { + return predicate.Category(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Category { + return predicate.Category(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Category { + return predicate.Category(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Category { + return predicate.Category(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Category { + return predicate.Category(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Category { + return predicate.Category(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Category { + return predicate.Category(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Category { + return predicate.Category(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Category { + return predicate.Category(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field. +func UpdatedAtIsNil() predicate.Category { + return predicate.Category(sql.FieldIsNull(FieldUpdatedAt)) +} + +// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field. +func UpdatedAtNotNil() predicate.Category { + return predicate.Category(sql.FieldNotNull(FieldUpdatedAt)) +} + +// TitleEQ applies the EQ predicate on the "title" field. +func TitleEQ(v string) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldTitle, v)) +} + +// TitleNEQ applies the NEQ predicate on the "title" field. +func TitleNEQ(v string) predicate.Category { + return predicate.Category(sql.FieldNEQ(FieldTitle, v)) +} + +// TitleIn applies the In predicate on the "title" field. +func TitleIn(vs ...string) predicate.Category { + return predicate.Category(sql.FieldIn(FieldTitle, vs...)) +} + +// TitleNotIn applies the NotIn predicate on the "title" field. +func TitleNotIn(vs ...string) predicate.Category { + return predicate.Category(sql.FieldNotIn(FieldTitle, vs...)) +} + +// TitleGT applies the GT predicate on the "title" field. +func TitleGT(v string) predicate.Category { + return predicate.Category(sql.FieldGT(FieldTitle, v)) +} + +// TitleGTE applies the GTE predicate on the "title" field. +func TitleGTE(v string) predicate.Category { + return predicate.Category(sql.FieldGTE(FieldTitle, v)) +} + +// TitleLT applies the LT predicate on the "title" field. +func TitleLT(v string) predicate.Category { + return predicate.Category(sql.FieldLT(FieldTitle, v)) +} + +// TitleLTE applies the LTE predicate on the "title" field. +func TitleLTE(v string) predicate.Category { + return predicate.Category(sql.FieldLTE(FieldTitle, v)) +} + +// TitleContains applies the Contains predicate on the "title" field. +func TitleContains(v string) predicate.Category { + return predicate.Category(sql.FieldContains(FieldTitle, v)) +} + +// TitleHasPrefix applies the HasPrefix predicate on the "title" field. +func TitleHasPrefix(v string) predicate.Category { + return predicate.Category(sql.FieldHasPrefix(FieldTitle, v)) +} + +// TitleHasSuffix applies the HasSuffix predicate on the "title" field. +func TitleHasSuffix(v string) predicate.Category { + return predicate.Category(sql.FieldHasSuffix(FieldTitle, v)) +} + +// TitleEqualFold applies the EqualFold predicate on the "title" field. +func TitleEqualFold(v string) predicate.Category { + return predicate.Category(sql.FieldEqualFold(FieldTitle, v)) +} + +// TitleContainsFold applies the ContainsFold predicate on the "title" field. +func TitleContainsFold(v string) predicate.Category { + return predicate.Category(sql.FieldContainsFold(FieldTitle, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.Category { + return predicate.Category(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.Category { + return predicate.Category(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.Category { + return predicate.Category(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.Category { + return predicate.Category(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.Category { + return predicate.Category(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.Category { + return predicate.Category(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.Category { + return predicate.Category(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.Category { + return predicate.Category(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.Category { + return predicate.Category(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.Category { + return predicate.Category(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.Category { + return predicate.Category(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.Category { + return predicate.Category(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.Category { + return predicate.Category(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.Category { + return predicate.Category(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.Category { + return predicate.Category(sql.FieldContainsFold(FieldDescription, v)) +} + +// HasPosts applies the HasEdge predicate on the "posts" edge. +func HasPosts() predicate.Category { + return predicate.Category(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, PostsTable, PostsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasPostsWith applies the HasEdge predicate on the "posts" edge with a given conditions (other predicates). +func HasPostsWith(preds ...predicate.Post) predicate.Category { + return predicate.Category(func(s *sql.Selector) { + step := newPostsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Category) predicate.Category { + return predicate.Category(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Category) predicate.Category { + return predicate.Category(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Category) predicate.Category { + return predicate.Category(sql.NotPredicates(p)) +} diff --git a/ent/category_create.go b/ent/category_create.go new file mode 100644 index 0000000..f8a81ab --- /dev/null +++ b/ent/category_create.go @@ -0,0 +1,316 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// CategoryCreate is the builder for creating a Category entity. +type CategoryCreate struct { + config + mutation *CategoryMutation + hooks []Hook +} + +// SetCreatedAt sets the "created_at" field. +func (cc *CategoryCreate) SetCreatedAt(t time.Time) *CategoryCreate { + cc.mutation.SetCreatedAt(t) + return cc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (cc *CategoryCreate) SetNillableCreatedAt(t *time.Time) *CategoryCreate { + if t != nil { + cc.SetCreatedAt(*t) + } + return cc +} + +// SetUpdatedAt sets the "updated_at" field. +func (cc *CategoryCreate) SetUpdatedAt(t time.Time) *CategoryCreate { + cc.mutation.SetUpdatedAt(t) + return cc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (cc *CategoryCreate) SetNillableUpdatedAt(t *time.Time) *CategoryCreate { + if t != nil { + cc.SetUpdatedAt(*t) + } + return cc +} + +// SetTitle sets the "title" field. +func (cc *CategoryCreate) SetTitle(s string) *CategoryCreate { + cc.mutation.SetTitle(s) + return cc +} + +// SetDescription sets the "description" field. +func (cc *CategoryCreate) SetDescription(s string) *CategoryCreate { + cc.mutation.SetDescription(s) + return cc +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (cc *CategoryCreate) SetNillableDescription(s *string) *CategoryCreate { + if s != nil { + cc.SetDescription(*s) + } + return cc +} + +// SetID sets the "id" field. +func (cc *CategoryCreate) SetID(u uuid.UUID) *CategoryCreate { + cc.mutation.SetID(u) + return cc +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (cc *CategoryCreate) SetNillableID(u *uuid.UUID) *CategoryCreate { + if u != nil { + cc.SetID(*u) + } + return cc +} + +// AddPostIDs adds the "posts" edge to the Post entity by IDs. +func (cc *CategoryCreate) AddPostIDs(ids ...uuid.UUID) *CategoryCreate { + cc.mutation.AddPostIDs(ids...) + return cc +} + +// AddPosts adds the "posts" edges to the Post entity. +func (cc *CategoryCreate) AddPosts(p ...*Post) *CategoryCreate { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return cc.AddPostIDs(ids...) +} + +// Mutation returns the CategoryMutation object of the builder. +func (cc *CategoryCreate) Mutation() *CategoryMutation { + return cc.mutation +} + +// Save creates the Category in the database. +func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) { + cc.defaults() + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (cc *CategoryCreate) SaveX(ctx context.Context) *Category { + v, err := cc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (cc *CategoryCreate) Exec(ctx context.Context) error { + _, err := cc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (cc *CategoryCreate) ExecX(ctx context.Context) { + if err := cc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (cc *CategoryCreate) defaults() { + if _, ok := cc.mutation.CreatedAt(); !ok { + v := category.DefaultCreatedAt() + cc.mutation.SetCreatedAt(v) + } + if _, ok := cc.mutation.UpdatedAt(); !ok { + v := category.DefaultUpdatedAt() + cc.mutation.SetUpdatedAt(v) + } + if _, ok := cc.mutation.ID(); !ok { + v := category.DefaultID() + cc.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (cc *CategoryCreate) check() error { + if _, ok := cc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Category.created_at"`)} + } + if _, ok := cc.mutation.Title(); !ok { + return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Category.title"`)} + } + if v, ok := cc.mutation.Title(); ok { + if err := category.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Category.title": %w`, err)} + } + } + return nil +} + +func (cc *CategoryCreate) sqlSave(ctx context.Context) (*Category, error) { + if err := cc.check(); err != nil { + return nil, err + } + _node, _spec := cc.createSpec() + if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + cc.mutation.id = &_node.ID + cc.mutation.done = true + return _node, nil +} + +func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) { + var ( + _node = &Category{config: cc.config} + _spec = sqlgraph.NewCreateSpec(category.Table, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID)) + ) + if id, ok := cc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := cc.mutation.CreatedAt(); ok { + _spec.SetField(category.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := cc.mutation.UpdatedAt(); ok { + _spec.SetField(category.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := cc.mutation.Title(); ok { + _spec.SetField(category.FieldTitle, field.TypeString, value) + _node.Title = value + } + if value, ok := cc.mutation.Description(); ok { + _spec.SetField(category.FieldDescription, field.TypeString, value) + _node.Description = value + } + if nodes := cc.mutation.PostsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: category.PostsTable, + Columns: []string{category.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// CategoryCreateBulk is the builder for creating many Category entities in bulk. +type CategoryCreateBulk struct { + config + err error + builders []*CategoryCreate +} + +// Save creates the Category entities in the database. +func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) { + if ccb.err != nil { + return nil, ccb.err + } + specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) + nodes := make([]*Category, len(ccb.builders)) + mutators := make([]Mutator, len(ccb.builders)) + for i := range ccb.builders { + func(i int, root context.Context) { + builder := ccb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*CategoryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, ccb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, ccb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (ccb *CategoryCreateBulk) SaveX(ctx context.Context) []*Category { + v, err := ccb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (ccb *CategoryCreateBulk) Exec(ctx context.Context) error { + _, err := ccb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ccb *CategoryCreateBulk) ExecX(ctx context.Context) { + if err := ccb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/category_delete.go b/ent/category_delete.go new file mode 100644 index 0000000..9909633 --- /dev/null +++ b/ent/category_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// CategoryDelete is the builder for deleting a Category entity. +type CategoryDelete struct { + config + hooks []Hook + mutation *CategoryMutation +} + +// Where appends a list predicates to the CategoryDelete builder. +func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete { + cd.mutation.Where(ps...) + return cd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (cd *CategoryDelete) ExecX(ctx context.Context) int { + n, err := cd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (cd *CategoryDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(category.Table, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID)) + if ps := cd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, cd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + cd.mutation.done = true + return affected, err +} + +// CategoryDeleteOne is the builder for deleting a single Category entity. +type CategoryDeleteOne struct { + cd *CategoryDelete +} + +// Where appends a list predicates to the CategoryDelete builder. +func (cdo *CategoryDeleteOne) Where(ps ...predicate.Category) *CategoryDeleteOne { + cdo.cd.mutation.Where(ps...) + return cdo +} + +// Exec executes the deletion query. +func (cdo *CategoryDeleteOne) Exec(ctx context.Context) error { + n, err := cdo.cd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{category.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (cdo *CategoryDeleteOne) ExecX(ctx context.Context) { + if err := cdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/category_query.go b/ent/category_query.go new file mode 100644 index 0000000..ce78a74 --- /dev/null +++ b/ent/category_query.go @@ -0,0 +1,643 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// CategoryQuery is the builder for querying Category entities. +type CategoryQuery struct { + config + ctx *QueryContext + order []category.OrderOption + inters []Interceptor + predicates []predicate.Category + withPosts *PostQuery + modifiers []func(*sql.Selector) + loadTotal []func(context.Context, []*Category) error + withNamedPosts map[string]*PostQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the CategoryQuery builder. +func (cq *CategoryQuery) Where(ps ...predicate.Category) *CategoryQuery { + cq.predicates = append(cq.predicates, ps...) + return cq +} + +// Limit the number of records to be returned by this query. +func (cq *CategoryQuery) Limit(limit int) *CategoryQuery { + cq.ctx.Limit = &limit + return cq +} + +// Offset to start from. +func (cq *CategoryQuery) Offset(offset int) *CategoryQuery { + cq.ctx.Offset = &offset + return cq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (cq *CategoryQuery) Unique(unique bool) *CategoryQuery { + cq.ctx.Unique = &unique + return cq +} + +// Order specifies how the records should be ordered. +func (cq *CategoryQuery) Order(o ...category.OrderOption) *CategoryQuery { + cq.order = append(cq.order, o...) + return cq +} + +// QueryPosts chains the current query on the "posts" edge. +func (cq *CategoryQuery) QueryPosts() *PostQuery { + query := (&PostClient{config: cq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := cq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := cq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(category.Table, category.FieldID, selector), + sqlgraph.To(post.Table, post.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, category.PostsTable, category.PostsColumn), + ) + fromU = sqlgraph.SetNeighbors(cq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Category entity from the query. +// Returns a *NotFoundError when no Category was found. +func (cq *CategoryQuery) First(ctx context.Context) (*Category, error) { + nodes, err := cq.Limit(1).All(setContextOp(ctx, cq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{category.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (cq *CategoryQuery) FirstX(ctx context.Context) *Category { + node, err := cq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Category ID from the query. +// Returns a *NotFoundError when no Category ID was found. +func (cq *CategoryQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = cq.Limit(1).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{category.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (cq *CategoryQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := cq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Category entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Category entity is found. +// Returns a *NotFoundError when no Category entities are found. +func (cq *CategoryQuery) Only(ctx context.Context) (*Category, error) { + nodes, err := cq.Limit(2).All(setContextOp(ctx, cq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{category.Label} + default: + return nil, &NotSingularError{category.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (cq *CategoryQuery) OnlyX(ctx context.Context) *Category { + node, err := cq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Category ID in the query. +// Returns a *NotSingularError when more than one Category ID is found. +// Returns a *NotFoundError when no entities are found. +func (cq *CategoryQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = cq.Limit(2).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{category.Label} + default: + err = &NotSingularError{category.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (cq *CategoryQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := cq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Categories. +func (cq *CategoryQuery) All(ctx context.Context) ([]*Category, error) { + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryAll) + if err := cq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Category, *CategoryQuery]() + return withInterceptors[[]*Category](ctx, cq, qr, cq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (cq *CategoryQuery) AllX(ctx context.Context) []*Category { + nodes, err := cq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Category IDs. +func (cq *CategoryQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if cq.ctx.Unique == nil && cq.path != nil { + cq.Unique(true) + } + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryIDs) + if err = cq.Select(category.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (cq *CategoryQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := cq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (cq *CategoryQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryCount) + if err := cq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, cq, querierCount[*CategoryQuery](), cq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (cq *CategoryQuery) CountX(ctx context.Context) int { + count, err := cq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (cq *CategoryQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryExist) + switch _, err := cq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (cq *CategoryQuery) ExistX(ctx context.Context) bool { + exist, err := cq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the CategoryQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (cq *CategoryQuery) Clone() *CategoryQuery { + if cq == nil { + return nil + } + return &CategoryQuery{ + config: cq.config, + ctx: cq.ctx.Clone(), + order: append([]category.OrderOption{}, cq.order...), + inters: append([]Interceptor{}, cq.inters...), + predicates: append([]predicate.Category{}, cq.predicates...), + withPosts: cq.withPosts.Clone(), + // clone intermediate query. + sql: cq.sql.Clone(), + path: cq.path, + } +} + +// WithPosts tells the query-builder to eager-load the nodes that are connected to +// the "posts" edge. The optional arguments are used to configure the query builder of the edge. +func (cq *CategoryQuery) WithPosts(opts ...func(*PostQuery)) *CategoryQuery { + query := (&PostClient{config: cq.config}).Query() + for _, opt := range opts { + opt(query) + } + cq.withPosts = query + return cq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Category.Query(). +// GroupBy(category.FieldCreatedAt). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (cq *CategoryQuery) GroupBy(field string, fields ...string) *CategoryGroupBy { + cq.ctx.Fields = append([]string{field}, fields...) + grbuild := &CategoryGroupBy{build: cq} + grbuild.flds = &cq.ctx.Fields + grbuild.label = category.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// } +// +// client.Category.Query(). +// Select(category.FieldCreatedAt). +// Scan(ctx, &v) +func (cq *CategoryQuery) Select(fields ...string) *CategorySelect { + cq.ctx.Fields = append(cq.ctx.Fields, fields...) + sbuild := &CategorySelect{CategoryQuery: cq} + sbuild.label = category.Label + sbuild.flds, sbuild.scan = &cq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a CategorySelect configured with the given aggregations. +func (cq *CategoryQuery) Aggregate(fns ...AggregateFunc) *CategorySelect { + return cq.Select().Aggregate(fns...) +} + +func (cq *CategoryQuery) prepareQuery(ctx context.Context) error { + for _, inter := range cq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, cq); err != nil { + return err + } + } + } + for _, f := range cq.ctx.Fields { + if !category.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if cq.path != nil { + prev, err := cq.path(ctx) + if err != nil { + return err + } + cq.sql = prev + } + return nil +} + +func (cq *CategoryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Category, error) { + var ( + nodes = []*Category{} + _spec = cq.querySpec() + loadedTypes = [1]bool{ + cq.withPosts != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Category).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Category{config: cq.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(cq.modifiers) > 0 { + _spec.Modifiers = cq.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := cq.withPosts; query != nil { + if err := cq.loadPosts(ctx, query, nodes, + func(n *Category) { n.Edges.Posts = []*Post{} }, + func(n *Category, e *Post) { n.Edges.Posts = append(n.Edges.Posts, e) }); err != nil { + return nil, err + } + } + for name, query := range cq.withNamedPosts { + if err := cq.loadPosts(ctx, query, nodes, + func(n *Category) { n.appendNamedPosts(name) }, + func(n *Category, e *Post) { n.appendNamedPosts(name, e) }); err != nil { + return nil, err + } + } + for i := range cq.loadTotal { + if err := cq.loadTotal[i](ctx, nodes); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (cq *CategoryQuery) loadPosts(ctx context.Context, query *PostQuery, nodes []*Category, init func(*Category), assign func(*Category, *Post)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Category) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + query.withFKs = true + query.Where(predicate.Post(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(category.PostsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.category_posts + if fk == nil { + return fmt.Errorf(`foreign-key "category_posts" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "category_posts" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} + +func (cq *CategoryQuery) sqlCount(ctx context.Context) (int, error) { + _spec := cq.querySpec() + if len(cq.modifiers) > 0 { + _spec.Modifiers = cq.modifiers + } + _spec.Node.Columns = cq.ctx.Fields + if len(cq.ctx.Fields) > 0 { + _spec.Unique = cq.ctx.Unique != nil && *cq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, cq.driver, _spec) +} + +func (cq *CategoryQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(category.Table, category.Columns, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID)) + _spec.From = cq.sql + if unique := cq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if cq.path != nil { + _spec.Unique = true + } + if fields := cq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, category.FieldID) + for i := range fields { + if fields[i] != category.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := cq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := cq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := cq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := cq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (cq *CategoryQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(cq.driver.Dialect()) + t1 := builder.Table(category.Table) + columns := cq.ctx.Fields + if len(columns) == 0 { + columns = category.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if cq.sql != nil { + selector = cq.sql + selector.Select(selector.Columns(columns...)...) + } + if cq.ctx.Unique != nil && *cq.ctx.Unique { + selector.Distinct() + } + for _, p := range cq.predicates { + p(selector) + } + for _, p := range cq.order { + p(selector) + } + if offset := cq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := cq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// WithNamedPosts tells the query-builder to eager-load the nodes that are connected to the "posts" +// edge with the given name. The optional arguments are used to configure the query builder of the edge. +func (cq *CategoryQuery) WithNamedPosts(name string, opts ...func(*PostQuery)) *CategoryQuery { + query := (&PostClient{config: cq.config}).Query() + for _, opt := range opts { + opt(query) + } + if cq.withNamedPosts == nil { + cq.withNamedPosts = make(map[string]*PostQuery) + } + cq.withNamedPosts[name] = query + return cq +} + +// CategoryGroupBy is the group-by builder for Category entities. +type CategoryGroupBy struct { + selector + build *CategoryQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (cgb *CategoryGroupBy) Aggregate(fns ...AggregateFunc) *CategoryGroupBy { + cgb.fns = append(cgb.fns, fns...) + return cgb +} + +// Scan applies the selector query and scans the result into the given value. +func (cgb *CategoryGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, cgb.build.ctx, ent.OpQueryGroupBy) + if err := cgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*CategoryQuery, *CategoryGroupBy](ctx, cgb.build, cgb, cgb.build.inters, v) +} + +func (cgb *CategoryGroupBy) sqlScan(ctx context.Context, root *CategoryQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(cgb.fns)) + for _, fn := range cgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*cgb.flds)+len(cgb.fns)) + for _, f := range *cgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*cgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := cgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// CategorySelect is the builder for selecting fields of Category entities. +type CategorySelect struct { + *CategoryQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (cs *CategorySelect) Aggregate(fns ...AggregateFunc) *CategorySelect { + cs.fns = append(cs.fns, fns...) + return cs +} + +// Scan applies the selector query and scans the result into the given value. +func (cs *CategorySelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, cs.ctx, ent.OpQuerySelect) + if err := cs.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*CategoryQuery, *CategorySelect](ctx, cs.CategoryQuery, cs, cs.inters, v) +} + +func (cs *CategorySelect) sqlScan(ctx context.Context, root *CategoryQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(cs.fns)) + for _, fn := range cs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*cs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := cs.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/category_update.go b/ent/category_update.go new file mode 100644 index 0000000..edd0ec8 --- /dev/null +++ b/ent/category_update.go @@ -0,0 +1,506 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// CategoryUpdate is the builder for updating Category entities. +type CategoryUpdate struct { + config + hooks []Hook + mutation *CategoryMutation +} + +// Where appends a list predicates to the CategoryUpdate builder. +func (cu *CategoryUpdate) Where(ps ...predicate.Category) *CategoryUpdate { + cu.mutation.Where(ps...) + return cu +} + +// SetUpdatedAt sets the "updated_at" field. +func (cu *CategoryUpdate) SetUpdatedAt(t time.Time) *CategoryUpdate { + cu.mutation.SetUpdatedAt(t) + return cu +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (cu *CategoryUpdate) ClearUpdatedAt() *CategoryUpdate { + cu.mutation.ClearUpdatedAt() + return cu +} + +// SetTitle sets the "title" field. +func (cu *CategoryUpdate) SetTitle(s string) *CategoryUpdate { + cu.mutation.SetTitle(s) + return cu +} + +// SetNillableTitle sets the "title" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableTitle(s *string) *CategoryUpdate { + if s != nil { + cu.SetTitle(*s) + } + return cu +} + +// SetDescription sets the "description" field. +func (cu *CategoryUpdate) SetDescription(s string) *CategoryUpdate { + cu.mutation.SetDescription(s) + return cu +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (cu *CategoryUpdate) SetNillableDescription(s *string) *CategoryUpdate { + if s != nil { + cu.SetDescription(*s) + } + return cu +} + +// ClearDescription clears the value of the "description" field. +func (cu *CategoryUpdate) ClearDescription() *CategoryUpdate { + cu.mutation.ClearDescription() + return cu +} + +// AddPostIDs adds the "posts" edge to the Post entity by IDs. +func (cu *CategoryUpdate) AddPostIDs(ids ...uuid.UUID) *CategoryUpdate { + cu.mutation.AddPostIDs(ids...) + return cu +} + +// AddPosts adds the "posts" edges to the Post entity. +func (cu *CategoryUpdate) AddPosts(p ...*Post) *CategoryUpdate { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return cu.AddPostIDs(ids...) +} + +// Mutation returns the CategoryMutation object of the builder. +func (cu *CategoryUpdate) Mutation() *CategoryMutation { + return cu.mutation +} + +// ClearPosts clears all "posts" edges to the Post entity. +func (cu *CategoryUpdate) ClearPosts() *CategoryUpdate { + cu.mutation.ClearPosts() + return cu +} + +// RemovePostIDs removes the "posts" edge to Post entities by IDs. +func (cu *CategoryUpdate) RemovePostIDs(ids ...uuid.UUID) *CategoryUpdate { + cu.mutation.RemovePostIDs(ids...) + return cu +} + +// RemovePosts removes "posts" edges to Post entities. +func (cu *CategoryUpdate) RemovePosts(p ...*Post) *CategoryUpdate { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return cu.RemovePostIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) { + cu.defaults() + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (cu *CategoryUpdate) SaveX(ctx context.Context) int { + affected, err := cu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (cu *CategoryUpdate) Exec(ctx context.Context) error { + _, err := cu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (cu *CategoryUpdate) ExecX(ctx context.Context) { + if err := cu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (cu *CategoryUpdate) defaults() { + if _, ok := cu.mutation.UpdatedAt(); !ok && !cu.mutation.UpdatedAtCleared() { + v := category.UpdateDefaultUpdatedAt() + cu.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (cu *CategoryUpdate) check() error { + if v, ok := cu.mutation.Title(); ok { + if err := category.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Category.title": %w`, err)} + } + } + return nil +} + +func (cu *CategoryUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := cu.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(category.Table, category.Columns, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID)) + if ps := cu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := cu.mutation.UpdatedAt(); ok { + _spec.SetField(category.FieldUpdatedAt, field.TypeTime, value) + } + if cu.mutation.UpdatedAtCleared() { + _spec.ClearField(category.FieldUpdatedAt, field.TypeTime) + } + if value, ok := cu.mutation.Title(); ok { + _spec.SetField(category.FieldTitle, field.TypeString, value) + } + if value, ok := cu.mutation.Description(); ok { + _spec.SetField(category.FieldDescription, field.TypeString, value) + } + if cu.mutation.DescriptionCleared() { + _spec.ClearField(category.FieldDescription, field.TypeString) + } + if cu.mutation.PostsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: category.PostsTable, + Columns: []string{category.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := cu.mutation.RemovedPostsIDs(); len(nodes) > 0 && !cu.mutation.PostsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: category.PostsTable, + Columns: []string{category.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := cu.mutation.PostsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: category.PostsTable, + Columns: []string{category.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{category.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + cu.mutation.done = true + return n, nil +} + +// CategoryUpdateOne is the builder for updating a single Category entity. +type CategoryUpdateOne struct { + config + fields []string + hooks []Hook + mutation *CategoryMutation +} + +// SetUpdatedAt sets the "updated_at" field. +func (cuo *CategoryUpdateOne) SetUpdatedAt(t time.Time) *CategoryUpdateOne { + cuo.mutation.SetUpdatedAt(t) + return cuo +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (cuo *CategoryUpdateOne) ClearUpdatedAt() *CategoryUpdateOne { + cuo.mutation.ClearUpdatedAt() + return cuo +} + +// SetTitle sets the "title" field. +func (cuo *CategoryUpdateOne) SetTitle(s string) *CategoryUpdateOne { + cuo.mutation.SetTitle(s) + return cuo +} + +// SetNillableTitle sets the "title" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableTitle(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetTitle(*s) + } + return cuo +} + +// SetDescription sets the "description" field. +func (cuo *CategoryUpdateOne) SetDescription(s string) *CategoryUpdateOne { + cuo.mutation.SetDescription(s) + return cuo +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (cuo *CategoryUpdateOne) SetNillableDescription(s *string) *CategoryUpdateOne { + if s != nil { + cuo.SetDescription(*s) + } + return cuo +} + +// ClearDescription clears the value of the "description" field. +func (cuo *CategoryUpdateOne) ClearDescription() *CategoryUpdateOne { + cuo.mutation.ClearDescription() + return cuo +} + +// AddPostIDs adds the "posts" edge to the Post entity by IDs. +func (cuo *CategoryUpdateOne) AddPostIDs(ids ...uuid.UUID) *CategoryUpdateOne { + cuo.mutation.AddPostIDs(ids...) + return cuo +} + +// AddPosts adds the "posts" edges to the Post entity. +func (cuo *CategoryUpdateOne) AddPosts(p ...*Post) *CategoryUpdateOne { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return cuo.AddPostIDs(ids...) +} + +// Mutation returns the CategoryMutation object of the builder. +func (cuo *CategoryUpdateOne) Mutation() *CategoryMutation { + return cuo.mutation +} + +// ClearPosts clears all "posts" edges to the Post entity. +func (cuo *CategoryUpdateOne) ClearPosts() *CategoryUpdateOne { + cuo.mutation.ClearPosts() + return cuo +} + +// RemovePostIDs removes the "posts" edge to Post entities by IDs. +func (cuo *CategoryUpdateOne) RemovePostIDs(ids ...uuid.UUID) *CategoryUpdateOne { + cuo.mutation.RemovePostIDs(ids...) + return cuo +} + +// RemovePosts removes "posts" edges to Post entities. +func (cuo *CategoryUpdateOne) RemovePosts(p ...*Post) *CategoryUpdateOne { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return cuo.RemovePostIDs(ids...) +} + +// Where appends a list predicates to the CategoryUpdate builder. +func (cuo *CategoryUpdateOne) Where(ps ...predicate.Category) *CategoryUpdateOne { + cuo.mutation.Where(ps...) + return cuo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUpdateOne { + cuo.fields = append([]string{field}, fields...) + return cuo +} + +// Save executes the query and returns the updated Category entity. +func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) { + cuo.defaults() + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (cuo *CategoryUpdateOne) SaveX(ctx context.Context) *Category { + node, err := cuo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (cuo *CategoryUpdateOne) Exec(ctx context.Context) error { + _, err := cuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (cuo *CategoryUpdateOne) ExecX(ctx context.Context) { + if err := cuo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (cuo *CategoryUpdateOne) defaults() { + if _, ok := cuo.mutation.UpdatedAt(); !ok && !cuo.mutation.UpdatedAtCleared() { + v := category.UpdateDefaultUpdatedAt() + cuo.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (cuo *CategoryUpdateOne) check() error { + if v, ok := cuo.mutation.Title(); ok { + if err := category.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Category.title": %w`, err)} + } + } + return nil +} + +func (cuo *CategoryUpdateOne) sqlSave(ctx context.Context) (_node *Category, err error) { + if err := cuo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(category.Table, category.Columns, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID)) + id, ok := cuo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Category.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := cuo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, category.FieldID) + for _, f := range fields { + if !category.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != category.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := cuo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := cuo.mutation.UpdatedAt(); ok { + _spec.SetField(category.FieldUpdatedAt, field.TypeTime, value) + } + if cuo.mutation.UpdatedAtCleared() { + _spec.ClearField(category.FieldUpdatedAt, field.TypeTime) + } + if value, ok := cuo.mutation.Title(); ok { + _spec.SetField(category.FieldTitle, field.TypeString, value) + } + if value, ok := cuo.mutation.Description(); ok { + _spec.SetField(category.FieldDescription, field.TypeString, value) + } + if cuo.mutation.DescriptionCleared() { + _spec.ClearField(category.FieldDescription, field.TypeString) + } + if cuo.mutation.PostsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: category.PostsTable, + Columns: []string{category.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := cuo.mutation.RemovedPostsIDs(); len(nodes) > 0 && !cuo.mutation.PostsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: category.PostsTable, + Columns: []string{category.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := cuo.mutation.PostsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: category.PostsTable, + Columns: []string{category.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Category{config: cuo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{category.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + cuo.mutation.done = true + return _node, nil +} diff --git a/ent/client.go b/ent/client.go new file mode 100644 index 0000000..df374f7 --- /dev/null +++ b/ent/client.go @@ -0,0 +1,692 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "log" + "reflect" + + "code.icod.de/dalu/ka/ent/migrate" + "github.com/google/uuid" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// Client is the client that holds all ent builders. +type Client struct { + config + // Schema is the client for creating, migrating and dropping schema. + Schema *migrate.Schema + // Category is the client for interacting with the Category builders. + Category *CategoryClient + // Post is the client for interacting with the Post builders. + Post *PostClient + // Profile is the client for interacting with the Profile builders. + Profile *ProfileClient +} + +// NewClient creates a new client configured with the given options. +func NewClient(opts ...Option) *Client { + client := &Client{config: newConfig(opts...)} + client.init() + return client +} + +func (c *Client) init() { + c.Schema = migrate.NewSchema(c.driver) + c.Category = NewCategoryClient(c.config) + c.Post = NewPostClient(c.config) + c.Profile = NewProfileClient(c.config) +} + +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// newConfig creates a new config for the client. +func newConfig(opts ...Option) config { + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} + cfg.options(opts...) + return cfg +} + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + +// Open opens a database/sql.DB specified by the driver name and +// the data source name, and returns a new client attached to it. +// Optional parameters can be added for configuring the client. +func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { + switch driverName { + case dialect.MySQL, dialect.Postgres, dialect.SQLite: + drv, err := sql.Open(driverName, dataSourceName) + if err != nil { + return nil, err + } + return NewClient(append(options, Driver(drv))...), nil + default: + return nil, fmt.Errorf("unsupported driver: %q", driverName) + } +} + +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + +// Tx returns a new transactional client. The provided context +// is used until the transaction is committed or rolled back. +func (c *Client) Tx(ctx context.Context) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, ErrTxStarted + } + tx, err := newTx(ctx, c.driver) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = tx + return &Tx{ + ctx: ctx, + config: cfg, + Category: NewCategoryClient(cfg), + Post: NewPostClient(cfg), + Profile: NewProfileClient(cfg), + }, nil +} + +// BeginTx returns a transactional client with specified options. +func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, errors.New("ent: cannot start a transaction within a transaction") + } + tx, err := c.driver.(interface { + BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) + }).BeginTx(ctx, opts) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = &txDriver{tx: tx, drv: c.driver} + return &Tx{ + ctx: ctx, + config: cfg, + Category: NewCategoryClient(cfg), + Post: NewPostClient(cfg), + Profile: NewProfileClient(cfg), + }, nil +} + +// Debug returns a new debug-client. It's used to get verbose logging on specific operations. +// +// client.Debug(). +// Category. +// Query(). +// Count(ctx) +func (c *Client) Debug() *Client { + if c.debug { + return c + } + cfg := c.config + cfg.driver = dialect.Debug(c.driver, c.log) + client := &Client{config: cfg} + client.init() + return client +} + +// Close closes the database connection and prevents new queries from starting. +func (c *Client) Close() error { + return c.driver.Close() +} + +// Use adds the mutation hooks to all the entity clients. +// In order to add hooks to a specific client, call: `client.Node.Use(...)`. +func (c *Client) Use(hooks ...Hook) { + c.Category.Use(hooks...) + c.Post.Use(hooks...) + c.Profile.Use(hooks...) +} + +// Intercept adds the query interceptors to all the entity clients. +// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. +func (c *Client) Intercept(interceptors ...Interceptor) { + c.Category.Intercept(interceptors...) + c.Post.Intercept(interceptors...) + c.Profile.Intercept(interceptors...) +} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CategoryMutation: + return c.Category.mutate(ctx, m) + case *PostMutation: + return c.Post.mutate(ctx, m) + case *ProfileMutation: + return c.Profile.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + +// CategoryClient is a client for the Category schema. +type CategoryClient struct { + config +} + +// NewCategoryClient returns a client for the Category from the given config. +func NewCategoryClient(c config) *CategoryClient { + return &CategoryClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `category.Hooks(f(g(h())))`. +func (c *CategoryClient) Use(hooks ...Hook) { + c.hooks.Category = append(c.hooks.Category, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `category.Intercept(f(g(h())))`. +func (c *CategoryClient) Intercept(interceptors ...Interceptor) { + c.inters.Category = append(c.inters.Category, interceptors...) +} + +// Create returns a builder for creating a Category entity. +func (c *CategoryClient) Create() *CategoryCreate { + mutation := newCategoryMutation(c.config, OpCreate) + return &CategoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Category entities. +func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreateBulk { + return &CategoryCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CategoryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CategoryCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Category. +func (c *CategoryClient) Update() *CategoryUpdate { + mutation := newCategoryMutation(c.config, OpUpdate) + return &CategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *CategoryClient) UpdateOne(ca *Category) *CategoryUpdateOne { + mutation := newCategoryMutation(c.config, OpUpdateOne, withCategory(ca)) + return &CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *CategoryClient) UpdateOneID(id uuid.UUID) *CategoryUpdateOne { + mutation := newCategoryMutation(c.config, OpUpdateOne, withCategoryID(id)) + return &CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Category. +func (c *CategoryClient) Delete() *CategoryDelete { + mutation := newCategoryMutation(c.config, OpDelete) + return &CategoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *CategoryClient) DeleteOne(ca *Category) *CategoryDeleteOne { + return c.DeleteOneID(ca.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *CategoryClient) DeleteOneID(id uuid.UUID) *CategoryDeleteOne { + builder := c.Delete().Where(category.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &CategoryDeleteOne{builder} +} + +// Query returns a query builder for Category. +func (c *CategoryClient) Query() *CategoryQuery { + return &CategoryQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeCategory}, + inters: c.Interceptors(), + } +} + +// Get returns a Category entity by its id. +func (c *CategoryClient) Get(ctx context.Context, id uuid.UUID) (*Category, error) { + return c.Query().Where(category.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *CategoryClient) GetX(ctx context.Context, id uuid.UUID) *Category { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryPosts queries the posts edge of a Category. +func (c *CategoryClient) QueryPosts(ca *Category) *PostQuery { + query := (&PostClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := ca.ID + step := sqlgraph.NewStep( + sqlgraph.From(category.Table, category.FieldID, id), + sqlgraph.To(post.Table, post.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, category.PostsTable, category.PostsColumn), + ) + fromV = sqlgraph.Neighbors(ca.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *CategoryClient) Hooks() []Hook { + return c.hooks.Category +} + +// Interceptors returns the client interceptors. +func (c *CategoryClient) Interceptors() []Interceptor { + return c.inters.Category +} + +func (c *CategoryClient) mutate(ctx context.Context, m *CategoryMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CategoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CategoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Category mutation op: %q", m.Op()) + } +} + +// PostClient is a client for the Post schema. +type PostClient struct { + config +} + +// NewPostClient returns a client for the Post from the given config. +func NewPostClient(c config) *PostClient { + return &PostClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `post.Hooks(f(g(h())))`. +func (c *PostClient) Use(hooks ...Hook) { + c.hooks.Post = append(c.hooks.Post, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `post.Intercept(f(g(h())))`. +func (c *PostClient) Intercept(interceptors ...Interceptor) { + c.inters.Post = append(c.inters.Post, interceptors...) +} + +// Create returns a builder for creating a Post entity. +func (c *PostClient) Create() *PostCreate { + mutation := newPostMutation(c.config, OpCreate) + return &PostCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Post entities. +func (c *PostClient) CreateBulk(builders ...*PostCreate) *PostCreateBulk { + return &PostCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *PostClient) MapCreateBulk(slice any, setFunc func(*PostCreate, int)) *PostCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &PostCreateBulk{err: fmt.Errorf("calling to PostClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*PostCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &PostCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Post. +func (c *PostClient) Update() *PostUpdate { + mutation := newPostMutation(c.config, OpUpdate) + return &PostUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *PostClient) UpdateOne(po *Post) *PostUpdateOne { + mutation := newPostMutation(c.config, OpUpdateOne, withPost(po)) + return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *PostClient) UpdateOneID(id uuid.UUID) *PostUpdateOne { + mutation := newPostMutation(c.config, OpUpdateOne, withPostID(id)) + return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Post. +func (c *PostClient) Delete() *PostDelete { + mutation := newPostMutation(c.config, OpDelete) + return &PostDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *PostClient) DeleteOne(po *Post) *PostDeleteOne { + return c.DeleteOneID(po.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *PostClient) DeleteOneID(id uuid.UUID) *PostDeleteOne { + builder := c.Delete().Where(post.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &PostDeleteOne{builder} +} + +// Query returns a query builder for Post. +func (c *PostClient) Query() *PostQuery { + return &PostQuery{ + config: c.config, + ctx: &QueryContext{Type: TypePost}, + inters: c.Interceptors(), + } +} + +// Get returns a Post entity by its id. +func (c *PostClient) Get(ctx context.Context, id uuid.UUID) (*Post, error) { + return c.Query().Where(post.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *PostClient) GetX(ctx context.Context, id uuid.UUID) *Post { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryCategory queries the category edge of a Post. +func (c *PostClient) QueryCategory(po *Post) *CategoryQuery { + query := (&CategoryClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := po.ID + step := sqlgraph.NewStep( + sqlgraph.From(post.Table, post.FieldID, id), + sqlgraph.To(category.Table, category.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, post.CategoryTable, post.CategoryColumn), + ) + fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryProfile queries the profile edge of a Post. +func (c *PostClient) QueryProfile(po *Post) *ProfileQuery { + query := (&ProfileClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := po.ID + step := sqlgraph.NewStep( + sqlgraph.From(post.Table, post.FieldID, id), + sqlgraph.To(profile.Table, profile.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, post.ProfileTable, post.ProfileColumn), + ) + fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *PostClient) Hooks() []Hook { + return c.hooks.Post +} + +// Interceptors returns the client interceptors. +func (c *PostClient) Interceptors() []Interceptor { + return c.inters.Post +} + +func (c *PostClient) mutate(ctx context.Context, m *PostMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PostCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PostUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PostDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Post mutation op: %q", m.Op()) + } +} + +// ProfileClient is a client for the Profile schema. +type ProfileClient struct { + config +} + +// NewProfileClient returns a client for the Profile from the given config. +func NewProfileClient(c config) *ProfileClient { + return &ProfileClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `profile.Hooks(f(g(h())))`. +func (c *ProfileClient) Use(hooks ...Hook) { + c.hooks.Profile = append(c.hooks.Profile, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `profile.Intercept(f(g(h())))`. +func (c *ProfileClient) Intercept(interceptors ...Interceptor) { + c.inters.Profile = append(c.inters.Profile, interceptors...) +} + +// Create returns a builder for creating a Profile entity. +func (c *ProfileClient) Create() *ProfileCreate { + mutation := newProfileMutation(c.config, OpCreate) + return &ProfileCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Profile entities. +func (c *ProfileClient) CreateBulk(builders ...*ProfileCreate) *ProfileCreateBulk { + return &ProfileCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ProfileClient) MapCreateBulk(slice any, setFunc func(*ProfileCreate, int)) *ProfileCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ProfileCreateBulk{err: fmt.Errorf("calling to ProfileClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ProfileCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ProfileCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Profile. +func (c *ProfileClient) Update() *ProfileUpdate { + mutation := newProfileMutation(c.config, OpUpdate) + return &ProfileUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ProfileClient) UpdateOne(pr *Profile) *ProfileUpdateOne { + mutation := newProfileMutation(c.config, OpUpdateOne, withProfile(pr)) + return &ProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ProfileClient) UpdateOneID(id uuid.UUID) *ProfileUpdateOne { + mutation := newProfileMutation(c.config, OpUpdateOne, withProfileID(id)) + return &ProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Profile. +func (c *ProfileClient) Delete() *ProfileDelete { + mutation := newProfileMutation(c.config, OpDelete) + return &ProfileDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ProfileClient) DeleteOne(pr *Profile) *ProfileDeleteOne { + return c.DeleteOneID(pr.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ProfileClient) DeleteOneID(id uuid.UUID) *ProfileDeleteOne { + builder := c.Delete().Where(profile.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ProfileDeleteOne{builder} +} + +// Query returns a query builder for Profile. +func (c *ProfileClient) Query() *ProfileQuery { + return &ProfileQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeProfile}, + inters: c.Interceptors(), + } +} + +// Get returns a Profile entity by its id. +func (c *ProfileClient) Get(ctx context.Context, id uuid.UUID) (*Profile, error) { + return c.Query().Where(profile.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ProfileClient) GetX(ctx context.Context, id uuid.UUID) *Profile { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryPosts queries the posts edge of a Profile. +func (c *ProfileClient) QueryPosts(pr *Profile) *PostQuery { + query := (&PostClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := pr.ID + step := sqlgraph.NewStep( + sqlgraph.From(profile.Table, profile.FieldID, id), + sqlgraph.To(post.Table, post.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, profile.PostsTable, profile.PostsColumn), + ) + fromV = sqlgraph.Neighbors(pr.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ProfileClient) Hooks() []Hook { + return c.hooks.Profile +} + +// Interceptors returns the client interceptors. +func (c *ProfileClient) Interceptors() []Interceptor { + return c.inters.Profile +} + +func (c *ProfileClient) mutate(ctx context.Context, m *ProfileMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ProfileCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ProfileUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ProfileDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Profile mutation op: %q", m.Op()) + } +} + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Category, Post, Profile []ent.Hook + } + inters struct { + Category, Post, Profile []ent.Interceptor + } +) diff --git a/ent/ent.go b/ent/ent.go new file mode 100644 index 0000000..40c33a1 --- /dev/null +++ b/ent/ent.go @@ -0,0 +1,612 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "reflect" + "sync" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ent aliases to avoid import conflicts in user's code. +type ( + Op = ent.Op + Hook = ent.Hook + Value = ent.Value + Query = ent.Query + QueryContext = ent.QueryContext + Querier = ent.Querier + QuerierFunc = ent.QuerierFunc + Interceptor = ent.Interceptor + InterceptFunc = ent.InterceptFunc + Traverser = ent.Traverser + TraverseFunc = ent.TraverseFunc + Policy = ent.Policy + Mutator = ent.Mutator + Mutation = ent.Mutation + MutateFunc = ent.MutateFunc +) + +type clientCtxKey struct{} + +// FromContext returns a Client stored inside a context, or nil if there isn't one. +func FromContext(ctx context.Context) *Client { + c, _ := ctx.Value(clientCtxKey{}).(*Client) + return c +} + +// NewContext returns a new context with the given Client attached. +func NewContext(parent context.Context, c *Client) context.Context { + return context.WithValue(parent, clientCtxKey{}, c) +} + +type txCtxKey struct{} + +// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. +func TxFromContext(ctx context.Context) *Tx { + tx, _ := ctx.Value(txCtxKey{}).(*Tx) + return tx +} + +// NewTxContext returns a new context with the given Tx attached. +func NewTxContext(parent context.Context, tx *Tx) context.Context { + return context.WithValue(parent, txCtxKey{}, tx) +} + +// OrderFunc applies an ordering on the sql selector. +// Deprecated: Use Asc/Desc functions or the package builders instead. +type OrderFunc func(*sql.Selector) + +var ( + initCheck sync.Once + columnCheck sql.ColumnCheck +) + +// checkColumn checks if the column exists in the given table. +func checkColumn(table, column string) error { + initCheck.Do(func() { + columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ + category.Table: category.ValidColumn, + post.Table: post.ValidColumn, + profile.Table: profile.ValidColumn, + }) + }) + return columnCheck(table, column) +} + +// Asc applies the given fields in ASC order. +func Asc(fields ...string) func(*sql.Selector) { + return func(s *sql.Selector) { + for _, f := range fields { + if err := checkColumn(s.TableName(), f); err != nil { + s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) + } + s.OrderBy(sql.Asc(s.C(f))) + } + } +} + +// Desc applies the given fields in DESC order. +func Desc(fields ...string) func(*sql.Selector) { + return func(s *sql.Selector) { + for _, f := range fields { + if err := checkColumn(s.TableName(), f); err != nil { + s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) + } + s.OrderBy(sql.Desc(s.C(f))) + } + } +} + +// AggregateFunc applies an aggregation step on the group-by traversal/selector. +type AggregateFunc func(*sql.Selector) string + +// As is a pseudo aggregation function for renaming another other functions with custom names. For example: +// +// GroupBy(field1, field2). +// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). +// Scan(ctx, &v) +func As(fn AggregateFunc, end string) AggregateFunc { + return func(s *sql.Selector) string { + return sql.As(fn(s), end) + } +} + +// Count applies the "count" aggregation function on each group. +func Count() AggregateFunc { + return func(s *sql.Selector) string { + return sql.Count("*") + } +} + +// Max applies the "max" aggregation function on the given field of each group. +func Max(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Max(s.C(field)) + } +} + +// Mean applies the "mean" aggregation function on the given field of each group. +func Mean(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Avg(s.C(field)) + } +} + +// Min applies the "min" aggregation function on the given field of each group. +func Min(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Min(s.C(field)) + } +} + +// Sum applies the "sum" aggregation function on the given field of each group. +func Sum(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Sum(s.C(field)) + } +} + +// ValidationError returns when validating a field or edge fails. +type ValidationError struct { + Name string // Field or edge name. + err error +} + +// Error implements the error interface. +func (e *ValidationError) Error() string { + return e.err.Error() +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ValidationError) Unwrap() error { + return e.err +} + +// IsValidationError returns a boolean indicating whether the error is a validation error. +func IsValidationError(err error) bool { + if err == nil { + return false + } + var e *ValidationError + return errors.As(err, &e) +} + +// NotFoundError returns when trying to fetch a specific entity and it was not found in the database. +type NotFoundError struct { + label string +} + +// Error implements the error interface. +func (e *NotFoundError) Error() string { + return "ent: " + e.label + " not found" +} + +// IsNotFound returns a boolean indicating whether the error is a not found error. +func IsNotFound(err error) bool { + if err == nil { + return false + } + var e *NotFoundError + return errors.As(err, &e) +} + +// MaskNotFound masks not found error. +func MaskNotFound(err error) error { + if IsNotFound(err) { + return nil + } + return err +} + +// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. +type NotSingularError struct { + label string +} + +// Error implements the error interface. +func (e *NotSingularError) Error() string { + return "ent: " + e.label + " not singular" +} + +// IsNotSingular returns a boolean indicating whether the error is a not singular error. +func IsNotSingular(err error) bool { + if err == nil { + return false + } + var e *NotSingularError + return errors.As(err, &e) +} + +// NotLoadedError returns when trying to get a node that was not loaded by the query. +type NotLoadedError struct { + edge string +} + +// Error implements the error interface. +func (e *NotLoadedError) Error() string { + return "ent: " + e.edge + " edge was not loaded" +} + +// IsNotLoaded returns a boolean indicating whether the error is a not loaded error. +func IsNotLoaded(err error) bool { + if err == nil { + return false + } + var e *NotLoadedError + return errors.As(err, &e) +} + +// ConstraintError returns when trying to create/update one or more entities and +// one or more of their constraints failed. For example, violation of edge or +// field uniqueness. +type ConstraintError struct { + msg string + wrap error +} + +// Error implements the error interface. +func (e ConstraintError) Error() string { + return "ent: constraint failed: " + e.msg +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ConstraintError) Unwrap() error { + return e.wrap +} + +// IsConstraintError returns a boolean indicating whether the error is a constraint failure. +func IsConstraintError(err error) bool { + if err == nil { + return false + } + var e *ConstraintError + return errors.As(err, &e) +} + +// selector embedded by the different Select/GroupBy builders. +type selector struct { + label string + flds *[]string + fns []AggregateFunc + scan func(context.Context, any) error +} + +// ScanX is like Scan, but panics if an error occurs. +func (s *selector) ScanX(ctx context.Context, v any) { + if err := s.scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (s *selector) Strings(ctx context.Context) ([]string, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (s *selector) StringsX(ctx context.Context) []string { + v, err := s.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (s *selector) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = s.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (s *selector) StringX(ctx context.Context) string { + v, err := s.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (s *selector) Ints(ctx context.Context) ([]int, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (s *selector) IntsX(ctx context.Context) []int { + v, err := s.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (s *selector) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = s.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (s *selector) IntX(ctx context.Context) int { + v, err := s.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (s *selector) Float64s(ctx context.Context) ([]float64, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (s *selector) Float64sX(ctx context.Context) []float64 { + v, err := s.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (s *selector) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = s.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (s *selector) Float64X(ctx context.Context) float64 { + v, err := s.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (s *selector) Bools(ctx context.Context) ([]bool, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (s *selector) BoolsX(ctx context.Context) []bool { + v, err := s.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (s *selector) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = s.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (s *selector) BoolX(ctx context.Context) bool { + v, err := s.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +// withHooks invokes the builder operation with the given hooks, if any. +func withHooks[V Value, M any, PM interface { + *M + Mutation +}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) { + if len(hooks) == 0 { + return exec(ctx) + } + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutationT, ok := any(m).(PM) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + // Set the mutation to the builder. + *mutation = *mutationT + return exec(ctx) + }) + for i := len(hooks) - 1; i >= 0; i-- { + if hooks[i] == nil { + return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = hooks[i](mut) + } + v, err := mut.Mutate(ctx, mutation) + if err != nil { + return value, err + } + nv, ok := v.(V) + if !ok { + return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation) + } + return nv, nil +} + +// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist. +func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context { + if ent.QueryFromContext(ctx) == nil { + qc.Op = op + ctx = ent.NewQueryContext(ctx, qc) + } + return ctx +} + +func querierAll[V Value, Q interface { + sqlAll(context.Context, ...queryHook) (V, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlAll(ctx) + }) +} + +func querierCount[Q interface { + sqlCount(context.Context) (int, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlCount(ctx) + }) +} + +func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) { + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + rv, err := qr.Query(ctx, q) + if err != nil { + return v, err + } + vt, ok := rv.(V) + if !ok { + return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v) + } + return vt, nil +} + +func scanWithInterceptors[Q1 ent.Query, Q2 interface { + sqlScan(context.Context, Q1, any) error +}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error { + rv := reflect.ValueOf(v) + var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q1) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + if err := selectOrGroup.sqlScan(ctx, query, v); err != nil { + return nil, err + } + if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() { + return rv.Elem().Interface(), nil + } + return v, nil + }) + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + vv, err := qr.Query(ctx, rootQuery) + if err != nil { + return err + } + switch rv2 := reflect.ValueOf(vv); { + case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer: + case rv.Type() == rv2.Type(): + rv.Elem().Set(rv2.Elem()) + case rv.Elem().Type() == rv2.Type(): + rv.Elem().Set(rv2) + } + return nil +} + +// queryHook describes an internal hook for the different sqlAll methods. +type queryHook func(context.Context, *sqlgraph.QuerySpec) diff --git a/ent/entc.go b/ent/entc.go index 7bc33db..00b9ce6 100644 --- a/ent/entc.go +++ b/ent/entc.go @@ -12,9 +12,9 @@ import ( func main() { ex, err := entgql.NewExtension( - entgql.WithConfigPath("gqlgen.yml"), + entgql.WithConfigPath("./gqlgen.yml"), entgql.WithSchemaGenerator(), - entgql.WithSchemaPath("ent.graphql"), + entgql.WithSchemaPath("./ent.graphql"), entgql.WithWhereInputs(true), ) if err != nil { diff --git a/ent/entql.go b/ent/entql.go new file mode 100644 index 0000000..faba40c --- /dev/null +++ b/ent/entql.go @@ -0,0 +1,380 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "code.icod.de/dalu/ka/ent/profile" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entql" + "entgo.io/ent/schema/field" +) + +// schemaGraph holds a representation of ent/schema at runtime. +var schemaGraph = func() *sqlgraph.Schema { + graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 3)} + graph.Nodes[0] = &sqlgraph.Node{ + NodeSpec: sqlgraph.NodeSpec{ + Table: category.Table, + Columns: category.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: category.FieldID, + }, + }, + Type: "Category", + Fields: map[string]*sqlgraph.FieldSpec{ + category.FieldCreatedAt: {Type: field.TypeTime, Column: category.FieldCreatedAt}, + category.FieldUpdatedAt: {Type: field.TypeTime, Column: category.FieldUpdatedAt}, + category.FieldTitle: {Type: field.TypeString, Column: category.FieldTitle}, + category.FieldDescription: {Type: field.TypeString, Column: category.FieldDescription}, + }, + } + graph.Nodes[1] = &sqlgraph.Node{ + NodeSpec: sqlgraph.NodeSpec{ + Table: post.Table, + Columns: post.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: post.FieldID, + }, + }, + Type: "Post", + Fields: map[string]*sqlgraph.FieldSpec{ + post.FieldCreatedAt: {Type: field.TypeTime, Column: post.FieldCreatedAt}, + post.FieldUpdatedAt: {Type: field.TypeTime, Column: post.FieldUpdatedAt}, + post.FieldExpires: {Type: field.TypeBool, Column: post.FieldExpires}, + post.FieldExpireTime: {Type: field.TypeTime, Column: post.FieldExpireTime}, + post.FieldTitle: {Type: field.TypeString, Column: post.FieldTitle}, + post.FieldBody: {Type: field.TypeString, Column: post.FieldBody}, + }, + } + graph.Nodes[2] = &sqlgraph.Node{ + NodeSpec: sqlgraph.NodeSpec{ + Table: profile.Table, + Columns: profile.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: profile.FieldID, + }, + }, + Type: "Profile", + Fields: map[string]*sqlgraph.FieldSpec{ + profile.FieldCreatedAt: {Type: field.TypeTime, Column: profile.FieldCreatedAt}, + profile.FieldUpdatedAt: {Type: field.TypeTime, Column: profile.FieldUpdatedAt}, + profile.FieldName: {Type: field.TypeString, Column: profile.FieldName}, + profile.FieldAddress: {Type: field.TypeString, Column: profile.FieldAddress}, + profile.FieldPhone: {Type: field.TypeString, Column: profile.FieldPhone}, + }, + } + graph.MustAddE( + "posts", + &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: category.PostsTable, + Columns: []string{category.PostsColumn}, + Bidi: false, + }, + "Category", + "Post", + ) + graph.MustAddE( + "category", + &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.CategoryTable, + Columns: []string{post.CategoryColumn}, + Bidi: false, + }, + "Post", + "Category", + ) + graph.MustAddE( + "profile", + &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.ProfileTable, + Columns: []string{post.ProfileColumn}, + Bidi: false, + }, + "Post", + "Profile", + ) + graph.MustAddE( + "posts", + &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: profile.PostsTable, + Columns: []string{profile.PostsColumn}, + Bidi: false, + }, + "Profile", + "Post", + ) + return graph +}() + +// predicateAdder wraps the addPredicate method. +// All update, update-one and query builders implement this interface. +type predicateAdder interface { + addPredicate(func(s *sql.Selector)) +} + +// addPredicate implements the predicateAdder interface. +func (cq *CategoryQuery) addPredicate(pred func(s *sql.Selector)) { + cq.predicates = append(cq.predicates, pred) +} + +// Filter returns a Filter implementation to apply filters on the CategoryQuery builder. +func (cq *CategoryQuery) Filter() *CategoryFilter { + return &CategoryFilter{config: cq.config, predicateAdder: cq} +} + +// addPredicate implements the predicateAdder interface. +func (m *CategoryMutation) addPredicate(pred func(s *sql.Selector)) { + m.predicates = append(m.predicates, pred) +} + +// Filter returns an entql.Where implementation to apply filters on the CategoryMutation builder. +func (m *CategoryMutation) Filter() *CategoryFilter { + return &CategoryFilter{config: m.config, predicateAdder: m} +} + +// CategoryFilter provides a generic filtering capability at runtime for CategoryQuery. +type CategoryFilter struct { + predicateAdder + config +} + +// Where applies the entql predicate on the query filter. +func (f *CategoryFilter) Where(p entql.P) { + f.addPredicate(func(s *sql.Selector) { + if err := schemaGraph.EvalP(schemaGraph.Nodes[0].Type, p, s); err != nil { + s.AddError(err) + } + }) +} + +// WhereID applies the entql [16]byte predicate on the id field. +func (f *CategoryFilter) WhereID(p entql.ValueP) { + f.Where(p.Field(category.FieldID)) +} + +// WhereCreatedAt applies the entql time.Time predicate on the created_at field. +func (f *CategoryFilter) WhereCreatedAt(p entql.TimeP) { + f.Where(p.Field(category.FieldCreatedAt)) +} + +// WhereUpdatedAt applies the entql time.Time predicate on the updated_at field. +func (f *CategoryFilter) WhereUpdatedAt(p entql.TimeP) { + f.Where(p.Field(category.FieldUpdatedAt)) +} + +// WhereTitle applies the entql string predicate on the title field. +func (f *CategoryFilter) WhereTitle(p entql.StringP) { + f.Where(p.Field(category.FieldTitle)) +} + +// WhereDescription applies the entql string predicate on the description field. +func (f *CategoryFilter) WhereDescription(p entql.StringP) { + f.Where(p.Field(category.FieldDescription)) +} + +// WhereHasPosts applies a predicate to check if query has an edge posts. +func (f *CategoryFilter) WhereHasPosts() { + f.Where(entql.HasEdge("posts")) +} + +// WhereHasPostsWith applies a predicate to check if query has an edge posts with a given conditions (other predicates). +func (f *CategoryFilter) WhereHasPostsWith(preds ...predicate.Post) { + f.Where(entql.HasEdgeWith("posts", sqlgraph.WrapFunc(func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }))) +} + +// addPredicate implements the predicateAdder interface. +func (pq *PostQuery) addPredicate(pred func(s *sql.Selector)) { + pq.predicates = append(pq.predicates, pred) +} + +// Filter returns a Filter implementation to apply filters on the PostQuery builder. +func (pq *PostQuery) Filter() *PostFilter { + return &PostFilter{config: pq.config, predicateAdder: pq} +} + +// addPredicate implements the predicateAdder interface. +func (m *PostMutation) addPredicate(pred func(s *sql.Selector)) { + m.predicates = append(m.predicates, pred) +} + +// Filter returns an entql.Where implementation to apply filters on the PostMutation builder. +func (m *PostMutation) Filter() *PostFilter { + return &PostFilter{config: m.config, predicateAdder: m} +} + +// PostFilter provides a generic filtering capability at runtime for PostQuery. +type PostFilter struct { + predicateAdder + config +} + +// Where applies the entql predicate on the query filter. +func (f *PostFilter) Where(p entql.P) { + f.addPredicate(func(s *sql.Selector) { + if err := schemaGraph.EvalP(schemaGraph.Nodes[1].Type, p, s); err != nil { + s.AddError(err) + } + }) +} + +// WhereID applies the entql [16]byte predicate on the id field. +func (f *PostFilter) WhereID(p entql.ValueP) { + f.Where(p.Field(post.FieldID)) +} + +// WhereCreatedAt applies the entql time.Time predicate on the created_at field. +func (f *PostFilter) WhereCreatedAt(p entql.TimeP) { + f.Where(p.Field(post.FieldCreatedAt)) +} + +// WhereUpdatedAt applies the entql time.Time predicate on the updated_at field. +func (f *PostFilter) WhereUpdatedAt(p entql.TimeP) { + f.Where(p.Field(post.FieldUpdatedAt)) +} + +// WhereExpires applies the entql bool predicate on the expires field. +func (f *PostFilter) WhereExpires(p entql.BoolP) { + f.Where(p.Field(post.FieldExpires)) +} + +// WhereExpireTime applies the entql time.Time predicate on the expire_time field. +func (f *PostFilter) WhereExpireTime(p entql.TimeP) { + f.Where(p.Field(post.FieldExpireTime)) +} + +// WhereTitle applies the entql string predicate on the title field. +func (f *PostFilter) WhereTitle(p entql.StringP) { + f.Where(p.Field(post.FieldTitle)) +} + +// WhereBody applies the entql string predicate on the body field. +func (f *PostFilter) WhereBody(p entql.StringP) { + f.Where(p.Field(post.FieldBody)) +} + +// WhereHasCategory applies a predicate to check if query has an edge category. +func (f *PostFilter) WhereHasCategory() { + f.Where(entql.HasEdge("category")) +} + +// WhereHasCategoryWith applies a predicate to check if query has an edge category with a given conditions (other predicates). +func (f *PostFilter) WhereHasCategoryWith(preds ...predicate.Category) { + f.Where(entql.HasEdgeWith("category", sqlgraph.WrapFunc(func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }))) +} + +// WhereHasProfile applies a predicate to check if query has an edge profile. +func (f *PostFilter) WhereHasProfile() { + f.Where(entql.HasEdge("profile")) +} + +// WhereHasProfileWith applies a predicate to check if query has an edge profile with a given conditions (other predicates). +func (f *PostFilter) WhereHasProfileWith(preds ...predicate.Profile) { + f.Where(entql.HasEdgeWith("profile", sqlgraph.WrapFunc(func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }))) +} + +// addPredicate implements the predicateAdder interface. +func (pq *ProfileQuery) addPredicate(pred func(s *sql.Selector)) { + pq.predicates = append(pq.predicates, pred) +} + +// Filter returns a Filter implementation to apply filters on the ProfileQuery builder. +func (pq *ProfileQuery) Filter() *ProfileFilter { + return &ProfileFilter{config: pq.config, predicateAdder: pq} +} + +// addPredicate implements the predicateAdder interface. +func (m *ProfileMutation) addPredicate(pred func(s *sql.Selector)) { + m.predicates = append(m.predicates, pred) +} + +// Filter returns an entql.Where implementation to apply filters on the ProfileMutation builder. +func (m *ProfileMutation) Filter() *ProfileFilter { + return &ProfileFilter{config: m.config, predicateAdder: m} +} + +// ProfileFilter provides a generic filtering capability at runtime for ProfileQuery. +type ProfileFilter struct { + predicateAdder + config +} + +// Where applies the entql predicate on the query filter. +func (f *ProfileFilter) Where(p entql.P) { + f.addPredicate(func(s *sql.Selector) { + if err := schemaGraph.EvalP(schemaGraph.Nodes[2].Type, p, s); err != nil { + s.AddError(err) + } + }) +} + +// WhereID applies the entql [16]byte predicate on the id field. +func (f *ProfileFilter) WhereID(p entql.ValueP) { + f.Where(p.Field(profile.FieldID)) +} + +// WhereCreatedAt applies the entql time.Time predicate on the created_at field. +func (f *ProfileFilter) WhereCreatedAt(p entql.TimeP) { + f.Where(p.Field(profile.FieldCreatedAt)) +} + +// WhereUpdatedAt applies the entql time.Time predicate on the updated_at field. +func (f *ProfileFilter) WhereUpdatedAt(p entql.TimeP) { + f.Where(p.Field(profile.FieldUpdatedAt)) +} + +// WhereName applies the entql string predicate on the name field. +func (f *ProfileFilter) WhereName(p entql.StringP) { + f.Where(p.Field(profile.FieldName)) +} + +// WhereAddress applies the entql string predicate on the address field. +func (f *ProfileFilter) WhereAddress(p entql.StringP) { + f.Where(p.Field(profile.FieldAddress)) +} + +// WherePhone applies the entql string predicate on the phone field. +func (f *ProfileFilter) WherePhone(p entql.StringP) { + f.Where(p.Field(profile.FieldPhone)) +} + +// WhereHasPosts applies a predicate to check if query has an edge posts. +func (f *ProfileFilter) WhereHasPosts() { + f.Where(entql.HasEdge("posts")) +} + +// WhereHasPostsWith applies a predicate to check if query has an edge posts with a given conditions (other predicates). +func (f *ProfileFilter) WhereHasPostsWith(preds ...predicate.Post) { + f.Where(entql.HasEdgeWith("posts", sqlgraph.WrapFunc(func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }))) +} diff --git a/ent/enttest/enttest.go b/ent/enttest/enttest.go new file mode 100644 index 0000000..fc00fa0 --- /dev/null +++ b/ent/enttest/enttest.go @@ -0,0 +1,84 @@ +// Code generated by ent, DO NOT EDIT. + +package enttest + +import ( + "context" + + "code.icod.de/dalu/ka/ent" + // required by schema hooks. + _ "code.icod.de/dalu/ka/ent/runtime" + + "code.icod.de/dalu/ka/ent/migrate" + "entgo.io/ent/dialect/sql/schema" +) + +type ( + // TestingT is the interface that is shared between + // testing.T and testing.B and used by enttest. + TestingT interface { + FailNow() + Error(...any) + } + + // Option configures client creation. + Option func(*options) + + options struct { + opts []ent.Option + migrateOpts []schema.MigrateOption + } +) + +// WithOptions forwards options to client creation. +func WithOptions(opts ...ent.Option) Option { + return func(o *options) { + o.opts = append(o.opts, opts...) + } +} + +// WithMigrateOptions forwards options to auto migration. +func WithMigrateOptions(opts ...schema.MigrateOption) Option { + return func(o *options) { + o.migrateOpts = append(o.migrateOpts, opts...) + } +} + +func newOptions(opts []Option) *options { + o := &options{} + for _, opt := range opts { + opt(o) + } + return o +} + +// Open calls ent.Open and auto-run migration. +func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { + o := newOptions(opts) + c, err := ent.Open(driverName, dataSourceName, o.opts...) + if err != nil { + t.Error(err) + t.FailNow() + } + migrateSchema(t, c, o) + return c +} + +// NewClient calls ent.NewClient and auto-run migration. +func NewClient(t TestingT, opts ...Option) *ent.Client { + o := newOptions(opts) + c := ent.NewClient(o.opts...) + migrateSchema(t, c, o) + return c +} +func migrateSchema(t TestingT, c *ent.Client, o *options) { + tables, err := schema.CopyTables(migrate.Tables) + if err != nil { + t.Error(err) + t.FailNow() + } + if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } +} diff --git a/ent/gql_collection.go b/ent/gql_collection.go new file mode 100644 index 0000000..123e392 --- /dev/null +++ b/ent/gql_collection.go @@ -0,0 +1,611 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/contrib/entgql" + "entgo.io/ent/dialect/sql" + "github.com/99designs/gqlgen/graphql" + "github.com/google/uuid" +) + +// CollectFields tells the query-builder to eagerly load connected nodes by resolver context. +func (c *CategoryQuery) CollectFields(ctx context.Context, satisfies ...string) (*CategoryQuery, error) { + fc := graphql.GetFieldContext(ctx) + if fc == nil { + return c, nil + } + if err := c.collectField(ctx, false, graphql.GetOperationContext(ctx), fc.Field, nil, satisfies...); err != nil { + return nil, err + } + return c, nil +} + +func (c *CategoryQuery) collectField(ctx context.Context, oneNode bool, opCtx *graphql.OperationContext, collected graphql.CollectedField, path []string, satisfies ...string) error { + path = append([]string(nil), path...) + var ( + unknownSeen bool + fieldSeen = make(map[string]struct{}, len(category.Columns)) + selectedFields = []string{category.FieldID} + ) + for _, field := range graphql.CollectFields(opCtx, collected.Selections, satisfies) { + switch field.Name { + + case "posts": + var ( + alias = field.Alias + path = append(path, alias) + query = (&PostClient{config: c.config}).Query() + ) + args := newPostPaginateArgs(fieldArgs(ctx, new(PostWhereInput), path...)) + if err := validateFirstLast(args.first, args.last); err != nil { + return fmt.Errorf("validate first and last in path %q: %w", path, err) + } + pager, err := newPostPager(args.opts, args.last != nil) + if err != nil { + return fmt.Errorf("create new pager in path %q: %w", path, err) + } + if query, err = pager.applyFilter(query); err != nil { + return err + } + ignoredEdges := !hasCollectedField(ctx, append(path, edgesField)...) + if hasCollectedField(ctx, append(path, totalCountField)...) || hasCollectedField(ctx, append(path, pageInfoField)...) { + hasPagination := args.after != nil || args.first != nil || args.before != nil || args.last != nil + if hasPagination || ignoredEdges { + query := query.Clone() + c.loadTotal = append(c.loadTotal, func(ctx context.Context, nodes []*Category) error { + ids := make([]driver.Value, len(nodes)) + for i := range nodes { + ids[i] = nodes[i].ID + } + var v []struct { + NodeID uuid.UUID `sql:"category_posts"` + Count int `sql:"count"` + } + query.Where(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(category.PostsColumn), ids...)) + }) + if err := query.GroupBy(category.PostsColumn).Aggregate(Count()).Scan(ctx, &v); err != nil { + return err + } + m := make(map[uuid.UUID]int, len(v)) + for i := range v { + m[v[i].NodeID] = v[i].Count + } + for i := range nodes { + n := m[nodes[i].ID] + if nodes[i].Edges.totalCount[0] == nil { + nodes[i].Edges.totalCount[0] = make(map[string]int) + } + nodes[i].Edges.totalCount[0][alias] = n + } + return nil + }) + } else { + c.loadTotal = append(c.loadTotal, func(_ context.Context, nodes []*Category) error { + for i := range nodes { + n := len(nodes[i].Edges.Posts) + if nodes[i].Edges.totalCount[0] == nil { + nodes[i].Edges.totalCount[0] = make(map[string]int) + } + nodes[i].Edges.totalCount[0][alias] = n + } + return nil + }) + } + } + if ignoredEdges || (args.first != nil && *args.first == 0) || (args.last != nil && *args.last == 0) { + continue + } + if query, err = pager.applyCursors(query, args.after, args.before); err != nil { + return err + } + path = append(path, edgesField, nodeField) + if field := collectedField(ctx, path...); field != nil { + if err := query.collectField(ctx, false, opCtx, *field, path, mayAddCondition(satisfies, postImplementors)...); err != nil { + return err + } + } + if limit := paginateLimit(args.first, args.last); limit > 0 { + if oneNode { + pager.applyOrder(query.Limit(limit)) + } else { + modify := entgql.LimitPerRow(category.PostsColumn, limit, pager.orderExpr(query)) + query.modifiers = append(query.modifiers, modify) + } + } else { + query = pager.applyOrder(query) + } + c.WithNamedPosts(alias, func(wq *PostQuery) { + *wq = *query + }) + case "createdAt": + if _, ok := fieldSeen[category.FieldCreatedAt]; !ok { + selectedFields = append(selectedFields, category.FieldCreatedAt) + fieldSeen[category.FieldCreatedAt] = struct{}{} + } + case "updatedAt": + if _, ok := fieldSeen[category.FieldUpdatedAt]; !ok { + selectedFields = append(selectedFields, category.FieldUpdatedAt) + fieldSeen[category.FieldUpdatedAt] = struct{}{} + } + case "title": + if _, ok := fieldSeen[category.FieldTitle]; !ok { + selectedFields = append(selectedFields, category.FieldTitle) + fieldSeen[category.FieldTitle] = struct{}{} + } + case "description": + if _, ok := fieldSeen[category.FieldDescription]; !ok { + selectedFields = append(selectedFields, category.FieldDescription) + fieldSeen[category.FieldDescription] = struct{}{} + } + case "id": + case "__typename": + default: + unknownSeen = true + } + } + if !unknownSeen { + c.Select(selectedFields...) + } + return nil +} + +type categoryPaginateArgs struct { + first, last *int + after, before *Cursor + opts []CategoryPaginateOption +} + +func newCategoryPaginateArgs(rv map[string]any) *categoryPaginateArgs { + args := &categoryPaginateArgs{} + if rv == nil { + return args + } + if v := rv[firstField]; v != nil { + args.first = v.(*int) + } + if v := rv[lastField]; v != nil { + args.last = v.(*int) + } + if v := rv[afterField]; v != nil { + args.after = v.(*Cursor) + } + if v := rv[beforeField]; v != nil { + args.before = v.(*Cursor) + } + if v, ok := rv[orderByField]; ok { + switch v := v.(type) { + case map[string]any: + var ( + err1, err2 error + order = &CategoryOrder{Field: &CategoryOrderField{}, Direction: entgql.OrderDirectionAsc} + ) + if d, ok := v[directionField]; ok { + err1 = order.Direction.UnmarshalGQL(d) + } + if f, ok := v[fieldField]; ok { + err2 = order.Field.UnmarshalGQL(f) + } + if err1 == nil && err2 == nil { + args.opts = append(args.opts, WithCategoryOrder(order)) + } + case *CategoryOrder: + if v != nil { + args.opts = append(args.opts, WithCategoryOrder(v)) + } + } + } + if v, ok := rv[whereField].(*CategoryWhereInput); ok { + args.opts = append(args.opts, WithCategoryFilter(v.Filter)) + } + return args +} + +// CollectFields tells the query-builder to eagerly load connected nodes by resolver context. +func (po *PostQuery) CollectFields(ctx context.Context, satisfies ...string) (*PostQuery, error) { + fc := graphql.GetFieldContext(ctx) + if fc == nil { + return po, nil + } + if err := po.collectField(ctx, false, graphql.GetOperationContext(ctx), fc.Field, nil, satisfies...); err != nil { + return nil, err + } + return po, nil +} + +func (po *PostQuery) collectField(ctx context.Context, oneNode bool, opCtx *graphql.OperationContext, collected graphql.CollectedField, path []string, satisfies ...string) error { + path = append([]string(nil), path...) + var ( + unknownSeen bool + fieldSeen = make(map[string]struct{}, len(post.Columns)) + selectedFields = []string{post.FieldID} + ) + for _, field := range graphql.CollectFields(opCtx, collected.Selections, satisfies) { + switch field.Name { + + case "category": + var ( + alias = field.Alias + path = append(path, alias) + query = (&CategoryClient{config: po.config}).Query() + ) + if err := query.collectField(ctx, oneNode, opCtx, field, path, mayAddCondition(satisfies, categoryImplementors)...); err != nil { + return err + } + po.withCategory = query + + case "profile": + var ( + alias = field.Alias + path = append(path, alias) + query = (&ProfileClient{config: po.config}).Query() + ) + if err := query.collectField(ctx, oneNode, opCtx, field, path, mayAddCondition(satisfies, profileImplementors)...); err != nil { + return err + } + po.withProfile = query + case "createdAt": + if _, ok := fieldSeen[post.FieldCreatedAt]; !ok { + selectedFields = append(selectedFields, post.FieldCreatedAt) + fieldSeen[post.FieldCreatedAt] = struct{}{} + } + case "updatedAt": + if _, ok := fieldSeen[post.FieldUpdatedAt]; !ok { + selectedFields = append(selectedFields, post.FieldUpdatedAt) + fieldSeen[post.FieldUpdatedAt] = struct{}{} + } + case "expires": + if _, ok := fieldSeen[post.FieldExpires]; !ok { + selectedFields = append(selectedFields, post.FieldExpires) + fieldSeen[post.FieldExpires] = struct{}{} + } + case "expireTime": + if _, ok := fieldSeen[post.FieldExpireTime]; !ok { + selectedFields = append(selectedFields, post.FieldExpireTime) + fieldSeen[post.FieldExpireTime] = struct{}{} + } + case "title": + if _, ok := fieldSeen[post.FieldTitle]; !ok { + selectedFields = append(selectedFields, post.FieldTitle) + fieldSeen[post.FieldTitle] = struct{}{} + } + case "body": + if _, ok := fieldSeen[post.FieldBody]; !ok { + selectedFields = append(selectedFields, post.FieldBody) + fieldSeen[post.FieldBody] = struct{}{} + } + case "id": + case "__typename": + default: + unknownSeen = true + } + } + if !unknownSeen { + po.Select(selectedFields...) + } + return nil +} + +type postPaginateArgs struct { + first, last *int + after, before *Cursor + opts []PostPaginateOption +} + +func newPostPaginateArgs(rv map[string]any) *postPaginateArgs { + args := &postPaginateArgs{} + if rv == nil { + return args + } + if v := rv[firstField]; v != nil { + args.first = v.(*int) + } + if v := rv[lastField]; v != nil { + args.last = v.(*int) + } + if v := rv[afterField]; v != nil { + args.after = v.(*Cursor) + } + if v := rv[beforeField]; v != nil { + args.before = v.(*Cursor) + } + if v, ok := rv[orderByField]; ok { + switch v := v.(type) { + case map[string]any: + var ( + err1, err2 error + order = &PostOrder{Field: &PostOrderField{}, Direction: entgql.OrderDirectionAsc} + ) + if d, ok := v[directionField]; ok { + err1 = order.Direction.UnmarshalGQL(d) + } + if f, ok := v[fieldField]; ok { + err2 = order.Field.UnmarshalGQL(f) + } + if err1 == nil && err2 == nil { + args.opts = append(args.opts, WithPostOrder(order)) + } + case *PostOrder: + if v != nil { + args.opts = append(args.opts, WithPostOrder(v)) + } + } + } + if v, ok := rv[whereField].(*PostWhereInput); ok { + args.opts = append(args.opts, WithPostFilter(v.Filter)) + } + return args +} + +// CollectFields tells the query-builder to eagerly load connected nodes by resolver context. +func (pr *ProfileQuery) CollectFields(ctx context.Context, satisfies ...string) (*ProfileQuery, error) { + fc := graphql.GetFieldContext(ctx) + if fc == nil { + return pr, nil + } + if err := pr.collectField(ctx, false, graphql.GetOperationContext(ctx), fc.Field, nil, satisfies...); err != nil { + return nil, err + } + return pr, nil +} + +func (pr *ProfileQuery) collectField(ctx context.Context, oneNode bool, opCtx *graphql.OperationContext, collected graphql.CollectedField, path []string, satisfies ...string) error { + path = append([]string(nil), path...) + var ( + unknownSeen bool + fieldSeen = make(map[string]struct{}, len(profile.Columns)) + selectedFields = []string{profile.FieldID} + ) + for _, field := range graphql.CollectFields(opCtx, collected.Selections, satisfies) { + switch field.Name { + + case "posts": + var ( + alias = field.Alias + path = append(path, alias) + query = (&PostClient{config: pr.config}).Query() + ) + args := newPostPaginateArgs(fieldArgs(ctx, new(PostWhereInput), path...)) + if err := validateFirstLast(args.first, args.last); err != nil { + return fmt.Errorf("validate first and last in path %q: %w", path, err) + } + pager, err := newPostPager(args.opts, args.last != nil) + if err != nil { + return fmt.Errorf("create new pager in path %q: %w", path, err) + } + if query, err = pager.applyFilter(query); err != nil { + return err + } + ignoredEdges := !hasCollectedField(ctx, append(path, edgesField)...) + if hasCollectedField(ctx, append(path, totalCountField)...) || hasCollectedField(ctx, append(path, pageInfoField)...) { + hasPagination := args.after != nil || args.first != nil || args.before != nil || args.last != nil + if hasPagination || ignoredEdges { + query := query.Clone() + pr.loadTotal = append(pr.loadTotal, func(ctx context.Context, nodes []*Profile) error { + ids := make([]driver.Value, len(nodes)) + for i := range nodes { + ids[i] = nodes[i].ID + } + var v []struct { + NodeID uuid.UUID `sql:"profile_posts"` + Count int `sql:"count"` + } + query.Where(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(profile.PostsColumn), ids...)) + }) + if err := query.GroupBy(profile.PostsColumn).Aggregate(Count()).Scan(ctx, &v); err != nil { + return err + } + m := make(map[uuid.UUID]int, len(v)) + for i := range v { + m[v[i].NodeID] = v[i].Count + } + for i := range nodes { + n := m[nodes[i].ID] + if nodes[i].Edges.totalCount[0] == nil { + nodes[i].Edges.totalCount[0] = make(map[string]int) + } + nodes[i].Edges.totalCount[0][alias] = n + } + return nil + }) + } else { + pr.loadTotal = append(pr.loadTotal, func(_ context.Context, nodes []*Profile) error { + for i := range nodes { + n := len(nodes[i].Edges.Posts) + if nodes[i].Edges.totalCount[0] == nil { + nodes[i].Edges.totalCount[0] = make(map[string]int) + } + nodes[i].Edges.totalCount[0][alias] = n + } + return nil + }) + } + } + if ignoredEdges || (args.first != nil && *args.first == 0) || (args.last != nil && *args.last == 0) { + continue + } + if query, err = pager.applyCursors(query, args.after, args.before); err != nil { + return err + } + path = append(path, edgesField, nodeField) + if field := collectedField(ctx, path...); field != nil { + if err := query.collectField(ctx, false, opCtx, *field, path, mayAddCondition(satisfies, postImplementors)...); err != nil { + return err + } + } + if limit := paginateLimit(args.first, args.last); limit > 0 { + if oneNode { + pager.applyOrder(query.Limit(limit)) + } else { + modify := entgql.LimitPerRow(profile.PostsColumn, limit, pager.orderExpr(query)) + query.modifiers = append(query.modifiers, modify) + } + } else { + query = pager.applyOrder(query) + } + pr.WithNamedPosts(alias, func(wq *PostQuery) { + *wq = *query + }) + case "createdAt": + if _, ok := fieldSeen[profile.FieldCreatedAt]; !ok { + selectedFields = append(selectedFields, profile.FieldCreatedAt) + fieldSeen[profile.FieldCreatedAt] = struct{}{} + } + case "updatedAt": + if _, ok := fieldSeen[profile.FieldUpdatedAt]; !ok { + selectedFields = append(selectedFields, profile.FieldUpdatedAt) + fieldSeen[profile.FieldUpdatedAt] = struct{}{} + } + case "name": + if _, ok := fieldSeen[profile.FieldName]; !ok { + selectedFields = append(selectedFields, profile.FieldName) + fieldSeen[profile.FieldName] = struct{}{} + } + case "address": + if _, ok := fieldSeen[profile.FieldAddress]; !ok { + selectedFields = append(selectedFields, profile.FieldAddress) + fieldSeen[profile.FieldAddress] = struct{}{} + } + case "phone": + if _, ok := fieldSeen[profile.FieldPhone]; !ok { + selectedFields = append(selectedFields, profile.FieldPhone) + fieldSeen[profile.FieldPhone] = struct{}{} + } + case "id": + case "__typename": + default: + unknownSeen = true + } + } + if !unknownSeen { + pr.Select(selectedFields...) + } + return nil +} + +type profilePaginateArgs struct { + first, last *int + after, before *Cursor + opts []ProfilePaginateOption +} + +func newProfilePaginateArgs(rv map[string]any) *profilePaginateArgs { + args := &profilePaginateArgs{} + if rv == nil { + return args + } + if v := rv[firstField]; v != nil { + args.first = v.(*int) + } + if v := rv[lastField]; v != nil { + args.last = v.(*int) + } + if v := rv[afterField]; v != nil { + args.after = v.(*Cursor) + } + if v := rv[beforeField]; v != nil { + args.before = v.(*Cursor) + } + if v, ok := rv[orderByField]; ok { + switch v := v.(type) { + case map[string]any: + var ( + err1, err2 error + order = &ProfileOrder{Field: &ProfileOrderField{}, Direction: entgql.OrderDirectionAsc} + ) + if d, ok := v[directionField]; ok { + err1 = order.Direction.UnmarshalGQL(d) + } + if f, ok := v[fieldField]; ok { + err2 = order.Field.UnmarshalGQL(f) + } + if err1 == nil && err2 == nil { + args.opts = append(args.opts, WithProfileOrder(order)) + } + case *ProfileOrder: + if v != nil { + args.opts = append(args.opts, WithProfileOrder(v)) + } + } + } + if v, ok := rv[whereField].(*ProfileWhereInput); ok { + args.opts = append(args.opts, WithProfileFilter(v.Filter)) + } + return args +} + +const ( + afterField = "after" + firstField = "first" + beforeField = "before" + lastField = "last" + orderByField = "orderBy" + directionField = "direction" + fieldField = "field" + whereField = "where" +) + +func fieldArgs(ctx context.Context, whereInput any, path ...string) map[string]any { + field := collectedField(ctx, path...) + if field == nil || field.Arguments == nil { + return nil + } + oc := graphql.GetOperationContext(ctx) + args := field.ArgumentMap(oc.Variables) + return unmarshalArgs(ctx, whereInput, args) +} + +// unmarshalArgs allows extracting the field arguments from their raw representation. +func unmarshalArgs(ctx context.Context, whereInput any, args map[string]any) map[string]any { + for _, k := range []string{firstField, lastField} { + v, ok := args[k] + if !ok { + continue + } + i, err := graphql.UnmarshalInt(v) + if err == nil { + args[k] = &i + } + } + for _, k := range []string{beforeField, afterField} { + v, ok := args[k] + if !ok { + continue + } + c := &Cursor{} + if c.UnmarshalGQL(v) == nil { + args[k] = c + } + } + if v, ok := args[whereField]; ok && whereInput != nil { + if err := graphql.UnmarshalInputFromContext(ctx, v, whereInput); err == nil { + args[whereField] = whereInput + } + } + + return args +} + +// mayAddCondition appends another type condition to the satisfies list +// if it does not exist in the list. +func mayAddCondition(satisfies []string, typeCond []string) []string { +Cond: + for _, c := range typeCond { + for _, s := range satisfies { + if c == s { + continue Cond + } + } + satisfies = append(satisfies, c) + } + return satisfies +} diff --git a/ent/gql_edge.go b/ent/gql_edge.go new file mode 100644 index 0000000..abf7238 --- /dev/null +++ b/ent/gql_edge.go @@ -0,0 +1,67 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "github.com/99designs/gqlgen/graphql" +) + +func (c *Category) Posts( + ctx context.Context, after *Cursor, first *int, before *Cursor, last *int, orderBy *PostOrder, where *PostWhereInput, +) (*PostConnection, error) { + opts := []PostPaginateOption{ + WithPostOrder(orderBy), + WithPostFilter(where.Filter), + } + alias := graphql.GetFieldContext(ctx).Field.Alias + totalCount, hasTotalCount := c.Edges.totalCount[0][alias] + if nodes, err := c.NamedPosts(alias); err == nil || hasTotalCount { + pager, err := newPostPager(opts, last != nil) + if err != nil { + return nil, err + } + conn := &PostConnection{Edges: []*PostEdge{}, TotalCount: totalCount} + conn.build(nodes, pager, after, first, before, last) + return conn, nil + } + return c.QueryPosts().Paginate(ctx, after, first, before, last, opts...) +} + +func (po *Post) Category(ctx context.Context) (*Category, error) { + result, err := po.Edges.CategoryOrErr() + if IsNotLoaded(err) { + result, err = po.QueryCategory().Only(ctx) + } + return result, MaskNotFound(err) +} + +func (po *Post) Profile(ctx context.Context) (*Profile, error) { + result, err := po.Edges.ProfileOrErr() + if IsNotLoaded(err) { + result, err = po.QueryProfile().Only(ctx) + } + return result, MaskNotFound(err) +} + +func (pr *Profile) Posts( + ctx context.Context, after *Cursor, first *int, before *Cursor, last *int, orderBy *PostOrder, where *PostWhereInput, +) (*PostConnection, error) { + opts := []PostPaginateOption{ + WithPostOrder(orderBy), + WithPostFilter(where.Filter), + } + alias := graphql.GetFieldContext(ctx).Field.Alias + totalCount, hasTotalCount := pr.Edges.totalCount[0][alias] + if nodes, err := pr.NamedPosts(alias); err == nil || hasTotalCount { + pager, err := newPostPager(opts, last != nil) + if err != nil { + return nil, err + } + conn := &PostConnection{Edges: []*PostEdge{}, TotalCount: totalCount} + conn.build(nodes, pager, after, first, before, last) + return conn, nil + } + return pr.QueryPosts().Paginate(ctx, after, first, before, last, opts...) +} diff --git a/ent/gql_mutation_input.go b/ent/gql_mutation_input.go new file mode 100644 index 0000000..5f2ea0a --- /dev/null +++ b/ent/gql_mutation_input.go @@ -0,0 +1,301 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "time" + + "github.com/google/uuid" +) + +// CreateCategoryInput represents a mutation input for creating categories. +type CreateCategoryInput struct { + CreatedAt *time.Time + UpdatedAt *time.Time + Title string + Description *string + PostIDs []uuid.UUID +} + +// Mutate applies the CreateCategoryInput on the CategoryMutation builder. +func (i *CreateCategoryInput) Mutate(m *CategoryMutation) { + if v := i.CreatedAt; v != nil { + m.SetCreatedAt(*v) + } + if v := i.UpdatedAt; v != nil { + m.SetUpdatedAt(*v) + } + m.SetTitle(i.Title) + if v := i.Description; v != nil { + m.SetDescription(*v) + } + if v := i.PostIDs; len(v) > 0 { + m.AddPostIDs(v...) + } +} + +// SetInput applies the change-set in the CreateCategoryInput on the CategoryCreate builder. +func (c *CategoryCreate) SetInput(i CreateCategoryInput) *CategoryCreate { + i.Mutate(c.Mutation()) + return c +} + +// UpdateCategoryInput represents a mutation input for updating categories. +type UpdateCategoryInput struct { + ClearUpdatedAt bool + UpdatedAt *time.Time + Title *string + ClearDescription bool + Description *string + ClearPosts bool + AddPostIDs []uuid.UUID + RemovePostIDs []uuid.UUID +} + +// Mutate applies the UpdateCategoryInput on the CategoryMutation builder. +func (i *UpdateCategoryInput) Mutate(m *CategoryMutation) { + if i.ClearUpdatedAt { + m.ClearUpdatedAt() + } + if v := i.UpdatedAt; v != nil { + m.SetUpdatedAt(*v) + } + if v := i.Title; v != nil { + m.SetTitle(*v) + } + if i.ClearDescription { + m.ClearDescription() + } + if v := i.Description; v != nil { + m.SetDescription(*v) + } + if i.ClearPosts { + m.ClearPosts() + } + if v := i.AddPostIDs; len(v) > 0 { + m.AddPostIDs(v...) + } + if v := i.RemovePostIDs; len(v) > 0 { + m.RemovePostIDs(v...) + } +} + +// SetInput applies the change-set in the UpdateCategoryInput on the CategoryUpdate builder. +func (c *CategoryUpdate) SetInput(i UpdateCategoryInput) *CategoryUpdate { + i.Mutate(c.Mutation()) + return c +} + +// SetInput applies the change-set in the UpdateCategoryInput on the CategoryUpdateOne builder. +func (c *CategoryUpdateOne) SetInput(i UpdateCategoryInput) *CategoryUpdateOne { + i.Mutate(c.Mutation()) + return c +} + +// CreatePostInput represents a mutation input for creating posts. +type CreatePostInput struct { + CreatedAt *time.Time + UpdatedAt *time.Time + Expires *bool + ExpireTime *time.Time + Title string + Body string + CategoryID *uuid.UUID + ProfileID *uuid.UUID +} + +// Mutate applies the CreatePostInput on the PostMutation builder. +func (i *CreatePostInput) Mutate(m *PostMutation) { + if v := i.CreatedAt; v != nil { + m.SetCreatedAt(*v) + } + if v := i.UpdatedAt; v != nil { + m.SetUpdatedAt(*v) + } + if v := i.Expires; v != nil { + m.SetExpires(*v) + } + if v := i.ExpireTime; v != nil { + m.SetExpireTime(*v) + } + m.SetTitle(i.Title) + m.SetBody(i.Body) + if v := i.CategoryID; v != nil { + m.SetCategoryID(*v) + } + if v := i.ProfileID; v != nil { + m.SetProfileID(*v) + } +} + +// SetInput applies the change-set in the CreatePostInput on the PostCreate builder. +func (c *PostCreate) SetInput(i CreatePostInput) *PostCreate { + i.Mutate(c.Mutation()) + return c +} + +// UpdatePostInput represents a mutation input for updating posts. +type UpdatePostInput struct { + ClearUpdatedAt bool + UpdatedAt *time.Time + Expires *bool + ClearExpireTime bool + ExpireTime *time.Time + Title *string + Body *string + ClearCategory bool + CategoryID *uuid.UUID + ClearProfile bool + ProfileID *uuid.UUID +} + +// Mutate applies the UpdatePostInput on the PostMutation builder. +func (i *UpdatePostInput) Mutate(m *PostMutation) { + if i.ClearUpdatedAt { + m.ClearUpdatedAt() + } + if v := i.UpdatedAt; v != nil { + m.SetUpdatedAt(*v) + } + if v := i.Expires; v != nil { + m.SetExpires(*v) + } + if i.ClearExpireTime { + m.ClearExpireTime() + } + if v := i.ExpireTime; v != nil { + m.SetExpireTime(*v) + } + if v := i.Title; v != nil { + m.SetTitle(*v) + } + if v := i.Body; v != nil { + m.SetBody(*v) + } + if i.ClearCategory { + m.ClearCategory() + } + if v := i.CategoryID; v != nil { + m.SetCategoryID(*v) + } + if i.ClearProfile { + m.ClearProfile() + } + if v := i.ProfileID; v != nil { + m.SetProfileID(*v) + } +} + +// SetInput applies the change-set in the UpdatePostInput on the PostUpdate builder. +func (c *PostUpdate) SetInput(i UpdatePostInput) *PostUpdate { + i.Mutate(c.Mutation()) + return c +} + +// SetInput applies the change-set in the UpdatePostInput on the PostUpdateOne builder. +func (c *PostUpdateOne) SetInput(i UpdatePostInput) *PostUpdateOne { + i.Mutate(c.Mutation()) + return c +} + +// CreateProfileInput represents a mutation input for creating profiles. +type CreateProfileInput struct { + CreatedAt *time.Time + UpdatedAt *time.Time + Name *string + Address *string + Phone *string + PostIDs []uuid.UUID +} + +// Mutate applies the CreateProfileInput on the ProfileMutation builder. +func (i *CreateProfileInput) Mutate(m *ProfileMutation) { + if v := i.CreatedAt; v != nil { + m.SetCreatedAt(*v) + } + if v := i.UpdatedAt; v != nil { + m.SetUpdatedAt(*v) + } + if v := i.Name; v != nil { + m.SetName(*v) + } + if v := i.Address; v != nil { + m.SetAddress(*v) + } + if v := i.Phone; v != nil { + m.SetPhone(*v) + } + if v := i.PostIDs; len(v) > 0 { + m.AddPostIDs(v...) + } +} + +// SetInput applies the change-set in the CreateProfileInput on the ProfileCreate builder. +func (c *ProfileCreate) SetInput(i CreateProfileInput) *ProfileCreate { + i.Mutate(c.Mutation()) + return c +} + +// UpdateProfileInput represents a mutation input for updating profiles. +type UpdateProfileInput struct { + ClearUpdatedAt bool + UpdatedAt *time.Time + ClearName bool + Name *string + ClearAddress bool + Address *string + ClearPhone bool + Phone *string + ClearPosts bool + AddPostIDs []uuid.UUID + RemovePostIDs []uuid.UUID +} + +// Mutate applies the UpdateProfileInput on the ProfileMutation builder. +func (i *UpdateProfileInput) Mutate(m *ProfileMutation) { + if i.ClearUpdatedAt { + m.ClearUpdatedAt() + } + if v := i.UpdatedAt; v != nil { + m.SetUpdatedAt(*v) + } + if i.ClearName { + m.ClearName() + } + if v := i.Name; v != nil { + m.SetName(*v) + } + if i.ClearAddress { + m.ClearAddress() + } + if v := i.Address; v != nil { + m.SetAddress(*v) + } + if i.ClearPhone { + m.ClearPhone() + } + if v := i.Phone; v != nil { + m.SetPhone(*v) + } + if i.ClearPosts { + m.ClearPosts() + } + if v := i.AddPostIDs; len(v) > 0 { + m.AddPostIDs(v...) + } + if v := i.RemovePostIDs; len(v) > 0 { + m.RemovePostIDs(v...) + } +} + +// SetInput applies the change-set in the UpdateProfileInput on the ProfileUpdate builder. +func (c *ProfileUpdate) SetInput(i UpdateProfileInput) *ProfileUpdate { + i.Mutate(c.Mutation()) + return c +} + +// SetInput applies the change-set in the UpdateProfileInput on the ProfileUpdateOne builder. +func (c *ProfileUpdateOne) SetInput(i UpdateProfileInput) *ProfileUpdateOne { + i.Mutate(c.Mutation()) + return c +} diff --git a/ent/gql_node.go b/ent/gql_node.go new file mode 100644 index 0000000..ac91924 --- /dev/null +++ b/ent/gql_node.go @@ -0,0 +1,248 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/contrib/entgql" + "github.com/99designs/gqlgen/graphql" + "github.com/google/uuid" + "github.com/hashicorp/go-multierror" +) + +// Noder wraps the basic Node method. +type Noder interface { + IsNode() +} + +var categoryImplementors = []string{"Category", "Node"} + +// IsNode implements the Node interface check for GQLGen. +func (*Category) IsNode() {} + +var postImplementors = []string{"Post", "Node"} + +// IsNode implements the Node interface check for GQLGen. +func (*Post) IsNode() {} + +var profileImplementors = []string{"Profile", "Node"} + +// IsNode implements the Node interface check for GQLGen. +func (*Profile) IsNode() {} + +var errNodeInvalidID = &NotFoundError{"node"} + +// NodeOption allows configuring the Noder execution using functional options. +type NodeOption func(*nodeOptions) + +// WithNodeType sets the node Type resolver function (i.e. the table to query). +// If was not provided, the table will be derived from the universal-id +// configuration as described in: https://entgo.io/docs/migrate/#universal-ids. +func WithNodeType(f func(context.Context, uuid.UUID) (string, error)) NodeOption { + return func(o *nodeOptions) { + o.nodeType = f + } +} + +// WithFixedNodeType sets the Type of the node to a fixed value. +func WithFixedNodeType(t string) NodeOption { + return WithNodeType(func(context.Context, uuid.UUID) (string, error) { + return t, nil + }) +} + +type nodeOptions struct { + nodeType func(context.Context, uuid.UUID) (string, error) +} + +func (c *Client) newNodeOpts(opts []NodeOption) *nodeOptions { + nopts := &nodeOptions{} + for _, opt := range opts { + opt(nopts) + } + if nopts.nodeType == nil { + nopts.nodeType = func(ctx context.Context, id uuid.UUID) (string, error) { + return "", fmt.Errorf("cannot resolve noder (%v) without its type", id) + } + } + return nopts +} + +// Noder returns a Node by its id. If the NodeType was not provided, it will +// be derived from the id value according to the universal-id configuration. +// +// c.Noder(ctx, id) +// c.Noder(ctx, id, ent.WithNodeType(typeResolver)) +func (c *Client) Noder(ctx context.Context, id uuid.UUID, opts ...NodeOption) (_ Noder, err error) { + defer func() { + if IsNotFound(err) { + err = multierror.Append(err, entgql.ErrNodeNotFound(id)) + } + }() + table, err := c.newNodeOpts(opts).nodeType(ctx, id) + if err != nil { + return nil, err + } + return c.noder(ctx, table, id) +} + +func (c *Client) noder(ctx context.Context, table string, id uuid.UUID) (Noder, error) { + switch table { + case category.Table: + query := c.Category.Query(). + Where(category.ID(id)) + if fc := graphql.GetFieldContext(ctx); fc != nil { + if err := query.collectField(ctx, true, graphql.GetOperationContext(ctx), fc.Field, nil, categoryImplementors...); err != nil { + return nil, err + } + } + return query.Only(ctx) + case post.Table: + query := c.Post.Query(). + Where(post.ID(id)) + if fc := graphql.GetFieldContext(ctx); fc != nil { + if err := query.collectField(ctx, true, graphql.GetOperationContext(ctx), fc.Field, nil, postImplementors...); err != nil { + return nil, err + } + } + return query.Only(ctx) + case profile.Table: + query := c.Profile.Query(). + Where(profile.ID(id)) + if fc := graphql.GetFieldContext(ctx); fc != nil { + if err := query.collectField(ctx, true, graphql.GetOperationContext(ctx), fc.Field, nil, profileImplementors...); err != nil { + return nil, err + } + } + return query.Only(ctx) + default: + return nil, fmt.Errorf("cannot resolve noder from table %q: %w", table, errNodeInvalidID) + } +} + +func (c *Client) Noders(ctx context.Context, ids []uuid.UUID, opts ...NodeOption) ([]Noder, error) { + switch len(ids) { + case 1: + noder, err := c.Noder(ctx, ids[0], opts...) + if err != nil { + return nil, err + } + return []Noder{noder}, nil + case 0: + return []Noder{}, nil + } + + noders := make([]Noder, len(ids)) + errors := make([]error, len(ids)) + tables := make(map[string][]uuid.UUID) + id2idx := make(map[uuid.UUID][]int, len(ids)) + nopts := c.newNodeOpts(opts) + for i, id := range ids { + table, err := nopts.nodeType(ctx, id) + if err != nil { + errors[i] = err + continue + } + tables[table] = append(tables[table], id) + id2idx[id] = append(id2idx[id], i) + } + + for table, ids := range tables { + nodes, err := c.noders(ctx, table, ids) + if err != nil { + for _, id := range ids { + for _, idx := range id2idx[id] { + errors[idx] = err + } + } + } else { + for i, id := range ids { + for _, idx := range id2idx[id] { + noders[idx] = nodes[i] + } + } + } + } + + for i, id := range ids { + if errors[i] == nil { + if noders[i] != nil { + continue + } + errors[i] = entgql.ErrNodeNotFound(id) + } else if IsNotFound(errors[i]) { + errors[i] = multierror.Append(errors[i], entgql.ErrNodeNotFound(id)) + } + ctx := graphql.WithPathContext(ctx, + graphql.NewPathWithIndex(i), + ) + graphql.AddError(ctx, errors[i]) + } + return noders, nil +} + +func (c *Client) noders(ctx context.Context, table string, ids []uuid.UUID) ([]Noder, error) { + noders := make([]Noder, len(ids)) + idmap := make(map[uuid.UUID][]*Noder, len(ids)) + for i, id := range ids { + idmap[id] = append(idmap[id], &noders[i]) + } + switch table { + case category.Table: + query := c.Category.Query(). + Where(category.IDIn(ids...)) + query, err := query.CollectFields(ctx, categoryImplementors...) + if err != nil { + return nil, err + } + nodes, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, node := range nodes { + for _, noder := range idmap[node.ID] { + *noder = node + } + } + case post.Table: + query := c.Post.Query(). + Where(post.IDIn(ids...)) + query, err := query.CollectFields(ctx, postImplementors...) + if err != nil { + return nil, err + } + nodes, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, node := range nodes { + for _, noder := range idmap[node.ID] { + *noder = node + } + } + case profile.Table: + query := c.Profile.Query(). + Where(profile.IDIn(ids...)) + query, err := query.CollectFields(ctx, profileImplementors...) + if err != nil { + return nil, err + } + nodes, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, node := range nodes { + for _, noder := range idmap[node.ID] { + *noder = node + } + } + default: + return nil, fmt.Errorf("cannot resolve noders from table %q: %w", table, errNodeInvalidID) + } + return noders, nil +} diff --git a/ent/gql_pagination.go b/ent/gql_pagination.go new file mode 100644 index 0000000..cc10b07 --- /dev/null +++ b/ent/gql_pagination.go @@ -0,0 +1,1126 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "io" + "strconv" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/contrib/entgql" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/errcode" + "github.com/google/uuid" + "github.com/vektah/gqlparser/v2/gqlerror" +) + +// Common entgql types. +type ( + Cursor = entgql.Cursor[uuid.UUID] + PageInfo = entgql.PageInfo[uuid.UUID] + OrderDirection = entgql.OrderDirection +) + +func orderFunc(o OrderDirection, field string) func(*sql.Selector) { + if o == entgql.OrderDirectionDesc { + return Desc(field) + } + return Asc(field) +} + +const errInvalidPagination = "INVALID_PAGINATION" + +func validateFirstLast(first, last *int) (err *gqlerror.Error) { + switch { + case first != nil && last != nil: + err = &gqlerror.Error{ + Message: "Passing both `first` and `last` to paginate a connection is not supported.", + } + case first != nil && *first < 0: + err = &gqlerror.Error{ + Message: "`first` on a connection cannot be less than zero.", + } + errcode.Set(err, errInvalidPagination) + case last != nil && *last < 0: + err = &gqlerror.Error{ + Message: "`last` on a connection cannot be less than zero.", + } + errcode.Set(err, errInvalidPagination) + } + return err +} + +func collectedField(ctx context.Context, path ...string) *graphql.CollectedField { + fc := graphql.GetFieldContext(ctx) + if fc == nil { + return nil + } + field := fc.Field + oc := graphql.GetOperationContext(ctx) +walk: + for _, name := range path { + for _, f := range graphql.CollectFields(oc, field.Selections, nil) { + if f.Alias == name { + field = f + continue walk + } + } + return nil + } + return &field +} + +func hasCollectedField(ctx context.Context, path ...string) bool { + if graphql.GetFieldContext(ctx) == nil { + return true + } + return collectedField(ctx, path...) != nil +} + +const ( + edgesField = "edges" + nodeField = "node" + pageInfoField = "pageInfo" + totalCountField = "totalCount" +) + +func paginateLimit(first, last *int) int { + var limit int + if first != nil { + limit = *first + 1 + } else if last != nil { + limit = *last + 1 + } + return limit +} + +// CategoryEdge is the edge representation of Category. +type CategoryEdge struct { + Node *Category `json:"node"` + Cursor Cursor `json:"cursor"` +} + +// CategoryConnection is the connection containing edges to Category. +type CategoryConnection struct { + Edges []*CategoryEdge `json:"edges"` + PageInfo PageInfo `json:"pageInfo"` + TotalCount int `json:"totalCount"` +} + +func (c *CategoryConnection) build(nodes []*Category, pager *categoryPager, after *Cursor, first *int, before *Cursor, last *int) { + c.PageInfo.HasNextPage = before != nil + c.PageInfo.HasPreviousPage = after != nil + if first != nil && *first+1 == len(nodes) { + c.PageInfo.HasNextPage = true + nodes = nodes[:len(nodes)-1] + } else if last != nil && *last+1 == len(nodes) { + c.PageInfo.HasPreviousPage = true + nodes = nodes[:len(nodes)-1] + } + var nodeAt func(int) *Category + if last != nil { + n := len(nodes) - 1 + nodeAt = func(i int) *Category { + return nodes[n-i] + } + } else { + nodeAt = func(i int) *Category { + return nodes[i] + } + } + c.Edges = make([]*CategoryEdge, len(nodes)) + for i := range nodes { + node := nodeAt(i) + c.Edges[i] = &CategoryEdge{ + Node: node, + Cursor: pager.toCursor(node), + } + } + if l := len(c.Edges); l > 0 { + c.PageInfo.StartCursor = &c.Edges[0].Cursor + c.PageInfo.EndCursor = &c.Edges[l-1].Cursor + } + if c.TotalCount == 0 { + c.TotalCount = len(nodes) + } +} + +// CategoryPaginateOption enables pagination customization. +type CategoryPaginateOption func(*categoryPager) error + +// WithCategoryOrder configures pagination ordering. +func WithCategoryOrder(order *CategoryOrder) CategoryPaginateOption { + if order == nil { + order = DefaultCategoryOrder + } + o := *order + return func(pager *categoryPager) error { + if err := o.Direction.Validate(); err != nil { + return err + } + if o.Field == nil { + o.Field = DefaultCategoryOrder.Field + } + pager.order = &o + return nil + } +} + +// WithCategoryFilter configures pagination filter. +func WithCategoryFilter(filter func(*CategoryQuery) (*CategoryQuery, error)) CategoryPaginateOption { + return func(pager *categoryPager) error { + if filter == nil { + return errors.New("CategoryQuery filter cannot be nil") + } + pager.filter = filter + return nil + } +} + +type categoryPager struct { + reverse bool + order *CategoryOrder + filter func(*CategoryQuery) (*CategoryQuery, error) +} + +func newCategoryPager(opts []CategoryPaginateOption, reverse bool) (*categoryPager, error) { + pager := &categoryPager{reverse: reverse} + for _, opt := range opts { + if err := opt(pager); err != nil { + return nil, err + } + } + if pager.order == nil { + pager.order = DefaultCategoryOrder + } + return pager, nil +} + +func (p *categoryPager) applyFilter(query *CategoryQuery) (*CategoryQuery, error) { + if p.filter != nil { + return p.filter(query) + } + return query, nil +} + +func (p *categoryPager) toCursor(c *Category) Cursor { + return p.order.Field.toCursor(c) +} + +func (p *categoryPager) applyCursors(query *CategoryQuery, after, before *Cursor) (*CategoryQuery, error) { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + for _, predicate := range entgql.CursorsPredicate(after, before, DefaultCategoryOrder.Field.column, p.order.Field.column, direction) { + query = query.Where(predicate) + } + return query, nil +} + +func (p *categoryPager) applyOrder(query *CategoryQuery) *CategoryQuery { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + query = query.Order(p.order.Field.toTerm(direction.OrderTermOption())) + if p.order.Field != DefaultCategoryOrder.Field { + query = query.Order(DefaultCategoryOrder.Field.toTerm(direction.OrderTermOption())) + } + switch p.order.Field.column { + case CategoryOrderFieldPostsCount.column: + default: + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(p.order.Field.column) + } + } + return query +} + +func (p *categoryPager) orderExpr(query *CategoryQuery) sql.Querier { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + switch p.order.Field.column { + case CategoryOrderFieldPostsCount.column: + query = query.Order(p.order.Field.toTerm(direction.OrderTermOption())) + default: + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(p.order.Field.column) + } + } + return sql.ExprFunc(func(b *sql.Builder) { + b.Ident(p.order.Field.column).Pad().WriteString(string(direction)) + if p.order.Field != DefaultCategoryOrder.Field { + b.Comma().Ident(DefaultCategoryOrder.Field.column).Pad().WriteString(string(direction)) + } + }) +} + +// Paginate executes the query and returns a relay based cursor connection to Category. +func (c *CategoryQuery) Paginate( + ctx context.Context, after *Cursor, first *int, + before *Cursor, last *int, opts ...CategoryPaginateOption, +) (*CategoryConnection, error) { + if err := validateFirstLast(first, last); err != nil { + return nil, err + } + pager, err := newCategoryPager(opts, last != nil) + if err != nil { + return nil, err + } + if c, err = pager.applyFilter(c); err != nil { + return nil, err + } + conn := &CategoryConnection{Edges: []*CategoryEdge{}} + ignoredEdges := !hasCollectedField(ctx, edgesField) + if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + hasPagination := after != nil || first != nil || before != nil || last != nil + if hasPagination || ignoredEdges { + c := c.Clone() + c.ctx.Fields = nil + if conn.TotalCount, err = c.Count(ctx); err != nil { + return nil, err + } + conn.PageInfo.HasNextPage = first != nil && conn.TotalCount > 0 + conn.PageInfo.HasPreviousPage = last != nil && conn.TotalCount > 0 + } + } + if ignoredEdges || (first != nil && *first == 0) || (last != nil && *last == 0) { + return conn, nil + } + if c, err = pager.applyCursors(c, after, before); err != nil { + return nil, err + } + limit := paginateLimit(first, last) + if limit != 0 { + c.Limit(limit) + } + if field := collectedField(ctx, edgesField, nodeField); field != nil { + if err := c.collectField(ctx, limit == 1, graphql.GetOperationContext(ctx), *field, []string{edgesField, nodeField}); err != nil { + return nil, err + } + } + c = pager.applyOrder(c) + nodes, err := c.All(ctx) + if err != nil { + return nil, err + } + conn.build(nodes, pager, after, first, before, last) + return conn, nil +} + +var ( + // CategoryOrderFieldCreatedAt orders Category by created_at. + CategoryOrderFieldCreatedAt = &CategoryOrderField{ + Value: func(c *Category) (ent.Value, error) { + return c.CreatedAt, nil + }, + column: category.FieldCreatedAt, + toTerm: category.ByCreatedAt, + toCursor: func(c *Category) Cursor { + return Cursor{ + ID: c.ID, + Value: c.CreatedAt, + } + }, + } + // CategoryOrderFieldUpdatedAt orders Category by updated_at. + CategoryOrderFieldUpdatedAt = &CategoryOrderField{ + Value: func(c *Category) (ent.Value, error) { + return c.UpdatedAt, nil + }, + column: category.FieldUpdatedAt, + toTerm: category.ByUpdatedAt, + toCursor: func(c *Category) Cursor { + return Cursor{ + ID: c.ID, + Value: c.UpdatedAt, + } + }, + } + // CategoryOrderFieldPostsCount orders by POSTS_COUNT. + CategoryOrderFieldPostsCount = &CategoryOrderField{ + Value: func(c *Category) (ent.Value, error) { + return c.Value("posts_count") + }, + column: "posts_count", + toTerm: func(opts ...sql.OrderTermOption) category.OrderOption { + return category.ByPostsCount( + append(opts, sql.OrderSelectAs("posts_count"))..., + ) + }, + toCursor: func(c *Category) Cursor { + cv, _ := c.Value("posts_count") + return Cursor{ + ID: c.ID, + Value: cv, + } + }, + } +) + +// String implement fmt.Stringer interface. +func (f CategoryOrderField) String() string { + var str string + switch f.column { + case CategoryOrderFieldCreatedAt.column: + str = "CREATED_AT" + case CategoryOrderFieldUpdatedAt.column: + str = "UPDATED_AT" + case CategoryOrderFieldPostsCount.column: + str = "POSTS_COUNT" + } + return str +} + +// MarshalGQL implements graphql.Marshaler interface. +func (f CategoryOrderField) MarshalGQL(w io.Writer) { + io.WriteString(w, strconv.Quote(f.String())) +} + +// UnmarshalGQL implements graphql.Unmarshaler interface. +func (f *CategoryOrderField) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("CategoryOrderField %T must be a string", v) + } + switch str { + case "CREATED_AT": + *f = *CategoryOrderFieldCreatedAt + case "UPDATED_AT": + *f = *CategoryOrderFieldUpdatedAt + case "POSTS_COUNT": + *f = *CategoryOrderFieldPostsCount + default: + return fmt.Errorf("%s is not a valid CategoryOrderField", str) + } + return nil +} + +// CategoryOrderField defines the ordering field of Category. +type CategoryOrderField struct { + // Value extracts the ordering value from the given Category. + Value func(*Category) (ent.Value, error) + column string // field or computed. + toTerm func(...sql.OrderTermOption) category.OrderOption + toCursor func(*Category) Cursor +} + +// CategoryOrder defines the ordering of Category. +type CategoryOrder struct { + Direction OrderDirection `json:"direction"` + Field *CategoryOrderField `json:"field"` +} + +// DefaultCategoryOrder is the default ordering of Category. +var DefaultCategoryOrder = &CategoryOrder{ + Direction: entgql.OrderDirectionAsc, + Field: &CategoryOrderField{ + Value: func(c *Category) (ent.Value, error) { + return c.ID, nil + }, + column: category.FieldID, + toTerm: category.ByID, + toCursor: func(c *Category) Cursor { + return Cursor{ID: c.ID} + }, + }, +} + +// ToEdge converts Category into CategoryEdge. +func (c *Category) ToEdge(order *CategoryOrder) *CategoryEdge { + if order == nil { + order = DefaultCategoryOrder + } + return &CategoryEdge{ + Node: c, + Cursor: order.Field.toCursor(c), + } +} + +// PostEdge is the edge representation of Post. +type PostEdge struct { + Node *Post `json:"node"` + Cursor Cursor `json:"cursor"` +} + +// PostConnection is the connection containing edges to Post. +type PostConnection struct { + Edges []*PostEdge `json:"edges"` + PageInfo PageInfo `json:"pageInfo"` + TotalCount int `json:"totalCount"` +} + +func (c *PostConnection) build(nodes []*Post, pager *postPager, after *Cursor, first *int, before *Cursor, last *int) { + c.PageInfo.HasNextPage = before != nil + c.PageInfo.HasPreviousPage = after != nil + if first != nil && *first+1 == len(nodes) { + c.PageInfo.HasNextPage = true + nodes = nodes[:len(nodes)-1] + } else if last != nil && *last+1 == len(nodes) { + c.PageInfo.HasPreviousPage = true + nodes = nodes[:len(nodes)-1] + } + var nodeAt func(int) *Post + if last != nil { + n := len(nodes) - 1 + nodeAt = func(i int) *Post { + return nodes[n-i] + } + } else { + nodeAt = func(i int) *Post { + return nodes[i] + } + } + c.Edges = make([]*PostEdge, len(nodes)) + for i := range nodes { + node := nodeAt(i) + c.Edges[i] = &PostEdge{ + Node: node, + Cursor: pager.toCursor(node), + } + } + if l := len(c.Edges); l > 0 { + c.PageInfo.StartCursor = &c.Edges[0].Cursor + c.PageInfo.EndCursor = &c.Edges[l-1].Cursor + } + if c.TotalCount == 0 { + c.TotalCount = len(nodes) + } +} + +// PostPaginateOption enables pagination customization. +type PostPaginateOption func(*postPager) error + +// WithPostOrder configures pagination ordering. +func WithPostOrder(order *PostOrder) PostPaginateOption { + if order == nil { + order = DefaultPostOrder + } + o := *order + return func(pager *postPager) error { + if err := o.Direction.Validate(); err != nil { + return err + } + if o.Field == nil { + o.Field = DefaultPostOrder.Field + } + pager.order = &o + return nil + } +} + +// WithPostFilter configures pagination filter. +func WithPostFilter(filter func(*PostQuery) (*PostQuery, error)) PostPaginateOption { + return func(pager *postPager) error { + if filter == nil { + return errors.New("PostQuery filter cannot be nil") + } + pager.filter = filter + return nil + } +} + +type postPager struct { + reverse bool + order *PostOrder + filter func(*PostQuery) (*PostQuery, error) +} + +func newPostPager(opts []PostPaginateOption, reverse bool) (*postPager, error) { + pager := &postPager{reverse: reverse} + for _, opt := range opts { + if err := opt(pager); err != nil { + return nil, err + } + } + if pager.order == nil { + pager.order = DefaultPostOrder + } + return pager, nil +} + +func (p *postPager) applyFilter(query *PostQuery) (*PostQuery, error) { + if p.filter != nil { + return p.filter(query) + } + return query, nil +} + +func (p *postPager) toCursor(po *Post) Cursor { + return p.order.Field.toCursor(po) +} + +func (p *postPager) applyCursors(query *PostQuery, after, before *Cursor) (*PostQuery, error) { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + for _, predicate := range entgql.CursorsPredicate(after, before, DefaultPostOrder.Field.column, p.order.Field.column, direction) { + query = query.Where(predicate) + } + return query, nil +} + +func (p *postPager) applyOrder(query *PostQuery) *PostQuery { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + query = query.Order(p.order.Field.toTerm(direction.OrderTermOption())) + if p.order.Field != DefaultPostOrder.Field { + query = query.Order(DefaultPostOrder.Field.toTerm(direction.OrderTermOption())) + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(p.order.Field.column) + } + return query +} + +func (p *postPager) orderExpr(query *PostQuery) sql.Querier { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(p.order.Field.column) + } + return sql.ExprFunc(func(b *sql.Builder) { + b.Ident(p.order.Field.column).Pad().WriteString(string(direction)) + if p.order.Field != DefaultPostOrder.Field { + b.Comma().Ident(DefaultPostOrder.Field.column).Pad().WriteString(string(direction)) + } + }) +} + +// Paginate executes the query and returns a relay based cursor connection to Post. +func (po *PostQuery) Paginate( + ctx context.Context, after *Cursor, first *int, + before *Cursor, last *int, opts ...PostPaginateOption, +) (*PostConnection, error) { + if err := validateFirstLast(first, last); err != nil { + return nil, err + } + pager, err := newPostPager(opts, last != nil) + if err != nil { + return nil, err + } + if po, err = pager.applyFilter(po); err != nil { + return nil, err + } + conn := &PostConnection{Edges: []*PostEdge{}} + ignoredEdges := !hasCollectedField(ctx, edgesField) + if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + hasPagination := after != nil || first != nil || before != nil || last != nil + if hasPagination || ignoredEdges { + c := po.Clone() + c.ctx.Fields = nil + if conn.TotalCount, err = c.Count(ctx); err != nil { + return nil, err + } + conn.PageInfo.HasNextPage = first != nil && conn.TotalCount > 0 + conn.PageInfo.HasPreviousPage = last != nil && conn.TotalCount > 0 + } + } + if ignoredEdges || (first != nil && *first == 0) || (last != nil && *last == 0) { + return conn, nil + } + if po, err = pager.applyCursors(po, after, before); err != nil { + return nil, err + } + limit := paginateLimit(first, last) + if limit != 0 { + po.Limit(limit) + } + if field := collectedField(ctx, edgesField, nodeField); field != nil { + if err := po.collectField(ctx, limit == 1, graphql.GetOperationContext(ctx), *field, []string{edgesField, nodeField}); err != nil { + return nil, err + } + } + po = pager.applyOrder(po) + nodes, err := po.All(ctx) + if err != nil { + return nil, err + } + conn.build(nodes, pager, after, first, before, last) + return conn, nil +} + +var ( + // PostOrderFieldCreatedAt orders Post by created_at. + PostOrderFieldCreatedAt = &PostOrderField{ + Value: func(po *Post) (ent.Value, error) { + return po.CreatedAt, nil + }, + column: post.FieldCreatedAt, + toTerm: post.ByCreatedAt, + toCursor: func(po *Post) Cursor { + return Cursor{ + ID: po.ID, + Value: po.CreatedAt, + } + }, + } + // PostOrderFieldUpdatedAt orders Post by updated_at. + PostOrderFieldUpdatedAt = &PostOrderField{ + Value: func(po *Post) (ent.Value, error) { + return po.UpdatedAt, nil + }, + column: post.FieldUpdatedAt, + toTerm: post.ByUpdatedAt, + toCursor: func(po *Post) Cursor { + return Cursor{ + ID: po.ID, + Value: po.UpdatedAt, + } + }, + } + // PostOrderFieldExpireTime orders Post by expire_time. + PostOrderFieldExpireTime = &PostOrderField{ + Value: func(po *Post) (ent.Value, error) { + return po.ExpireTime, nil + }, + column: post.FieldExpireTime, + toTerm: post.ByExpireTime, + toCursor: func(po *Post) Cursor { + return Cursor{ + ID: po.ID, + Value: po.ExpireTime, + } + }, + } +) + +// String implement fmt.Stringer interface. +func (f PostOrderField) String() string { + var str string + switch f.column { + case PostOrderFieldCreatedAt.column: + str = "CREATED_AT" + case PostOrderFieldUpdatedAt.column: + str = "UPDATED_AT" + case PostOrderFieldExpireTime.column: + str = "EXPIRE_TIME" + } + return str +} + +// MarshalGQL implements graphql.Marshaler interface. +func (f PostOrderField) MarshalGQL(w io.Writer) { + io.WriteString(w, strconv.Quote(f.String())) +} + +// UnmarshalGQL implements graphql.Unmarshaler interface. +func (f *PostOrderField) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("PostOrderField %T must be a string", v) + } + switch str { + case "CREATED_AT": + *f = *PostOrderFieldCreatedAt + case "UPDATED_AT": + *f = *PostOrderFieldUpdatedAt + case "EXPIRE_TIME": + *f = *PostOrderFieldExpireTime + default: + return fmt.Errorf("%s is not a valid PostOrderField", str) + } + return nil +} + +// PostOrderField defines the ordering field of Post. +type PostOrderField struct { + // Value extracts the ordering value from the given Post. + Value func(*Post) (ent.Value, error) + column string // field or computed. + toTerm func(...sql.OrderTermOption) post.OrderOption + toCursor func(*Post) Cursor +} + +// PostOrder defines the ordering of Post. +type PostOrder struct { + Direction OrderDirection `json:"direction"` + Field *PostOrderField `json:"field"` +} + +// DefaultPostOrder is the default ordering of Post. +var DefaultPostOrder = &PostOrder{ + Direction: entgql.OrderDirectionAsc, + Field: &PostOrderField{ + Value: func(po *Post) (ent.Value, error) { + return po.ID, nil + }, + column: post.FieldID, + toTerm: post.ByID, + toCursor: func(po *Post) Cursor { + return Cursor{ID: po.ID} + }, + }, +} + +// ToEdge converts Post into PostEdge. +func (po *Post) ToEdge(order *PostOrder) *PostEdge { + if order == nil { + order = DefaultPostOrder + } + return &PostEdge{ + Node: po, + Cursor: order.Field.toCursor(po), + } +} + +// ProfileEdge is the edge representation of Profile. +type ProfileEdge struct { + Node *Profile `json:"node"` + Cursor Cursor `json:"cursor"` +} + +// ProfileConnection is the connection containing edges to Profile. +type ProfileConnection struct { + Edges []*ProfileEdge `json:"edges"` + PageInfo PageInfo `json:"pageInfo"` + TotalCount int `json:"totalCount"` +} + +func (c *ProfileConnection) build(nodes []*Profile, pager *profilePager, after *Cursor, first *int, before *Cursor, last *int) { + c.PageInfo.HasNextPage = before != nil + c.PageInfo.HasPreviousPage = after != nil + if first != nil && *first+1 == len(nodes) { + c.PageInfo.HasNextPage = true + nodes = nodes[:len(nodes)-1] + } else if last != nil && *last+1 == len(nodes) { + c.PageInfo.HasPreviousPage = true + nodes = nodes[:len(nodes)-1] + } + var nodeAt func(int) *Profile + if last != nil { + n := len(nodes) - 1 + nodeAt = func(i int) *Profile { + return nodes[n-i] + } + } else { + nodeAt = func(i int) *Profile { + return nodes[i] + } + } + c.Edges = make([]*ProfileEdge, len(nodes)) + for i := range nodes { + node := nodeAt(i) + c.Edges[i] = &ProfileEdge{ + Node: node, + Cursor: pager.toCursor(node), + } + } + if l := len(c.Edges); l > 0 { + c.PageInfo.StartCursor = &c.Edges[0].Cursor + c.PageInfo.EndCursor = &c.Edges[l-1].Cursor + } + if c.TotalCount == 0 { + c.TotalCount = len(nodes) + } +} + +// ProfilePaginateOption enables pagination customization. +type ProfilePaginateOption func(*profilePager) error + +// WithProfileOrder configures pagination ordering. +func WithProfileOrder(order *ProfileOrder) ProfilePaginateOption { + if order == nil { + order = DefaultProfileOrder + } + o := *order + return func(pager *profilePager) error { + if err := o.Direction.Validate(); err != nil { + return err + } + if o.Field == nil { + o.Field = DefaultProfileOrder.Field + } + pager.order = &o + return nil + } +} + +// WithProfileFilter configures pagination filter. +func WithProfileFilter(filter func(*ProfileQuery) (*ProfileQuery, error)) ProfilePaginateOption { + return func(pager *profilePager) error { + if filter == nil { + return errors.New("ProfileQuery filter cannot be nil") + } + pager.filter = filter + return nil + } +} + +type profilePager struct { + reverse bool + order *ProfileOrder + filter func(*ProfileQuery) (*ProfileQuery, error) +} + +func newProfilePager(opts []ProfilePaginateOption, reverse bool) (*profilePager, error) { + pager := &profilePager{reverse: reverse} + for _, opt := range opts { + if err := opt(pager); err != nil { + return nil, err + } + } + if pager.order == nil { + pager.order = DefaultProfileOrder + } + return pager, nil +} + +func (p *profilePager) applyFilter(query *ProfileQuery) (*ProfileQuery, error) { + if p.filter != nil { + return p.filter(query) + } + return query, nil +} + +func (p *profilePager) toCursor(pr *Profile) Cursor { + return p.order.Field.toCursor(pr) +} + +func (p *profilePager) applyCursors(query *ProfileQuery, after, before *Cursor) (*ProfileQuery, error) { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + for _, predicate := range entgql.CursorsPredicate(after, before, DefaultProfileOrder.Field.column, p.order.Field.column, direction) { + query = query.Where(predicate) + } + return query, nil +} + +func (p *profilePager) applyOrder(query *ProfileQuery) *ProfileQuery { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + query = query.Order(p.order.Field.toTerm(direction.OrderTermOption())) + if p.order.Field != DefaultProfileOrder.Field { + query = query.Order(DefaultProfileOrder.Field.toTerm(direction.OrderTermOption())) + } + switch p.order.Field.column { + case ProfileOrderFieldPostsCount.column: + default: + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(p.order.Field.column) + } + } + return query +} + +func (p *profilePager) orderExpr(query *ProfileQuery) sql.Querier { + direction := p.order.Direction + if p.reverse { + direction = direction.Reverse() + } + switch p.order.Field.column { + case ProfileOrderFieldPostsCount.column: + query = query.Order(p.order.Field.toTerm(direction.OrderTermOption())) + default: + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(p.order.Field.column) + } + } + return sql.ExprFunc(func(b *sql.Builder) { + b.Ident(p.order.Field.column).Pad().WriteString(string(direction)) + if p.order.Field != DefaultProfileOrder.Field { + b.Comma().Ident(DefaultProfileOrder.Field.column).Pad().WriteString(string(direction)) + } + }) +} + +// Paginate executes the query and returns a relay based cursor connection to Profile. +func (pr *ProfileQuery) Paginate( + ctx context.Context, after *Cursor, first *int, + before *Cursor, last *int, opts ...ProfilePaginateOption, +) (*ProfileConnection, error) { + if err := validateFirstLast(first, last); err != nil { + return nil, err + } + pager, err := newProfilePager(opts, last != nil) + if err != nil { + return nil, err + } + if pr, err = pager.applyFilter(pr); err != nil { + return nil, err + } + conn := &ProfileConnection{Edges: []*ProfileEdge{}} + ignoredEdges := !hasCollectedField(ctx, edgesField) + if hasCollectedField(ctx, totalCountField) || hasCollectedField(ctx, pageInfoField) { + hasPagination := after != nil || first != nil || before != nil || last != nil + if hasPagination || ignoredEdges { + c := pr.Clone() + c.ctx.Fields = nil + if conn.TotalCount, err = c.Count(ctx); err != nil { + return nil, err + } + conn.PageInfo.HasNextPage = first != nil && conn.TotalCount > 0 + conn.PageInfo.HasPreviousPage = last != nil && conn.TotalCount > 0 + } + } + if ignoredEdges || (first != nil && *first == 0) || (last != nil && *last == 0) { + return conn, nil + } + if pr, err = pager.applyCursors(pr, after, before); err != nil { + return nil, err + } + limit := paginateLimit(first, last) + if limit != 0 { + pr.Limit(limit) + } + if field := collectedField(ctx, edgesField, nodeField); field != nil { + if err := pr.collectField(ctx, limit == 1, graphql.GetOperationContext(ctx), *field, []string{edgesField, nodeField}); err != nil { + return nil, err + } + } + pr = pager.applyOrder(pr) + nodes, err := pr.All(ctx) + if err != nil { + return nil, err + } + conn.build(nodes, pager, after, first, before, last) + return conn, nil +} + +var ( + // ProfileOrderFieldCreatedAt orders Profile by created_at. + ProfileOrderFieldCreatedAt = &ProfileOrderField{ + Value: func(pr *Profile) (ent.Value, error) { + return pr.CreatedAt, nil + }, + column: profile.FieldCreatedAt, + toTerm: profile.ByCreatedAt, + toCursor: func(pr *Profile) Cursor { + return Cursor{ + ID: pr.ID, + Value: pr.CreatedAt, + } + }, + } + // ProfileOrderFieldUpdatedAt orders Profile by updated_at. + ProfileOrderFieldUpdatedAt = &ProfileOrderField{ + Value: func(pr *Profile) (ent.Value, error) { + return pr.UpdatedAt, nil + }, + column: profile.FieldUpdatedAt, + toTerm: profile.ByUpdatedAt, + toCursor: func(pr *Profile) Cursor { + return Cursor{ + ID: pr.ID, + Value: pr.UpdatedAt, + } + }, + } + // ProfileOrderFieldPostsCount orders by POSTS_COUNT. + ProfileOrderFieldPostsCount = &ProfileOrderField{ + Value: func(pr *Profile) (ent.Value, error) { + return pr.Value("posts_count") + }, + column: "posts_count", + toTerm: func(opts ...sql.OrderTermOption) profile.OrderOption { + return profile.ByPostsCount( + append(opts, sql.OrderSelectAs("posts_count"))..., + ) + }, + toCursor: func(pr *Profile) Cursor { + cv, _ := pr.Value("posts_count") + return Cursor{ + ID: pr.ID, + Value: cv, + } + }, + } +) + +// String implement fmt.Stringer interface. +func (f ProfileOrderField) String() string { + var str string + switch f.column { + case ProfileOrderFieldCreatedAt.column: + str = "CREATED_AT" + case ProfileOrderFieldUpdatedAt.column: + str = "UPDATED_AT" + case ProfileOrderFieldPostsCount.column: + str = "POSTS_COUNT" + } + return str +} + +// MarshalGQL implements graphql.Marshaler interface. +func (f ProfileOrderField) MarshalGQL(w io.Writer) { + io.WriteString(w, strconv.Quote(f.String())) +} + +// UnmarshalGQL implements graphql.Unmarshaler interface. +func (f *ProfileOrderField) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("ProfileOrderField %T must be a string", v) + } + switch str { + case "CREATED_AT": + *f = *ProfileOrderFieldCreatedAt + case "UPDATED_AT": + *f = *ProfileOrderFieldUpdatedAt + case "POSTS_COUNT": + *f = *ProfileOrderFieldPostsCount + default: + return fmt.Errorf("%s is not a valid ProfileOrderField", str) + } + return nil +} + +// ProfileOrderField defines the ordering field of Profile. +type ProfileOrderField struct { + // Value extracts the ordering value from the given Profile. + Value func(*Profile) (ent.Value, error) + column string // field or computed. + toTerm func(...sql.OrderTermOption) profile.OrderOption + toCursor func(*Profile) Cursor +} + +// ProfileOrder defines the ordering of Profile. +type ProfileOrder struct { + Direction OrderDirection `json:"direction"` + Field *ProfileOrderField `json:"field"` +} + +// DefaultProfileOrder is the default ordering of Profile. +var DefaultProfileOrder = &ProfileOrder{ + Direction: entgql.OrderDirectionAsc, + Field: &ProfileOrderField{ + Value: func(pr *Profile) (ent.Value, error) { + return pr.ID, nil + }, + column: profile.FieldID, + toTerm: profile.ByID, + toCursor: func(pr *Profile) Cursor { + return Cursor{ID: pr.ID} + }, + }, +} + +// ToEdge converts Profile into ProfileEdge. +func (pr *Profile) ToEdge(order *ProfileOrder) *ProfileEdge { + if order == nil { + order = DefaultProfileOrder + } + return &ProfileEdge{ + Node: pr, + Cursor: order.Field.toCursor(pr), + } +} diff --git a/ent/gql_transaction.go b/ent/gql_transaction.go new file mode 100644 index 0000000..9611713 --- /dev/null +++ b/ent/gql_transaction.go @@ -0,0 +1,30 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "errors" +) + +// OpenTx opens a transaction and returns a transactional +// context along with the created transaction. +func (c *Client) OpenTx(ctx context.Context) (context.Context, driver.Tx, error) { + tx, err := c.Tx(ctx) + if err != nil { + return nil, nil, err + } + ctx = NewTxContext(ctx, tx) + ctx = NewContext(ctx, tx.Client()) + return ctx, tx, nil +} + +// OpenTxFromContext open transactions from client stored in context. +func OpenTxFromContext(ctx context.Context) (context.Context, driver.Tx, error) { + client := FromContext(ctx) + if client == nil { + return nil, nil, errors.New("no client attached to context") + } + return client.OpenTx(ctx) +} diff --git a/ent/gql_where_input.go b/ent/gql_where_input.go new file mode 100644 index 0000000..0a3ceb2 --- /dev/null +++ b/ent/gql_where_input.go @@ -0,0 +1,1165 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "errors" + "fmt" + "time" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "code.icod.de/dalu/ka/ent/profile" + "github.com/google/uuid" +) + +// CategoryWhereInput represents a where input for filtering Category queries. +type CategoryWhereInput struct { + Predicates []predicate.Category `json:"-"` + Not *CategoryWhereInput `json:"not,omitempty"` + Or []*CategoryWhereInput `json:"or,omitempty"` + And []*CategoryWhereInput `json:"and,omitempty"` + + // "id" field predicates. + ID *uuid.UUID `json:"id,omitempty"` + IDNEQ *uuid.UUID `json:"idNEQ,omitempty"` + IDIn []uuid.UUID `json:"idIn,omitempty"` + IDNotIn []uuid.UUID `json:"idNotIn,omitempty"` + IDGT *uuid.UUID `json:"idGT,omitempty"` + IDGTE *uuid.UUID `json:"idGTE,omitempty"` + IDLT *uuid.UUID `json:"idLT,omitempty"` + IDLTE *uuid.UUID `json:"idLTE,omitempty"` + + // "created_at" field predicates. + CreatedAt *time.Time `json:"createdAt,omitempty"` + CreatedAtNEQ *time.Time `json:"createdAtNEQ,omitempty"` + CreatedAtIn []time.Time `json:"createdAtIn,omitempty"` + CreatedAtNotIn []time.Time `json:"createdAtNotIn,omitempty"` + CreatedAtGT *time.Time `json:"createdAtGT,omitempty"` + CreatedAtGTE *time.Time `json:"createdAtGTE,omitempty"` + CreatedAtLT *time.Time `json:"createdAtLT,omitempty"` + CreatedAtLTE *time.Time `json:"createdAtLTE,omitempty"` + + // "updated_at" field predicates. + UpdatedAt *time.Time `json:"updatedAt,omitempty"` + UpdatedAtNEQ *time.Time `json:"updatedAtNEQ,omitempty"` + UpdatedAtIn []time.Time `json:"updatedAtIn,omitempty"` + UpdatedAtNotIn []time.Time `json:"updatedAtNotIn,omitempty"` + UpdatedAtGT *time.Time `json:"updatedAtGT,omitempty"` + UpdatedAtGTE *time.Time `json:"updatedAtGTE,omitempty"` + UpdatedAtLT *time.Time `json:"updatedAtLT,omitempty"` + UpdatedAtLTE *time.Time `json:"updatedAtLTE,omitempty"` + UpdatedAtIsNil bool `json:"updatedAtIsNil,omitempty"` + UpdatedAtNotNil bool `json:"updatedAtNotNil,omitempty"` + + // "title" field predicates. + Title *string `json:"title,omitempty"` + TitleNEQ *string `json:"titleNEQ,omitempty"` + TitleIn []string `json:"titleIn,omitempty"` + TitleNotIn []string `json:"titleNotIn,omitempty"` + TitleGT *string `json:"titleGT,omitempty"` + TitleGTE *string `json:"titleGTE,omitempty"` + TitleLT *string `json:"titleLT,omitempty"` + TitleLTE *string `json:"titleLTE,omitempty"` + TitleContains *string `json:"titleContains,omitempty"` + TitleHasPrefix *string `json:"titleHasPrefix,omitempty"` + TitleHasSuffix *string `json:"titleHasSuffix,omitempty"` + TitleEqualFold *string `json:"titleEqualFold,omitempty"` + TitleContainsFold *string `json:"titleContainsFold,omitempty"` + + // "description" field predicates. + Description *string `json:"description,omitempty"` + DescriptionNEQ *string `json:"descriptionNEQ,omitempty"` + DescriptionIn []string `json:"descriptionIn,omitempty"` + DescriptionNotIn []string `json:"descriptionNotIn,omitempty"` + DescriptionGT *string `json:"descriptionGT,omitempty"` + DescriptionGTE *string `json:"descriptionGTE,omitempty"` + DescriptionLT *string `json:"descriptionLT,omitempty"` + DescriptionLTE *string `json:"descriptionLTE,omitempty"` + DescriptionContains *string `json:"descriptionContains,omitempty"` + DescriptionHasPrefix *string `json:"descriptionHasPrefix,omitempty"` + DescriptionHasSuffix *string `json:"descriptionHasSuffix,omitempty"` + DescriptionIsNil bool `json:"descriptionIsNil,omitempty"` + DescriptionNotNil bool `json:"descriptionNotNil,omitempty"` + DescriptionEqualFold *string `json:"descriptionEqualFold,omitempty"` + DescriptionContainsFold *string `json:"descriptionContainsFold,omitempty"` + + // "posts" edge predicates. + HasPosts *bool `json:"hasPosts,omitempty"` + HasPostsWith []*PostWhereInput `json:"hasPostsWith,omitempty"` +} + +// AddPredicates adds custom predicates to the where input to be used during the filtering phase. +func (i *CategoryWhereInput) AddPredicates(predicates ...predicate.Category) { + i.Predicates = append(i.Predicates, predicates...) +} + +// Filter applies the CategoryWhereInput filter on the CategoryQuery builder. +func (i *CategoryWhereInput) Filter(q *CategoryQuery) (*CategoryQuery, error) { + if i == nil { + return q, nil + } + p, err := i.P() + if err != nil { + if err == ErrEmptyCategoryWhereInput { + return q, nil + } + return nil, err + } + return q.Where(p), nil +} + +// ErrEmptyCategoryWhereInput is returned in case the CategoryWhereInput is empty. +var ErrEmptyCategoryWhereInput = errors.New("ent: empty predicate CategoryWhereInput") + +// P returns a predicate for filtering categories. +// An error is returned if the input is empty or invalid. +func (i *CategoryWhereInput) P() (predicate.Category, error) { + var predicates []predicate.Category + if i.Not != nil { + p, err := i.Not.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'not'", err) + } + predicates = append(predicates, category.Not(p)) + } + switch n := len(i.Or); { + case n == 1: + p, err := i.Or[0].P() + if err != nil { + return nil, fmt.Errorf("%w: field 'or'", err) + } + predicates = append(predicates, p) + case n > 1: + or := make([]predicate.Category, 0, n) + for _, w := range i.Or { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'or'", err) + } + or = append(or, p) + } + predicates = append(predicates, category.Or(or...)) + } + switch n := len(i.And); { + case n == 1: + p, err := i.And[0].P() + if err != nil { + return nil, fmt.Errorf("%w: field 'and'", err) + } + predicates = append(predicates, p) + case n > 1: + and := make([]predicate.Category, 0, n) + for _, w := range i.And { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'and'", err) + } + and = append(and, p) + } + predicates = append(predicates, category.And(and...)) + } + predicates = append(predicates, i.Predicates...) + if i.ID != nil { + predicates = append(predicates, category.IDEQ(*i.ID)) + } + if i.IDNEQ != nil { + predicates = append(predicates, category.IDNEQ(*i.IDNEQ)) + } + if len(i.IDIn) > 0 { + predicates = append(predicates, category.IDIn(i.IDIn...)) + } + if len(i.IDNotIn) > 0 { + predicates = append(predicates, category.IDNotIn(i.IDNotIn...)) + } + if i.IDGT != nil { + predicates = append(predicates, category.IDGT(*i.IDGT)) + } + if i.IDGTE != nil { + predicates = append(predicates, category.IDGTE(*i.IDGTE)) + } + if i.IDLT != nil { + predicates = append(predicates, category.IDLT(*i.IDLT)) + } + if i.IDLTE != nil { + predicates = append(predicates, category.IDLTE(*i.IDLTE)) + } + if i.CreatedAt != nil { + predicates = append(predicates, category.CreatedAtEQ(*i.CreatedAt)) + } + if i.CreatedAtNEQ != nil { + predicates = append(predicates, category.CreatedAtNEQ(*i.CreatedAtNEQ)) + } + if len(i.CreatedAtIn) > 0 { + predicates = append(predicates, category.CreatedAtIn(i.CreatedAtIn...)) + } + if len(i.CreatedAtNotIn) > 0 { + predicates = append(predicates, category.CreatedAtNotIn(i.CreatedAtNotIn...)) + } + if i.CreatedAtGT != nil { + predicates = append(predicates, category.CreatedAtGT(*i.CreatedAtGT)) + } + if i.CreatedAtGTE != nil { + predicates = append(predicates, category.CreatedAtGTE(*i.CreatedAtGTE)) + } + if i.CreatedAtLT != nil { + predicates = append(predicates, category.CreatedAtLT(*i.CreatedAtLT)) + } + if i.CreatedAtLTE != nil { + predicates = append(predicates, category.CreatedAtLTE(*i.CreatedAtLTE)) + } + if i.UpdatedAt != nil { + predicates = append(predicates, category.UpdatedAtEQ(*i.UpdatedAt)) + } + if i.UpdatedAtNEQ != nil { + predicates = append(predicates, category.UpdatedAtNEQ(*i.UpdatedAtNEQ)) + } + if len(i.UpdatedAtIn) > 0 { + predicates = append(predicates, category.UpdatedAtIn(i.UpdatedAtIn...)) + } + if len(i.UpdatedAtNotIn) > 0 { + predicates = append(predicates, category.UpdatedAtNotIn(i.UpdatedAtNotIn...)) + } + if i.UpdatedAtGT != nil { + predicates = append(predicates, category.UpdatedAtGT(*i.UpdatedAtGT)) + } + if i.UpdatedAtGTE != nil { + predicates = append(predicates, category.UpdatedAtGTE(*i.UpdatedAtGTE)) + } + if i.UpdatedAtLT != nil { + predicates = append(predicates, category.UpdatedAtLT(*i.UpdatedAtLT)) + } + if i.UpdatedAtLTE != nil { + predicates = append(predicates, category.UpdatedAtLTE(*i.UpdatedAtLTE)) + } + if i.UpdatedAtIsNil { + predicates = append(predicates, category.UpdatedAtIsNil()) + } + if i.UpdatedAtNotNil { + predicates = append(predicates, category.UpdatedAtNotNil()) + } + if i.Title != nil { + predicates = append(predicates, category.TitleEQ(*i.Title)) + } + if i.TitleNEQ != nil { + predicates = append(predicates, category.TitleNEQ(*i.TitleNEQ)) + } + if len(i.TitleIn) > 0 { + predicates = append(predicates, category.TitleIn(i.TitleIn...)) + } + if len(i.TitleNotIn) > 0 { + predicates = append(predicates, category.TitleNotIn(i.TitleNotIn...)) + } + if i.TitleGT != nil { + predicates = append(predicates, category.TitleGT(*i.TitleGT)) + } + if i.TitleGTE != nil { + predicates = append(predicates, category.TitleGTE(*i.TitleGTE)) + } + if i.TitleLT != nil { + predicates = append(predicates, category.TitleLT(*i.TitleLT)) + } + if i.TitleLTE != nil { + predicates = append(predicates, category.TitleLTE(*i.TitleLTE)) + } + if i.TitleContains != nil { + predicates = append(predicates, category.TitleContains(*i.TitleContains)) + } + if i.TitleHasPrefix != nil { + predicates = append(predicates, category.TitleHasPrefix(*i.TitleHasPrefix)) + } + if i.TitleHasSuffix != nil { + predicates = append(predicates, category.TitleHasSuffix(*i.TitleHasSuffix)) + } + if i.TitleEqualFold != nil { + predicates = append(predicates, category.TitleEqualFold(*i.TitleEqualFold)) + } + if i.TitleContainsFold != nil { + predicates = append(predicates, category.TitleContainsFold(*i.TitleContainsFold)) + } + if i.Description != nil { + predicates = append(predicates, category.DescriptionEQ(*i.Description)) + } + if i.DescriptionNEQ != nil { + predicates = append(predicates, category.DescriptionNEQ(*i.DescriptionNEQ)) + } + if len(i.DescriptionIn) > 0 { + predicates = append(predicates, category.DescriptionIn(i.DescriptionIn...)) + } + if len(i.DescriptionNotIn) > 0 { + predicates = append(predicates, category.DescriptionNotIn(i.DescriptionNotIn...)) + } + if i.DescriptionGT != nil { + predicates = append(predicates, category.DescriptionGT(*i.DescriptionGT)) + } + if i.DescriptionGTE != nil { + predicates = append(predicates, category.DescriptionGTE(*i.DescriptionGTE)) + } + if i.DescriptionLT != nil { + predicates = append(predicates, category.DescriptionLT(*i.DescriptionLT)) + } + if i.DescriptionLTE != nil { + predicates = append(predicates, category.DescriptionLTE(*i.DescriptionLTE)) + } + if i.DescriptionContains != nil { + predicates = append(predicates, category.DescriptionContains(*i.DescriptionContains)) + } + if i.DescriptionHasPrefix != nil { + predicates = append(predicates, category.DescriptionHasPrefix(*i.DescriptionHasPrefix)) + } + if i.DescriptionHasSuffix != nil { + predicates = append(predicates, category.DescriptionHasSuffix(*i.DescriptionHasSuffix)) + } + if i.DescriptionIsNil { + predicates = append(predicates, category.DescriptionIsNil()) + } + if i.DescriptionNotNil { + predicates = append(predicates, category.DescriptionNotNil()) + } + if i.DescriptionEqualFold != nil { + predicates = append(predicates, category.DescriptionEqualFold(*i.DescriptionEqualFold)) + } + if i.DescriptionContainsFold != nil { + predicates = append(predicates, category.DescriptionContainsFold(*i.DescriptionContainsFold)) + } + + if i.HasPosts != nil { + p := category.HasPosts() + if !*i.HasPosts { + p = category.Not(p) + } + predicates = append(predicates, p) + } + if len(i.HasPostsWith) > 0 { + with := make([]predicate.Post, 0, len(i.HasPostsWith)) + for _, w := range i.HasPostsWith { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'HasPostsWith'", err) + } + with = append(with, p) + } + predicates = append(predicates, category.HasPostsWith(with...)) + } + switch len(predicates) { + case 0: + return nil, ErrEmptyCategoryWhereInput + case 1: + return predicates[0], nil + default: + return category.And(predicates...), nil + } +} + +// PostWhereInput represents a where input for filtering Post queries. +type PostWhereInput struct { + Predicates []predicate.Post `json:"-"` + Not *PostWhereInput `json:"not,omitempty"` + Or []*PostWhereInput `json:"or,omitempty"` + And []*PostWhereInput `json:"and,omitempty"` + + // "id" field predicates. + ID *uuid.UUID `json:"id,omitempty"` + IDNEQ *uuid.UUID `json:"idNEQ,omitempty"` + IDIn []uuid.UUID `json:"idIn,omitempty"` + IDNotIn []uuid.UUID `json:"idNotIn,omitempty"` + IDGT *uuid.UUID `json:"idGT,omitempty"` + IDGTE *uuid.UUID `json:"idGTE,omitempty"` + IDLT *uuid.UUID `json:"idLT,omitempty"` + IDLTE *uuid.UUID `json:"idLTE,omitempty"` + + // "created_at" field predicates. + CreatedAt *time.Time `json:"createdAt,omitempty"` + CreatedAtNEQ *time.Time `json:"createdAtNEQ,omitempty"` + CreatedAtIn []time.Time `json:"createdAtIn,omitempty"` + CreatedAtNotIn []time.Time `json:"createdAtNotIn,omitempty"` + CreatedAtGT *time.Time `json:"createdAtGT,omitempty"` + CreatedAtGTE *time.Time `json:"createdAtGTE,omitempty"` + CreatedAtLT *time.Time `json:"createdAtLT,omitempty"` + CreatedAtLTE *time.Time `json:"createdAtLTE,omitempty"` + + // "updated_at" field predicates. + UpdatedAt *time.Time `json:"updatedAt,omitempty"` + UpdatedAtNEQ *time.Time `json:"updatedAtNEQ,omitempty"` + UpdatedAtIn []time.Time `json:"updatedAtIn,omitempty"` + UpdatedAtNotIn []time.Time `json:"updatedAtNotIn,omitempty"` + UpdatedAtGT *time.Time `json:"updatedAtGT,omitempty"` + UpdatedAtGTE *time.Time `json:"updatedAtGTE,omitempty"` + UpdatedAtLT *time.Time `json:"updatedAtLT,omitempty"` + UpdatedAtLTE *time.Time `json:"updatedAtLTE,omitempty"` + UpdatedAtIsNil bool `json:"updatedAtIsNil,omitempty"` + UpdatedAtNotNil bool `json:"updatedAtNotNil,omitempty"` + + // "expires" field predicates. + Expires *bool `json:"expires,omitempty"` + ExpiresNEQ *bool `json:"expiresNEQ,omitempty"` + + // "expire_time" field predicates. + ExpireTime *time.Time `json:"expireTime,omitempty"` + ExpireTimeNEQ *time.Time `json:"expireTimeNEQ,omitempty"` + ExpireTimeIn []time.Time `json:"expireTimeIn,omitempty"` + ExpireTimeNotIn []time.Time `json:"expireTimeNotIn,omitempty"` + ExpireTimeGT *time.Time `json:"expireTimeGT,omitempty"` + ExpireTimeGTE *time.Time `json:"expireTimeGTE,omitempty"` + ExpireTimeLT *time.Time `json:"expireTimeLT,omitempty"` + ExpireTimeLTE *time.Time `json:"expireTimeLTE,omitempty"` + ExpireTimeIsNil bool `json:"expireTimeIsNil,omitempty"` + ExpireTimeNotNil bool `json:"expireTimeNotNil,omitempty"` + + // "title" field predicates. + Title *string `json:"title,omitempty"` + TitleNEQ *string `json:"titleNEQ,omitempty"` + TitleIn []string `json:"titleIn,omitempty"` + TitleNotIn []string `json:"titleNotIn,omitempty"` + TitleGT *string `json:"titleGT,omitempty"` + TitleGTE *string `json:"titleGTE,omitempty"` + TitleLT *string `json:"titleLT,omitempty"` + TitleLTE *string `json:"titleLTE,omitempty"` + TitleContains *string `json:"titleContains,omitempty"` + TitleHasPrefix *string `json:"titleHasPrefix,omitempty"` + TitleHasSuffix *string `json:"titleHasSuffix,omitempty"` + TitleEqualFold *string `json:"titleEqualFold,omitempty"` + TitleContainsFold *string `json:"titleContainsFold,omitempty"` + + // "body" field predicates. + Body *string `json:"body,omitempty"` + BodyNEQ *string `json:"bodyNEQ,omitempty"` + BodyIn []string `json:"bodyIn,omitempty"` + BodyNotIn []string `json:"bodyNotIn,omitempty"` + BodyGT *string `json:"bodyGT,omitempty"` + BodyGTE *string `json:"bodyGTE,omitempty"` + BodyLT *string `json:"bodyLT,omitempty"` + BodyLTE *string `json:"bodyLTE,omitempty"` + BodyContains *string `json:"bodyContains,omitempty"` + BodyHasPrefix *string `json:"bodyHasPrefix,omitempty"` + BodyHasSuffix *string `json:"bodyHasSuffix,omitempty"` + BodyEqualFold *string `json:"bodyEqualFold,omitempty"` + BodyContainsFold *string `json:"bodyContainsFold,omitempty"` + + // "category" edge predicates. + HasCategory *bool `json:"hasCategory,omitempty"` + HasCategoryWith []*CategoryWhereInput `json:"hasCategoryWith,omitempty"` + + // "profile" edge predicates. + HasProfile *bool `json:"hasProfile,omitempty"` + HasProfileWith []*ProfileWhereInput `json:"hasProfileWith,omitempty"` +} + +// AddPredicates adds custom predicates to the where input to be used during the filtering phase. +func (i *PostWhereInput) AddPredicates(predicates ...predicate.Post) { + i.Predicates = append(i.Predicates, predicates...) +} + +// Filter applies the PostWhereInput filter on the PostQuery builder. +func (i *PostWhereInput) Filter(q *PostQuery) (*PostQuery, error) { + if i == nil { + return q, nil + } + p, err := i.P() + if err != nil { + if err == ErrEmptyPostWhereInput { + return q, nil + } + return nil, err + } + return q.Where(p), nil +} + +// ErrEmptyPostWhereInput is returned in case the PostWhereInput is empty. +var ErrEmptyPostWhereInput = errors.New("ent: empty predicate PostWhereInput") + +// P returns a predicate for filtering posts. +// An error is returned if the input is empty or invalid. +func (i *PostWhereInput) P() (predicate.Post, error) { + var predicates []predicate.Post + if i.Not != nil { + p, err := i.Not.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'not'", err) + } + predicates = append(predicates, post.Not(p)) + } + switch n := len(i.Or); { + case n == 1: + p, err := i.Or[0].P() + if err != nil { + return nil, fmt.Errorf("%w: field 'or'", err) + } + predicates = append(predicates, p) + case n > 1: + or := make([]predicate.Post, 0, n) + for _, w := range i.Or { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'or'", err) + } + or = append(or, p) + } + predicates = append(predicates, post.Or(or...)) + } + switch n := len(i.And); { + case n == 1: + p, err := i.And[0].P() + if err != nil { + return nil, fmt.Errorf("%w: field 'and'", err) + } + predicates = append(predicates, p) + case n > 1: + and := make([]predicate.Post, 0, n) + for _, w := range i.And { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'and'", err) + } + and = append(and, p) + } + predicates = append(predicates, post.And(and...)) + } + predicates = append(predicates, i.Predicates...) + if i.ID != nil { + predicates = append(predicates, post.IDEQ(*i.ID)) + } + if i.IDNEQ != nil { + predicates = append(predicates, post.IDNEQ(*i.IDNEQ)) + } + if len(i.IDIn) > 0 { + predicates = append(predicates, post.IDIn(i.IDIn...)) + } + if len(i.IDNotIn) > 0 { + predicates = append(predicates, post.IDNotIn(i.IDNotIn...)) + } + if i.IDGT != nil { + predicates = append(predicates, post.IDGT(*i.IDGT)) + } + if i.IDGTE != nil { + predicates = append(predicates, post.IDGTE(*i.IDGTE)) + } + if i.IDLT != nil { + predicates = append(predicates, post.IDLT(*i.IDLT)) + } + if i.IDLTE != nil { + predicates = append(predicates, post.IDLTE(*i.IDLTE)) + } + if i.CreatedAt != nil { + predicates = append(predicates, post.CreatedAtEQ(*i.CreatedAt)) + } + if i.CreatedAtNEQ != nil { + predicates = append(predicates, post.CreatedAtNEQ(*i.CreatedAtNEQ)) + } + if len(i.CreatedAtIn) > 0 { + predicates = append(predicates, post.CreatedAtIn(i.CreatedAtIn...)) + } + if len(i.CreatedAtNotIn) > 0 { + predicates = append(predicates, post.CreatedAtNotIn(i.CreatedAtNotIn...)) + } + if i.CreatedAtGT != nil { + predicates = append(predicates, post.CreatedAtGT(*i.CreatedAtGT)) + } + if i.CreatedAtGTE != nil { + predicates = append(predicates, post.CreatedAtGTE(*i.CreatedAtGTE)) + } + if i.CreatedAtLT != nil { + predicates = append(predicates, post.CreatedAtLT(*i.CreatedAtLT)) + } + if i.CreatedAtLTE != nil { + predicates = append(predicates, post.CreatedAtLTE(*i.CreatedAtLTE)) + } + if i.UpdatedAt != nil { + predicates = append(predicates, post.UpdatedAtEQ(*i.UpdatedAt)) + } + if i.UpdatedAtNEQ != nil { + predicates = append(predicates, post.UpdatedAtNEQ(*i.UpdatedAtNEQ)) + } + if len(i.UpdatedAtIn) > 0 { + predicates = append(predicates, post.UpdatedAtIn(i.UpdatedAtIn...)) + } + if len(i.UpdatedAtNotIn) > 0 { + predicates = append(predicates, post.UpdatedAtNotIn(i.UpdatedAtNotIn...)) + } + if i.UpdatedAtGT != nil { + predicates = append(predicates, post.UpdatedAtGT(*i.UpdatedAtGT)) + } + if i.UpdatedAtGTE != nil { + predicates = append(predicates, post.UpdatedAtGTE(*i.UpdatedAtGTE)) + } + if i.UpdatedAtLT != nil { + predicates = append(predicates, post.UpdatedAtLT(*i.UpdatedAtLT)) + } + if i.UpdatedAtLTE != nil { + predicates = append(predicates, post.UpdatedAtLTE(*i.UpdatedAtLTE)) + } + if i.UpdatedAtIsNil { + predicates = append(predicates, post.UpdatedAtIsNil()) + } + if i.UpdatedAtNotNil { + predicates = append(predicates, post.UpdatedAtNotNil()) + } + if i.Expires != nil { + predicates = append(predicates, post.ExpiresEQ(*i.Expires)) + } + if i.ExpiresNEQ != nil { + predicates = append(predicates, post.ExpiresNEQ(*i.ExpiresNEQ)) + } + if i.ExpireTime != nil { + predicates = append(predicates, post.ExpireTimeEQ(*i.ExpireTime)) + } + if i.ExpireTimeNEQ != nil { + predicates = append(predicates, post.ExpireTimeNEQ(*i.ExpireTimeNEQ)) + } + if len(i.ExpireTimeIn) > 0 { + predicates = append(predicates, post.ExpireTimeIn(i.ExpireTimeIn...)) + } + if len(i.ExpireTimeNotIn) > 0 { + predicates = append(predicates, post.ExpireTimeNotIn(i.ExpireTimeNotIn...)) + } + if i.ExpireTimeGT != nil { + predicates = append(predicates, post.ExpireTimeGT(*i.ExpireTimeGT)) + } + if i.ExpireTimeGTE != nil { + predicates = append(predicates, post.ExpireTimeGTE(*i.ExpireTimeGTE)) + } + if i.ExpireTimeLT != nil { + predicates = append(predicates, post.ExpireTimeLT(*i.ExpireTimeLT)) + } + if i.ExpireTimeLTE != nil { + predicates = append(predicates, post.ExpireTimeLTE(*i.ExpireTimeLTE)) + } + if i.ExpireTimeIsNil { + predicates = append(predicates, post.ExpireTimeIsNil()) + } + if i.ExpireTimeNotNil { + predicates = append(predicates, post.ExpireTimeNotNil()) + } + if i.Title != nil { + predicates = append(predicates, post.TitleEQ(*i.Title)) + } + if i.TitleNEQ != nil { + predicates = append(predicates, post.TitleNEQ(*i.TitleNEQ)) + } + if len(i.TitleIn) > 0 { + predicates = append(predicates, post.TitleIn(i.TitleIn...)) + } + if len(i.TitleNotIn) > 0 { + predicates = append(predicates, post.TitleNotIn(i.TitleNotIn...)) + } + if i.TitleGT != nil { + predicates = append(predicates, post.TitleGT(*i.TitleGT)) + } + if i.TitleGTE != nil { + predicates = append(predicates, post.TitleGTE(*i.TitleGTE)) + } + if i.TitleLT != nil { + predicates = append(predicates, post.TitleLT(*i.TitleLT)) + } + if i.TitleLTE != nil { + predicates = append(predicates, post.TitleLTE(*i.TitleLTE)) + } + if i.TitleContains != nil { + predicates = append(predicates, post.TitleContains(*i.TitleContains)) + } + if i.TitleHasPrefix != nil { + predicates = append(predicates, post.TitleHasPrefix(*i.TitleHasPrefix)) + } + if i.TitleHasSuffix != nil { + predicates = append(predicates, post.TitleHasSuffix(*i.TitleHasSuffix)) + } + if i.TitleEqualFold != nil { + predicates = append(predicates, post.TitleEqualFold(*i.TitleEqualFold)) + } + if i.TitleContainsFold != nil { + predicates = append(predicates, post.TitleContainsFold(*i.TitleContainsFold)) + } + if i.Body != nil { + predicates = append(predicates, post.BodyEQ(*i.Body)) + } + if i.BodyNEQ != nil { + predicates = append(predicates, post.BodyNEQ(*i.BodyNEQ)) + } + if len(i.BodyIn) > 0 { + predicates = append(predicates, post.BodyIn(i.BodyIn...)) + } + if len(i.BodyNotIn) > 0 { + predicates = append(predicates, post.BodyNotIn(i.BodyNotIn...)) + } + if i.BodyGT != nil { + predicates = append(predicates, post.BodyGT(*i.BodyGT)) + } + if i.BodyGTE != nil { + predicates = append(predicates, post.BodyGTE(*i.BodyGTE)) + } + if i.BodyLT != nil { + predicates = append(predicates, post.BodyLT(*i.BodyLT)) + } + if i.BodyLTE != nil { + predicates = append(predicates, post.BodyLTE(*i.BodyLTE)) + } + if i.BodyContains != nil { + predicates = append(predicates, post.BodyContains(*i.BodyContains)) + } + if i.BodyHasPrefix != nil { + predicates = append(predicates, post.BodyHasPrefix(*i.BodyHasPrefix)) + } + if i.BodyHasSuffix != nil { + predicates = append(predicates, post.BodyHasSuffix(*i.BodyHasSuffix)) + } + if i.BodyEqualFold != nil { + predicates = append(predicates, post.BodyEqualFold(*i.BodyEqualFold)) + } + if i.BodyContainsFold != nil { + predicates = append(predicates, post.BodyContainsFold(*i.BodyContainsFold)) + } + + if i.HasCategory != nil { + p := post.HasCategory() + if !*i.HasCategory { + p = post.Not(p) + } + predicates = append(predicates, p) + } + if len(i.HasCategoryWith) > 0 { + with := make([]predicate.Category, 0, len(i.HasCategoryWith)) + for _, w := range i.HasCategoryWith { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'HasCategoryWith'", err) + } + with = append(with, p) + } + predicates = append(predicates, post.HasCategoryWith(with...)) + } + if i.HasProfile != nil { + p := post.HasProfile() + if !*i.HasProfile { + p = post.Not(p) + } + predicates = append(predicates, p) + } + if len(i.HasProfileWith) > 0 { + with := make([]predicate.Profile, 0, len(i.HasProfileWith)) + for _, w := range i.HasProfileWith { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'HasProfileWith'", err) + } + with = append(with, p) + } + predicates = append(predicates, post.HasProfileWith(with...)) + } + switch len(predicates) { + case 0: + return nil, ErrEmptyPostWhereInput + case 1: + return predicates[0], nil + default: + return post.And(predicates...), nil + } +} + +// ProfileWhereInput represents a where input for filtering Profile queries. +type ProfileWhereInput struct { + Predicates []predicate.Profile `json:"-"` + Not *ProfileWhereInput `json:"not,omitempty"` + Or []*ProfileWhereInput `json:"or,omitempty"` + And []*ProfileWhereInput `json:"and,omitempty"` + + // "id" field predicates. + ID *uuid.UUID `json:"id,omitempty"` + IDNEQ *uuid.UUID `json:"idNEQ,omitempty"` + IDIn []uuid.UUID `json:"idIn,omitempty"` + IDNotIn []uuid.UUID `json:"idNotIn,omitempty"` + IDGT *uuid.UUID `json:"idGT,omitempty"` + IDGTE *uuid.UUID `json:"idGTE,omitempty"` + IDLT *uuid.UUID `json:"idLT,omitempty"` + IDLTE *uuid.UUID `json:"idLTE,omitempty"` + + // "created_at" field predicates. + CreatedAt *time.Time `json:"createdAt,omitempty"` + CreatedAtNEQ *time.Time `json:"createdAtNEQ,omitempty"` + CreatedAtIn []time.Time `json:"createdAtIn,omitempty"` + CreatedAtNotIn []time.Time `json:"createdAtNotIn,omitempty"` + CreatedAtGT *time.Time `json:"createdAtGT,omitempty"` + CreatedAtGTE *time.Time `json:"createdAtGTE,omitempty"` + CreatedAtLT *time.Time `json:"createdAtLT,omitempty"` + CreatedAtLTE *time.Time `json:"createdAtLTE,omitempty"` + + // "updated_at" field predicates. + UpdatedAt *time.Time `json:"updatedAt,omitempty"` + UpdatedAtNEQ *time.Time `json:"updatedAtNEQ,omitempty"` + UpdatedAtIn []time.Time `json:"updatedAtIn,omitempty"` + UpdatedAtNotIn []time.Time `json:"updatedAtNotIn,omitempty"` + UpdatedAtGT *time.Time `json:"updatedAtGT,omitempty"` + UpdatedAtGTE *time.Time `json:"updatedAtGTE,omitempty"` + UpdatedAtLT *time.Time `json:"updatedAtLT,omitempty"` + UpdatedAtLTE *time.Time `json:"updatedAtLTE,omitempty"` + UpdatedAtIsNil bool `json:"updatedAtIsNil,omitempty"` + UpdatedAtNotNil bool `json:"updatedAtNotNil,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"` + + // "address" field predicates. + Address *string `json:"address,omitempty"` + AddressNEQ *string `json:"addressNEQ,omitempty"` + AddressIn []string `json:"addressIn,omitempty"` + AddressNotIn []string `json:"addressNotIn,omitempty"` + AddressGT *string `json:"addressGT,omitempty"` + AddressGTE *string `json:"addressGTE,omitempty"` + AddressLT *string `json:"addressLT,omitempty"` + AddressLTE *string `json:"addressLTE,omitempty"` + AddressContains *string `json:"addressContains,omitempty"` + AddressHasPrefix *string `json:"addressHasPrefix,omitempty"` + AddressHasSuffix *string `json:"addressHasSuffix,omitempty"` + AddressIsNil bool `json:"addressIsNil,omitempty"` + AddressNotNil bool `json:"addressNotNil,omitempty"` + AddressEqualFold *string `json:"addressEqualFold,omitempty"` + AddressContainsFold *string `json:"addressContainsFold,omitempty"` + + // "phone" field predicates. + Phone *string `json:"phone,omitempty"` + PhoneNEQ *string `json:"phoneNEQ,omitempty"` + PhoneIn []string `json:"phoneIn,omitempty"` + PhoneNotIn []string `json:"phoneNotIn,omitempty"` + PhoneGT *string `json:"phoneGT,omitempty"` + PhoneGTE *string `json:"phoneGTE,omitempty"` + PhoneLT *string `json:"phoneLT,omitempty"` + PhoneLTE *string `json:"phoneLTE,omitempty"` + PhoneContains *string `json:"phoneContains,omitempty"` + PhoneHasPrefix *string `json:"phoneHasPrefix,omitempty"` + PhoneHasSuffix *string `json:"phoneHasSuffix,omitempty"` + PhoneIsNil bool `json:"phoneIsNil,omitempty"` + PhoneNotNil bool `json:"phoneNotNil,omitempty"` + PhoneEqualFold *string `json:"phoneEqualFold,omitempty"` + PhoneContainsFold *string `json:"phoneContainsFold,omitempty"` + + // "posts" edge predicates. + HasPosts *bool `json:"hasPosts,omitempty"` + HasPostsWith []*PostWhereInput `json:"hasPostsWith,omitempty"` +} + +// AddPredicates adds custom predicates to the where input to be used during the filtering phase. +func (i *ProfileWhereInput) AddPredicates(predicates ...predicate.Profile) { + i.Predicates = append(i.Predicates, predicates...) +} + +// Filter applies the ProfileWhereInput filter on the ProfileQuery builder. +func (i *ProfileWhereInput) Filter(q *ProfileQuery) (*ProfileQuery, error) { + if i == nil { + return q, nil + } + p, err := i.P() + if err != nil { + if err == ErrEmptyProfileWhereInput { + return q, nil + } + return nil, err + } + return q.Where(p), nil +} + +// ErrEmptyProfileWhereInput is returned in case the ProfileWhereInput is empty. +var ErrEmptyProfileWhereInput = errors.New("ent: empty predicate ProfileWhereInput") + +// P returns a predicate for filtering profiles. +// An error is returned if the input is empty or invalid. +func (i *ProfileWhereInput) P() (predicate.Profile, error) { + var predicates []predicate.Profile + if i.Not != nil { + p, err := i.Not.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'not'", err) + } + predicates = append(predicates, profile.Not(p)) + } + switch n := len(i.Or); { + case n == 1: + p, err := i.Or[0].P() + if err != nil { + return nil, fmt.Errorf("%w: field 'or'", err) + } + predicates = append(predicates, p) + case n > 1: + or := make([]predicate.Profile, 0, n) + for _, w := range i.Or { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'or'", err) + } + or = append(or, p) + } + predicates = append(predicates, profile.Or(or...)) + } + switch n := len(i.And); { + case n == 1: + p, err := i.And[0].P() + if err != nil { + return nil, fmt.Errorf("%w: field 'and'", err) + } + predicates = append(predicates, p) + case n > 1: + and := make([]predicate.Profile, 0, n) + for _, w := range i.And { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'and'", err) + } + and = append(and, p) + } + predicates = append(predicates, profile.And(and...)) + } + predicates = append(predicates, i.Predicates...) + if i.ID != nil { + predicates = append(predicates, profile.IDEQ(*i.ID)) + } + if i.IDNEQ != nil { + predicates = append(predicates, profile.IDNEQ(*i.IDNEQ)) + } + if len(i.IDIn) > 0 { + predicates = append(predicates, profile.IDIn(i.IDIn...)) + } + if len(i.IDNotIn) > 0 { + predicates = append(predicates, profile.IDNotIn(i.IDNotIn...)) + } + if i.IDGT != nil { + predicates = append(predicates, profile.IDGT(*i.IDGT)) + } + if i.IDGTE != nil { + predicates = append(predicates, profile.IDGTE(*i.IDGTE)) + } + if i.IDLT != nil { + predicates = append(predicates, profile.IDLT(*i.IDLT)) + } + if i.IDLTE != nil { + predicates = append(predicates, profile.IDLTE(*i.IDLTE)) + } + if i.CreatedAt != nil { + predicates = append(predicates, profile.CreatedAtEQ(*i.CreatedAt)) + } + if i.CreatedAtNEQ != nil { + predicates = append(predicates, profile.CreatedAtNEQ(*i.CreatedAtNEQ)) + } + if len(i.CreatedAtIn) > 0 { + predicates = append(predicates, profile.CreatedAtIn(i.CreatedAtIn...)) + } + if len(i.CreatedAtNotIn) > 0 { + predicates = append(predicates, profile.CreatedAtNotIn(i.CreatedAtNotIn...)) + } + if i.CreatedAtGT != nil { + predicates = append(predicates, profile.CreatedAtGT(*i.CreatedAtGT)) + } + if i.CreatedAtGTE != nil { + predicates = append(predicates, profile.CreatedAtGTE(*i.CreatedAtGTE)) + } + if i.CreatedAtLT != nil { + predicates = append(predicates, profile.CreatedAtLT(*i.CreatedAtLT)) + } + if i.CreatedAtLTE != nil { + predicates = append(predicates, profile.CreatedAtLTE(*i.CreatedAtLTE)) + } + if i.UpdatedAt != nil { + predicates = append(predicates, profile.UpdatedAtEQ(*i.UpdatedAt)) + } + if i.UpdatedAtNEQ != nil { + predicates = append(predicates, profile.UpdatedAtNEQ(*i.UpdatedAtNEQ)) + } + if len(i.UpdatedAtIn) > 0 { + predicates = append(predicates, profile.UpdatedAtIn(i.UpdatedAtIn...)) + } + if len(i.UpdatedAtNotIn) > 0 { + predicates = append(predicates, profile.UpdatedAtNotIn(i.UpdatedAtNotIn...)) + } + if i.UpdatedAtGT != nil { + predicates = append(predicates, profile.UpdatedAtGT(*i.UpdatedAtGT)) + } + if i.UpdatedAtGTE != nil { + predicates = append(predicates, profile.UpdatedAtGTE(*i.UpdatedAtGTE)) + } + if i.UpdatedAtLT != nil { + predicates = append(predicates, profile.UpdatedAtLT(*i.UpdatedAtLT)) + } + if i.UpdatedAtLTE != nil { + predicates = append(predicates, profile.UpdatedAtLTE(*i.UpdatedAtLTE)) + } + if i.UpdatedAtIsNil { + predicates = append(predicates, profile.UpdatedAtIsNil()) + } + if i.UpdatedAtNotNil { + predicates = append(predicates, profile.UpdatedAtNotNil()) + } + if i.Name != nil { + predicates = append(predicates, profile.NameEQ(*i.Name)) + } + if i.NameNEQ != nil { + predicates = append(predicates, profile.NameNEQ(*i.NameNEQ)) + } + if len(i.NameIn) > 0 { + predicates = append(predicates, profile.NameIn(i.NameIn...)) + } + if len(i.NameNotIn) > 0 { + predicates = append(predicates, profile.NameNotIn(i.NameNotIn...)) + } + if i.NameGT != nil { + predicates = append(predicates, profile.NameGT(*i.NameGT)) + } + if i.NameGTE != nil { + predicates = append(predicates, profile.NameGTE(*i.NameGTE)) + } + if i.NameLT != nil { + predicates = append(predicates, profile.NameLT(*i.NameLT)) + } + if i.NameLTE != nil { + predicates = append(predicates, profile.NameLTE(*i.NameLTE)) + } + if i.NameContains != nil { + predicates = append(predicates, profile.NameContains(*i.NameContains)) + } + if i.NameHasPrefix != nil { + predicates = append(predicates, profile.NameHasPrefix(*i.NameHasPrefix)) + } + if i.NameHasSuffix != nil { + predicates = append(predicates, profile.NameHasSuffix(*i.NameHasSuffix)) + } + if i.NameIsNil { + predicates = append(predicates, profile.NameIsNil()) + } + if i.NameNotNil { + predicates = append(predicates, profile.NameNotNil()) + } + if i.NameEqualFold != nil { + predicates = append(predicates, profile.NameEqualFold(*i.NameEqualFold)) + } + if i.NameContainsFold != nil { + predicates = append(predicates, profile.NameContainsFold(*i.NameContainsFold)) + } + if i.Address != nil { + predicates = append(predicates, profile.AddressEQ(*i.Address)) + } + if i.AddressNEQ != nil { + predicates = append(predicates, profile.AddressNEQ(*i.AddressNEQ)) + } + if len(i.AddressIn) > 0 { + predicates = append(predicates, profile.AddressIn(i.AddressIn...)) + } + if len(i.AddressNotIn) > 0 { + predicates = append(predicates, profile.AddressNotIn(i.AddressNotIn...)) + } + if i.AddressGT != nil { + predicates = append(predicates, profile.AddressGT(*i.AddressGT)) + } + if i.AddressGTE != nil { + predicates = append(predicates, profile.AddressGTE(*i.AddressGTE)) + } + if i.AddressLT != nil { + predicates = append(predicates, profile.AddressLT(*i.AddressLT)) + } + if i.AddressLTE != nil { + predicates = append(predicates, profile.AddressLTE(*i.AddressLTE)) + } + if i.AddressContains != nil { + predicates = append(predicates, profile.AddressContains(*i.AddressContains)) + } + if i.AddressHasPrefix != nil { + predicates = append(predicates, profile.AddressHasPrefix(*i.AddressHasPrefix)) + } + if i.AddressHasSuffix != nil { + predicates = append(predicates, profile.AddressHasSuffix(*i.AddressHasSuffix)) + } + if i.AddressIsNil { + predicates = append(predicates, profile.AddressIsNil()) + } + if i.AddressNotNil { + predicates = append(predicates, profile.AddressNotNil()) + } + if i.AddressEqualFold != nil { + predicates = append(predicates, profile.AddressEqualFold(*i.AddressEqualFold)) + } + if i.AddressContainsFold != nil { + predicates = append(predicates, profile.AddressContainsFold(*i.AddressContainsFold)) + } + if i.Phone != nil { + predicates = append(predicates, profile.PhoneEQ(*i.Phone)) + } + if i.PhoneNEQ != nil { + predicates = append(predicates, profile.PhoneNEQ(*i.PhoneNEQ)) + } + if len(i.PhoneIn) > 0 { + predicates = append(predicates, profile.PhoneIn(i.PhoneIn...)) + } + if len(i.PhoneNotIn) > 0 { + predicates = append(predicates, profile.PhoneNotIn(i.PhoneNotIn...)) + } + if i.PhoneGT != nil { + predicates = append(predicates, profile.PhoneGT(*i.PhoneGT)) + } + if i.PhoneGTE != nil { + predicates = append(predicates, profile.PhoneGTE(*i.PhoneGTE)) + } + if i.PhoneLT != nil { + predicates = append(predicates, profile.PhoneLT(*i.PhoneLT)) + } + if i.PhoneLTE != nil { + predicates = append(predicates, profile.PhoneLTE(*i.PhoneLTE)) + } + if i.PhoneContains != nil { + predicates = append(predicates, profile.PhoneContains(*i.PhoneContains)) + } + if i.PhoneHasPrefix != nil { + predicates = append(predicates, profile.PhoneHasPrefix(*i.PhoneHasPrefix)) + } + if i.PhoneHasSuffix != nil { + predicates = append(predicates, profile.PhoneHasSuffix(*i.PhoneHasSuffix)) + } + if i.PhoneIsNil { + predicates = append(predicates, profile.PhoneIsNil()) + } + if i.PhoneNotNil { + predicates = append(predicates, profile.PhoneNotNil()) + } + if i.PhoneEqualFold != nil { + predicates = append(predicates, profile.PhoneEqualFold(*i.PhoneEqualFold)) + } + if i.PhoneContainsFold != nil { + predicates = append(predicates, profile.PhoneContainsFold(*i.PhoneContainsFold)) + } + + if i.HasPosts != nil { + p := profile.HasPosts() + if !*i.HasPosts { + p = profile.Not(p) + } + predicates = append(predicates, p) + } + if len(i.HasPostsWith) > 0 { + with := make([]predicate.Post, 0, len(i.HasPostsWith)) + for _, w := range i.HasPostsWith { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'HasPostsWith'", err) + } + with = append(with, p) + } + predicates = append(predicates, profile.HasPostsWith(with...)) + } + switch len(predicates) { + case 0: + return nil, ErrEmptyProfileWhereInput + case 1: + return predicates[0], nil + default: + return profile.And(predicates...), nil + } +} diff --git a/ent/hook/hook.go b/ent/hook/hook.go new file mode 100644 index 0000000..441cd5d --- /dev/null +++ b/ent/hook/hook.go @@ -0,0 +1,223 @@ +// Code generated by ent, DO NOT EDIT. + +package hook + +import ( + "context" + "fmt" + + "code.icod.de/dalu/ka/ent" +) + +// The CategoryFunc type is an adapter to allow the use of ordinary +// function as Category mutator. +type CategoryFunc func(context.Context, *ent.CategoryMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f CategoryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.CategoryMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CategoryMutation", m) +} + +// The PostFunc type is an adapter to allow the use of ordinary +// function as Post mutator. +type PostFunc func(context.Context, *ent.PostMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f PostFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.PostMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PostMutation", m) +} + +// The ProfileFunc type is an adapter to allow the use of ordinary +// function as Profile mutator. +type ProfileFunc func(context.Context, *ent.ProfileMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f ProfileFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.ProfileMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ProfileMutation", m) +} + +// Condition is a hook condition function. +type Condition func(context.Context, ent.Mutation) bool + +// And groups conditions with the AND operator. +func And(first, second Condition, rest ...Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + if !first(ctx, m) || !second(ctx, m) { + return false + } + for _, cond := range rest { + if !cond(ctx, m) { + return false + } + } + return true + } +} + +// Or groups conditions with the OR operator. +func Or(first, second Condition, rest ...Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + if first(ctx, m) || second(ctx, m) { + return true + } + for _, cond := range rest { + if cond(ctx, m) { + return true + } + } + return false + } +} + +// Not negates a given condition. +func Not(cond Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + return !cond(ctx, m) + } +} + +// HasOp is a condition testing mutation operation. +func HasOp(op ent.Op) Condition { + return func(_ context.Context, m ent.Mutation) bool { + return m.Op().Is(op) + } +} + +// HasAddedFields is a condition validating `.AddedField` on fields. +func HasAddedFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if _, exists := m.AddedField(field); !exists { + return false + } + for _, field := range fields { + if _, exists := m.AddedField(field); !exists { + return false + } + } + return true + } +} + +// HasClearedFields is a condition validating `.FieldCleared` on fields. +func HasClearedFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if exists := m.FieldCleared(field); !exists { + return false + } + for _, field := range fields { + if exists := m.FieldCleared(field); !exists { + return false + } + } + return true + } +} + +// HasFields is a condition validating `.Field` on fields. +func HasFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if _, exists := m.Field(field); !exists { + return false + } + for _, field := range fields { + if _, exists := m.Field(field); !exists { + return false + } + } + return true + } +} + +// If executes the given hook under condition. +// +// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) +func If(hk ent.Hook, cond Condition) ent.Hook { + return func(next ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if cond(ctx, m) { + return hk(next).Mutate(ctx, m) + } + return next.Mutate(ctx, m) + }) + } +} + +// On executes the given hook only for the given operation. +// +// hook.On(Log, ent.Delete|ent.Create) +func On(hk ent.Hook, op ent.Op) ent.Hook { + return If(hk, HasOp(op)) +} + +// Unless skips the given hook only for the given operation. +// +// hook.Unless(Log, ent.Update|ent.UpdateOne) +func Unless(hk ent.Hook, op ent.Op) ent.Hook { + return If(hk, Not(HasOp(op))) +} + +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + +// Reject returns a hook that rejects all operations that match op. +// +// func (T) Hooks() []ent.Hook { +// return []ent.Hook{ +// Reject(ent.Delete|ent.Update), +// } +// } +func Reject(op ent.Op) ent.Hook { + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) + return On(hk, op) +} + +// Chain acts as a list of hooks and is effectively immutable. +// Once created, it will always hold the same set of hooks in the same order. +type Chain struct { + hooks []ent.Hook +} + +// NewChain creates a new chain of hooks. +func NewChain(hooks ...ent.Hook) Chain { + return Chain{append([]ent.Hook(nil), hooks...)} +} + +// Hook chains the list of hooks and returns the final hook. +func (c Chain) Hook() ent.Hook { + return func(mutator ent.Mutator) ent.Mutator { + for i := len(c.hooks) - 1; i >= 0; i-- { + mutator = c.hooks[i](mutator) + } + return mutator + } +} + +// Append extends a chain, adding the specified hook +// as the last ones in the mutation flow. +func (c Chain) Append(hooks ...ent.Hook) Chain { + newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) + newHooks = append(newHooks, c.hooks...) + newHooks = append(newHooks, hooks...) + return Chain{newHooks} +} + +// Extend extends a chain, adding the specified chain +// as the last ones in the mutation flow. +func (c Chain) Extend(chain Chain) Chain { + return c.Append(chain.hooks...) +} diff --git a/ent/internal/schema.go b/ent/internal/schema.go new file mode 100644 index 0000000..7414872 --- /dev/null +++ b/ent/internal/schema.go @@ -0,0 +1,9 @@ +// Code generated by ent, DO NOT EDIT. + +//go:build tools +// +build tools + +// Package internal holds a loadable version of the latest schema. +package internal + +const Schema = "{\"Schema\":\"code.icod.de/dalu/ka/ent/schema\",\"Package\":\"code.icod.de/dalu/ka/ent\",\"Schemas\":[{\"name\":\"Category\",\"config\":{\"Table\":\"\"},\"edges\":[{\"name\":\"posts\",\"type\":\"Post\",\"annotations\":{\"EntGQL\":{\"OrderField\":\"POSTS_COUNT\",\"RelayConnection\":true}}}],\"fields\":[{\"name\":\"id\",\"type\":{\"Type\":4,\"Ident\":\"uuid.UUID\",\"PkgPath\":\"github.com/google/uuid\",\"PkgName\":\"uuid\",\"Nillable\":false,\"RType\":{\"Name\":\"UUID\",\"Ident\":\"uuid.UUID\",\"Kind\":17,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":{\"ClockSequence\":{\"In\":[],\"Out\":[{\"Name\":\"int\",\"Ident\":\"int\",\"Kind\":2,\"PkgPath\":\"\",\"Methods\":null}]},\"Domain\":{\"In\":[],\"Out\":[{\"Name\":\"Domain\",\"Ident\":\"uuid.Domain\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"ID\":{\"In\":[],\"Out\":[{\"Name\":\"uint32\",\"Ident\":\"uint32\",\"Kind\":10,\"PkgPath\":\"\",\"Methods\":null}]},\"MarshalBinary\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"MarshalText\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"NodeID\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}]},\"Scan\":{\"In\":[{\"Name\":\"\",\"Ident\":\"interface {}\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"String\":{\"In\":[],\"Out\":[{\"Name\":\"string\",\"Ident\":\"string\",\"Kind\":24,\"PkgPath\":\"\",\"Methods\":null}]},\"Time\":{\"In\":[],\"Out\":[{\"Name\":\"Time\",\"Ident\":\"uuid.Time\",\"Kind\":6,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"URN\":{\"In\":[],\"Out\":[{\"Name\":\"string\",\"Ident\":\"string\",\"Kind\":24,\"PkgPath\":\"\",\"Methods\":null}]},\"UnmarshalBinary\":{\"In\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"UnmarshalText\":{\"In\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"Value\":{\"In\":[],\"Out\":[{\"Name\":\"Value\",\"Ident\":\"driver.Value\",\"Kind\":20,\"PkgPath\":\"database/sql/driver\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"Variant\":{\"In\":[],\"Out\":[{\"Name\":\"Variant\",\"Ident\":\"uuid.Variant\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"Version\":{\"In\":[],\"Out\":[{\"Name\":\"Version\",\"Ident\":\"uuid.Version\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]}}}},\"unique\":true,\"default\":true,\"default_kind\":19,\"immutable\":true,\"position\":{\"Index\":0,\"MixedIn\":false,\"MixinIndex\":0}},{\"name\":\"created_at\",\"type\":{\"Type\":2,\"Ident\":\"\",\"PkgPath\":\"time\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"default\":true,\"default_kind\":19,\"immutable\":true,\"position\":{\"Index\":1,\"MixedIn\":false,\"MixinIndex\":0},\"annotations\":{\"EntGQL\":{\"OrderField\":\"CREATED_AT\"}}},{\"name\":\"updated_at\",\"type\":{\"Type\":2,\"Ident\":\"\",\"PkgPath\":\"time\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"optional\":true,\"default\":true,\"default_kind\":19,\"update_default\":true,\"position\":{\"Index\":2,\"MixedIn\":false,\"MixinIndex\":0},\"annotations\":{\"EntGQL\":{\"OrderField\":\"UPDATED_AT\"}}},{\"name\":\"title\",\"type\":{\"Type\":7,\"Ident\":\"\",\"PkgPath\":\"\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"validators\":1,\"position\":{\"Index\":3,\"MixedIn\":false,\"MixinIndex\":0}},{\"name\":\"description\",\"type\":{\"Type\":7,\"Ident\":\"\",\"PkgPath\":\"\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"size\":2147483647,\"optional\":true,\"position\":{\"Index\":4,\"MixedIn\":false,\"MixinIndex\":0}}],\"annotations\":{\"EntGQL\":{\"MutationInputs\":[{\"IsCreate\":true},{}],\"QueryField\":{},\"RelayConnection\":true}}},{\"name\":\"Post\",\"config\":{\"Table\":\"\"},\"edges\":[{\"name\":\"category\",\"type\":\"Category\",\"ref_name\":\"posts\",\"unique\":true,\"inverse\":true},{\"name\":\"profile\",\"type\":\"Profile\",\"ref_name\":\"posts\",\"unique\":true,\"inverse\":true}],\"fields\":[{\"name\":\"id\",\"type\":{\"Type\":4,\"Ident\":\"uuid.UUID\",\"PkgPath\":\"github.com/google/uuid\",\"PkgName\":\"uuid\",\"Nillable\":false,\"RType\":{\"Name\":\"UUID\",\"Ident\":\"uuid.UUID\",\"Kind\":17,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":{\"ClockSequence\":{\"In\":[],\"Out\":[{\"Name\":\"int\",\"Ident\":\"int\",\"Kind\":2,\"PkgPath\":\"\",\"Methods\":null}]},\"Domain\":{\"In\":[],\"Out\":[{\"Name\":\"Domain\",\"Ident\":\"uuid.Domain\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"ID\":{\"In\":[],\"Out\":[{\"Name\":\"uint32\",\"Ident\":\"uint32\",\"Kind\":10,\"PkgPath\":\"\",\"Methods\":null}]},\"MarshalBinary\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"MarshalText\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"NodeID\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}]},\"Scan\":{\"In\":[{\"Name\":\"\",\"Ident\":\"interface {}\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"String\":{\"In\":[],\"Out\":[{\"Name\":\"string\",\"Ident\":\"string\",\"Kind\":24,\"PkgPath\":\"\",\"Methods\":null}]},\"Time\":{\"In\":[],\"Out\":[{\"Name\":\"Time\",\"Ident\":\"uuid.Time\",\"Kind\":6,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"URN\":{\"In\":[],\"Out\":[{\"Name\":\"string\",\"Ident\":\"string\",\"Kind\":24,\"PkgPath\":\"\",\"Methods\":null}]},\"UnmarshalBinary\":{\"In\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"UnmarshalText\":{\"In\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"Value\":{\"In\":[],\"Out\":[{\"Name\":\"Value\",\"Ident\":\"driver.Value\",\"Kind\":20,\"PkgPath\":\"database/sql/driver\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"Variant\":{\"In\":[],\"Out\":[{\"Name\":\"Variant\",\"Ident\":\"uuid.Variant\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"Version\":{\"In\":[],\"Out\":[{\"Name\":\"Version\",\"Ident\":\"uuid.Version\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]}}}},\"unique\":true,\"default\":true,\"default_kind\":19,\"immutable\":true,\"position\":{\"Index\":0,\"MixedIn\":false,\"MixinIndex\":0}},{\"name\":\"created_at\",\"type\":{\"Type\":2,\"Ident\":\"\",\"PkgPath\":\"time\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"default\":true,\"default_kind\":19,\"immutable\":true,\"position\":{\"Index\":1,\"MixedIn\":false,\"MixinIndex\":0},\"annotations\":{\"EntGQL\":{\"OrderField\":\"CREATED_AT\"}}},{\"name\":\"updated_at\",\"type\":{\"Type\":2,\"Ident\":\"\",\"PkgPath\":\"time\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"optional\":true,\"default\":true,\"default_kind\":19,\"update_default\":true,\"position\":{\"Index\":2,\"MixedIn\":false,\"MixinIndex\":0},\"annotations\":{\"EntGQL\":{\"OrderField\":\"UPDATED_AT\"}}},{\"name\":\"expires\",\"type\":{\"Type\":1,\"Ident\":\"\",\"PkgPath\":\"\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"default\":true,\"default_value\":false,\"default_kind\":1,\"position\":{\"Index\":3,\"MixedIn\":false,\"MixinIndex\":0}},{\"name\":\"expire_time\",\"type\":{\"Type\":2,\"Ident\":\"\",\"PkgPath\":\"time\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"nillable\":true,\"optional\":true,\"position\":{\"Index\":4,\"MixedIn\":false,\"MixinIndex\":0},\"annotations\":{\"EntGQL\":{\"OrderField\":\"EXPIRE_TIME\"}}},{\"name\":\"title\",\"type\":{\"Type\":7,\"Ident\":\"\",\"PkgPath\":\"\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"validators\":1,\"position\":{\"Index\":5,\"MixedIn\":false,\"MixinIndex\":0}},{\"name\":\"body\",\"type\":{\"Type\":7,\"Ident\":\"\",\"PkgPath\":\"\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"size\":2147483647,\"validators\":1,\"position\":{\"Index\":6,\"MixedIn\":false,\"MixinIndex\":0}}],\"annotations\":{\"EntGQL\":{\"MutationInputs\":[{\"IsCreate\":true},{}],\"QueryField\":{},\"RelayConnection\":true}}},{\"name\":\"Profile\",\"config\":{\"Table\":\"\"},\"edges\":[{\"name\":\"posts\",\"type\":\"Post\",\"annotations\":{\"EntGQL\":{\"OrderField\":\"POSTS_COUNT\",\"RelayConnection\":true}}}],\"fields\":[{\"name\":\"id\",\"type\":{\"Type\":4,\"Ident\":\"uuid.UUID\",\"PkgPath\":\"github.com/google/uuid\",\"PkgName\":\"uuid\",\"Nillable\":false,\"RType\":{\"Name\":\"UUID\",\"Ident\":\"uuid.UUID\",\"Kind\":17,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":{\"ClockSequence\":{\"In\":[],\"Out\":[{\"Name\":\"int\",\"Ident\":\"int\",\"Kind\":2,\"PkgPath\":\"\",\"Methods\":null}]},\"Domain\":{\"In\":[],\"Out\":[{\"Name\":\"Domain\",\"Ident\":\"uuid.Domain\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"ID\":{\"In\":[],\"Out\":[{\"Name\":\"uint32\",\"Ident\":\"uint32\",\"Kind\":10,\"PkgPath\":\"\",\"Methods\":null}]},\"MarshalBinary\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"MarshalText\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"NodeID\":{\"In\":[],\"Out\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}]},\"Scan\":{\"In\":[{\"Name\":\"\",\"Ident\":\"interface {}\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"String\":{\"In\":[],\"Out\":[{\"Name\":\"string\",\"Ident\":\"string\",\"Kind\":24,\"PkgPath\":\"\",\"Methods\":null}]},\"Time\":{\"In\":[],\"Out\":[{\"Name\":\"Time\",\"Ident\":\"uuid.Time\",\"Kind\":6,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"URN\":{\"In\":[],\"Out\":[{\"Name\":\"string\",\"Ident\":\"string\",\"Kind\":24,\"PkgPath\":\"\",\"Methods\":null}]},\"UnmarshalBinary\":{\"In\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"UnmarshalText\":{\"In\":[{\"Name\":\"\",\"Ident\":\"[]uint8\",\"Kind\":23,\"PkgPath\":\"\",\"Methods\":null}],\"Out\":[{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"Value\":{\"In\":[],\"Out\":[{\"Name\":\"Value\",\"Ident\":\"driver.Value\",\"Kind\":20,\"PkgPath\":\"database/sql/driver\",\"Methods\":null},{\"Name\":\"error\",\"Ident\":\"error\",\"Kind\":20,\"PkgPath\":\"\",\"Methods\":null}]},\"Variant\":{\"In\":[],\"Out\":[{\"Name\":\"Variant\",\"Ident\":\"uuid.Variant\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]},\"Version\":{\"In\":[],\"Out\":[{\"Name\":\"Version\",\"Ident\":\"uuid.Version\",\"Kind\":8,\"PkgPath\":\"github.com/google/uuid\",\"Methods\":null}]}}}},\"unique\":true,\"default\":true,\"default_kind\":19,\"immutable\":true,\"position\":{\"Index\":0,\"MixedIn\":false,\"MixinIndex\":0}},{\"name\":\"created_at\",\"type\":{\"Type\":2,\"Ident\":\"\",\"PkgPath\":\"time\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"default\":true,\"default_kind\":19,\"immutable\":true,\"position\":{\"Index\":1,\"MixedIn\":false,\"MixinIndex\":0},\"annotations\":{\"EntGQL\":{\"OrderField\":\"CREATED_AT\"}}},{\"name\":\"updated_at\",\"type\":{\"Type\":2,\"Ident\":\"\",\"PkgPath\":\"time\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"optional\":true,\"default\":true,\"default_kind\":19,\"update_default\":true,\"position\":{\"Index\":2,\"MixedIn\":false,\"MixinIndex\":0},\"annotations\":{\"EntGQL\":{\"OrderField\":\"UPDATED_AT\"}}},{\"name\":\"name\",\"type\":{\"Type\":7,\"Ident\":\"\",\"PkgPath\":\"\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"optional\":true,\"position\":{\"Index\":3,\"MixedIn\":false,\"MixinIndex\":0}},{\"name\":\"address\",\"type\":{\"Type\":7,\"Ident\":\"\",\"PkgPath\":\"\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"size\":2147483647,\"optional\":true,\"position\":{\"Index\":4,\"MixedIn\":false,\"MixinIndex\":0}},{\"name\":\"phone\",\"type\":{\"Type\":7,\"Ident\":\"\",\"PkgPath\":\"\",\"PkgName\":\"\",\"Nillable\":false,\"RType\":null},\"optional\":true,\"position\":{\"Index\":5,\"MixedIn\":false,\"MixinIndex\":0}}],\"annotations\":{\"EntGQL\":{\"MutationInputs\":[{\"IsCreate\":true},{}],\"QueryField\":{},\"RelayConnection\":true}}}],\"Features\":[\"namedges\",\"privacy\",\"schema/snapshot\",\"entql\"]}" diff --git a/ent/migrate/migrate.go b/ent/migrate/migrate.go new file mode 100644 index 0000000..1956a6b --- /dev/null +++ b/ent/migrate/migrate.go @@ -0,0 +1,64 @@ +// Code generated by ent, DO NOT EDIT. + +package migrate + +import ( + "context" + "fmt" + "io" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql/schema" +) + +var ( + // WithGlobalUniqueID sets the universal ids options to the migration. + // If this option is enabled, ent migration will allocate a 1<<32 range + // for the ids of each entity (table). + // Note that this option cannot be applied on tables that already exist. + WithGlobalUniqueID = schema.WithGlobalUniqueID + // WithDropColumn sets the drop column option to the migration. + // If this option is enabled, ent migration will drop old columns + // that were used for both fields and edges. This defaults to false. + WithDropColumn = schema.WithDropColumn + // WithDropIndex sets the drop index option to the migration. + // If this option is enabled, ent migration will drop old indexes + // that were defined in the schema. This defaults to false. + // Note that unique constraints are defined using `UNIQUE INDEX`, + // and therefore, it's recommended to enable this option to get more + // flexibility in the schema changes. + WithDropIndex = schema.WithDropIndex + // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. + WithForeignKeys = schema.WithForeignKeys +) + +// Schema is the API for creating, migrating and dropping a schema. +type Schema struct { + drv dialect.Driver +} + +// NewSchema creates a new schema client. +func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } + +// Create creates all schema resources. +func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { + return Create(ctx, s, Tables, opts...) +} + +// Create creates all table resources using the given schema driver. +func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error { + migrate, err := schema.NewMigrate(s.drv, opts...) + if err != nil { + return fmt.Errorf("ent/migrate: %w", err) + } + return migrate.Create(ctx, tables...) +} + +// WriteTo writes the schema changes to w instead of running them against the database. +// +// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { +// log.Fatal(err) +// } +func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { + return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...) +} diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go new file mode 100644 index 0000000..5adf726 --- /dev/null +++ b/ent/migrate/schema.go @@ -0,0 +1,83 @@ +// Code generated by ent, DO NOT EDIT. + +package migrate + +import ( + "entgo.io/ent/dialect/sql/schema" + "entgo.io/ent/schema/field" +) + +var ( + // CategoriesColumns holds the columns for the "categories" table. + CategoriesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime, Nullable: true}, + {Name: "title", Type: field.TypeString}, + {Name: "description", Type: field.TypeString, Nullable: true, Size: 2147483647}, + } + // CategoriesTable holds the schema information for the "categories" table. + CategoriesTable = &schema.Table{ + Name: "categories", + Columns: CategoriesColumns, + PrimaryKey: []*schema.Column{CategoriesColumns[0]}, + } + // PostsColumns holds the columns for the "posts" table. + PostsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime, Nullable: true}, + {Name: "expires", Type: field.TypeBool, Default: false}, + {Name: "expire_time", Type: field.TypeTime, Nullable: true}, + {Name: "title", Type: field.TypeString}, + {Name: "body", Type: field.TypeString, Size: 2147483647}, + {Name: "category_posts", Type: field.TypeUUID, Nullable: true}, + {Name: "profile_posts", Type: field.TypeUUID, Nullable: true}, + } + // PostsTable holds the schema information for the "posts" table. + PostsTable = &schema.Table{ + Name: "posts", + Columns: PostsColumns, + PrimaryKey: []*schema.Column{PostsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "posts_categories_posts", + Columns: []*schema.Column{PostsColumns[7]}, + RefColumns: []*schema.Column{CategoriesColumns[0]}, + OnDelete: schema.SetNull, + }, + { + Symbol: "posts_profiles_posts", + Columns: []*schema.Column{PostsColumns[8]}, + RefColumns: []*schema.Column{ProfilesColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } + // ProfilesColumns holds the columns for the "profiles" table. + ProfilesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime, Nullable: true}, + {Name: "name", Type: field.TypeString, Nullable: true}, + {Name: "address", Type: field.TypeString, Nullable: true, Size: 2147483647}, + {Name: "phone", Type: field.TypeString, Nullable: true}, + } + // ProfilesTable holds the schema information for the "profiles" table. + ProfilesTable = &schema.Table{ + Name: "profiles", + Columns: ProfilesColumns, + PrimaryKey: []*schema.Column{ProfilesColumns[0]}, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + CategoriesTable, + PostsTable, + ProfilesTable, + } +) + +func init() { + PostsTable.ForeignKeys[0].RefTable = CategoriesTable + PostsTable.ForeignKeys[1].RefTable = ProfilesTable +} diff --git a/ent/mutation.go b/ent/mutation.go new file mode 100644 index 0000000..bf25bab --- /dev/null +++ b/ent/mutation.go @@ -0,0 +1,2150 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "sync" + "time" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" +) + +const ( + // Operation types. + OpCreate = ent.OpCreate + OpDelete = ent.OpDelete + OpDeleteOne = ent.OpDeleteOne + OpUpdate = ent.OpUpdate + OpUpdateOne = ent.OpUpdateOne + + // Node types. + TypeCategory = "Category" + TypePost = "Post" + TypeProfile = "Profile" +) + +// CategoryMutation represents an operation that mutates the Category nodes in the graph. +type CategoryMutation struct { + config + op Op + typ string + id *uuid.UUID + created_at *time.Time + updated_at *time.Time + title *string + description *string + clearedFields map[string]struct{} + posts map[uuid.UUID]struct{} + removedposts map[uuid.UUID]struct{} + clearedposts bool + done bool + oldValue func(context.Context) (*Category, error) + predicates []predicate.Category +} + +var _ ent.Mutation = (*CategoryMutation)(nil) + +// categoryOption allows management of the mutation configuration using functional options. +type categoryOption func(*CategoryMutation) + +// newCategoryMutation creates new mutation for the Category entity. +func newCategoryMutation(c config, op Op, opts ...categoryOption) *CategoryMutation { + m := &CategoryMutation{ + config: c, + op: op, + typ: TypeCategory, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withCategoryID sets the ID field of the mutation. +func withCategoryID(id uuid.UUID) categoryOption { + return func(m *CategoryMutation) { + var ( + err error + once sync.Once + value *Category + ) + m.oldValue = func(ctx context.Context) (*Category, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Category.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withCategory sets the old Category of the mutation. +func withCategory(node *Category) categoryOption { + return func(m *CategoryMutation) { + m.oldValue = func(context.Context) (*Category, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m CategoryMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m CategoryMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Category entities. +func (m *CategoryMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *CategoryMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *CategoryMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Category.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCreatedAt sets the "created_at" field. +func (m *CategoryMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *CategoryMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Category entity. +// If the Category 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 *CategoryMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *CategoryMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *CategoryMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *CategoryMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Category entity. +// If the Category 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 *CategoryMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (m *CategoryMutation) ClearUpdatedAt() { + m.updated_at = nil + m.clearedFields[category.FieldUpdatedAt] = struct{}{} +} + +// UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. +func (m *CategoryMutation) UpdatedAtCleared() bool { + _, ok := m.clearedFields[category.FieldUpdatedAt] + return ok +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *CategoryMutation) ResetUpdatedAt() { + m.updated_at = nil + delete(m.clearedFields, category.FieldUpdatedAt) +} + +// SetTitle sets the "title" field. +func (m *CategoryMutation) SetTitle(s string) { + m.title = &s +} + +// Title returns the value of the "title" field in the mutation. +func (m *CategoryMutation) Title() (r string, exists bool) { + v := m.title + if v == nil { + return + } + return *v, true +} + +// OldTitle returns the old "title" field's value of the Category entity. +// If the Category 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 *CategoryMutation) OldTitle(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTitle is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTitle requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTitle: %w", err) + } + return oldValue.Title, nil +} + +// ResetTitle resets all changes to the "title" field. +func (m *CategoryMutation) ResetTitle() { + m.title = nil +} + +// SetDescription sets the "description" field. +func (m *CategoryMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *CategoryMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the Category entity. +// If the Category 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 *CategoryMutation) OldDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *CategoryMutation) ClearDescription() { + m.description = nil + m.clearedFields[category.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *CategoryMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[category.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *CategoryMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, category.FieldDescription) +} + +// AddPostIDs adds the "posts" edge to the Post entity by ids. +func (m *CategoryMutation) AddPostIDs(ids ...uuid.UUID) { + if m.posts == nil { + m.posts = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.posts[ids[i]] = struct{}{} + } +} + +// ClearPosts clears the "posts" edge to the Post entity. +func (m *CategoryMutation) ClearPosts() { + m.clearedposts = true +} + +// PostsCleared reports if the "posts" edge to the Post entity was cleared. +func (m *CategoryMutation) PostsCleared() bool { + return m.clearedposts +} + +// RemovePostIDs removes the "posts" edge to the Post entity by IDs. +func (m *CategoryMutation) RemovePostIDs(ids ...uuid.UUID) { + if m.removedposts == nil { + m.removedposts = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.posts, ids[i]) + m.removedposts[ids[i]] = struct{}{} + } +} + +// RemovedPosts returns the removed IDs of the "posts" edge to the Post entity. +func (m *CategoryMutation) RemovedPostsIDs() (ids []uuid.UUID) { + for id := range m.removedposts { + ids = append(ids, id) + } + return +} + +// PostsIDs returns the "posts" edge IDs in the mutation. +func (m *CategoryMutation) PostsIDs() (ids []uuid.UUID) { + for id := range m.posts { + ids = append(ids, id) + } + return +} + +// ResetPosts resets all changes to the "posts" edge. +func (m *CategoryMutation) ResetPosts() { + m.posts = nil + m.clearedposts = false + m.removedposts = nil +} + +// Where appends a list predicates to the CategoryMutation builder. +func (m *CategoryMutation) Where(ps ...predicate.Category) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the CategoryMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *CategoryMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Category, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *CategoryMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *CategoryMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Category). +func (m *CategoryMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *CategoryMutation) Fields() []string { + fields := make([]string, 0, 4) + if m.created_at != nil { + fields = append(fields, category.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, category.FieldUpdatedAt) + } + if m.title != nil { + fields = append(fields, category.FieldTitle) + } + if m.description != nil { + fields = append(fields, category.FieldDescription) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *CategoryMutation) Field(name string) (ent.Value, bool) { + switch name { + case category.FieldCreatedAt: + return m.CreatedAt() + case category.FieldUpdatedAt: + return m.UpdatedAt() + case category.FieldTitle: + return m.Title() + case category.FieldDescription: + return m.Description() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *CategoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case category.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case category.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case category.FieldTitle: + return m.OldTitle(ctx) + case category.FieldDescription: + return m.OldDescription(ctx) + } + return nil, fmt.Errorf("unknown Category field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *CategoryMutation) SetField(name string, value ent.Value) error { + switch name { + case category.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case category.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case category.FieldTitle: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTitle(v) + return nil + case category.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + } + return fmt.Errorf("unknown Category field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *CategoryMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *CategoryMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *CategoryMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Category numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *CategoryMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(category.FieldUpdatedAt) { + fields = append(fields, category.FieldUpdatedAt) + } + if m.FieldCleared(category.FieldDescription) { + fields = append(fields, category.FieldDescription) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *CategoryMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *CategoryMutation) ClearField(name string) error { + switch name { + case category.FieldUpdatedAt: + m.ClearUpdatedAt() + return nil + case category.FieldDescription: + m.ClearDescription() + return nil + } + return fmt.Errorf("unknown Category nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *CategoryMutation) ResetField(name string) error { + switch name { + case category.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case category.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case category.FieldTitle: + m.ResetTitle() + return nil + case category.FieldDescription: + m.ResetDescription() + return nil + } + return fmt.Errorf("unknown Category field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *CategoryMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.posts != nil { + edges = append(edges, category.EdgePosts) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *CategoryMutation) AddedIDs(name string) []ent.Value { + switch name { + case category.EdgePosts: + ids := make([]ent.Value, 0, len(m.posts)) + for id := range m.posts { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *CategoryMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + if m.removedposts != nil { + edges = append(edges, category.EdgePosts) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *CategoryMutation) RemovedIDs(name string) []ent.Value { + switch name { + case category.EdgePosts: + ids := make([]ent.Value, 0, len(m.removedposts)) + for id := range m.removedposts { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *CategoryMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedposts { + edges = append(edges, category.EdgePosts) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *CategoryMutation) EdgeCleared(name string) bool { + switch name { + case category.EdgePosts: + return m.clearedposts + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *CategoryMutation) ClearEdge(name string) error { + switch name { + } + return fmt.Errorf("unknown Category unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *CategoryMutation) ResetEdge(name string) error { + switch name { + case category.EdgePosts: + m.ResetPosts() + return nil + } + return fmt.Errorf("unknown Category edge %s", name) +} + +// PostMutation represents an operation that mutates the Post nodes in the graph. +type PostMutation struct { + config + op Op + typ string + id *uuid.UUID + created_at *time.Time + updated_at *time.Time + expires *bool + expire_time *time.Time + title *string + body *string + clearedFields map[string]struct{} + category *uuid.UUID + clearedcategory bool + profile *uuid.UUID + clearedprofile bool + done bool + oldValue func(context.Context) (*Post, error) + predicates []predicate.Post +} + +var _ ent.Mutation = (*PostMutation)(nil) + +// postOption allows management of the mutation configuration using functional options. +type postOption func(*PostMutation) + +// newPostMutation creates new mutation for the Post entity. +func newPostMutation(c config, op Op, opts ...postOption) *PostMutation { + m := &PostMutation{ + config: c, + op: op, + typ: TypePost, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withPostID sets the ID field of the mutation. +func withPostID(id uuid.UUID) postOption { + return func(m *PostMutation) { + var ( + err error + once sync.Once + value *Post + ) + m.oldValue = func(ctx context.Context) (*Post, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Post.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withPost sets the old Post of the mutation. +func withPost(node *Post) postOption { + return func(m *PostMutation) { + m.oldValue = func(context.Context) (*Post, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m PostMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m PostMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Post entities. +func (m *PostMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *PostMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *PostMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Post.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCreatedAt sets the "created_at" field. +func (m *PostMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *PostMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Post entity. +// If the Post 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 *PostMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *PostMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *PostMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *PostMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Post entity. +// If the Post 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 *PostMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (m *PostMutation) ClearUpdatedAt() { + m.updated_at = nil + m.clearedFields[post.FieldUpdatedAt] = struct{}{} +} + +// UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. +func (m *PostMutation) UpdatedAtCleared() bool { + _, ok := m.clearedFields[post.FieldUpdatedAt] + return ok +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *PostMutation) ResetUpdatedAt() { + m.updated_at = nil + delete(m.clearedFields, post.FieldUpdatedAt) +} + +// SetExpires sets the "expires" field. +func (m *PostMutation) SetExpires(b bool) { + m.expires = &b +} + +// Expires returns the value of the "expires" field in the mutation. +func (m *PostMutation) Expires() (r bool, exists bool) { + v := m.expires + if v == nil { + return + } + return *v, true +} + +// OldExpires returns the old "expires" field's value of the Post entity. +// If the Post 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 *PostMutation) OldExpires(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldExpires is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldExpires requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldExpires: %w", err) + } + return oldValue.Expires, nil +} + +// ResetExpires resets all changes to the "expires" field. +func (m *PostMutation) ResetExpires() { + m.expires = nil +} + +// SetExpireTime sets the "expire_time" field. +func (m *PostMutation) SetExpireTime(t time.Time) { + m.expire_time = &t +} + +// ExpireTime returns the value of the "expire_time" field in the mutation. +func (m *PostMutation) ExpireTime() (r time.Time, exists bool) { + v := m.expire_time + if v == nil { + return + } + return *v, true +} + +// OldExpireTime returns the old "expire_time" field's value of the Post entity. +// If the Post 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 *PostMutation) OldExpireTime(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldExpireTime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldExpireTime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldExpireTime: %w", err) + } + return oldValue.ExpireTime, nil +} + +// ClearExpireTime clears the value of the "expire_time" field. +func (m *PostMutation) ClearExpireTime() { + m.expire_time = nil + m.clearedFields[post.FieldExpireTime] = struct{}{} +} + +// ExpireTimeCleared returns if the "expire_time" field was cleared in this mutation. +func (m *PostMutation) ExpireTimeCleared() bool { + _, ok := m.clearedFields[post.FieldExpireTime] + return ok +} + +// ResetExpireTime resets all changes to the "expire_time" field. +func (m *PostMutation) ResetExpireTime() { + m.expire_time = nil + delete(m.clearedFields, post.FieldExpireTime) +} + +// SetTitle sets the "title" field. +func (m *PostMutation) SetTitle(s string) { + m.title = &s +} + +// Title returns the value of the "title" field in the mutation. +func (m *PostMutation) Title() (r string, exists bool) { + v := m.title + if v == nil { + return + } + return *v, true +} + +// OldTitle returns the old "title" field's value of the Post entity. +// If the Post 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 *PostMutation) OldTitle(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTitle is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTitle requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTitle: %w", err) + } + return oldValue.Title, nil +} + +// ResetTitle resets all changes to the "title" field. +func (m *PostMutation) ResetTitle() { + m.title = nil +} + +// SetBody sets the "body" field. +func (m *PostMutation) SetBody(s string) { + m.body = &s +} + +// Body returns the value of the "body" field in the mutation. +func (m *PostMutation) Body() (r string, exists bool) { + v := m.body + if v == nil { + return + } + return *v, true +} + +// OldBody returns the old "body" field's value of the Post entity. +// If the Post 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 *PostMutation) OldBody(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBody is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBody requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBody: %w", err) + } + return oldValue.Body, nil +} + +// ResetBody resets all changes to the "body" field. +func (m *PostMutation) ResetBody() { + m.body = nil +} + +// SetCategoryID sets the "category" edge to the Category entity by id. +func (m *PostMutation) SetCategoryID(id uuid.UUID) { + m.category = &id +} + +// ClearCategory clears the "category" edge to the Category entity. +func (m *PostMutation) ClearCategory() { + m.clearedcategory = true +} + +// CategoryCleared reports if the "category" edge to the Category entity was cleared. +func (m *PostMutation) CategoryCleared() bool { + return m.clearedcategory +} + +// CategoryID returns the "category" edge ID in the mutation. +func (m *PostMutation) CategoryID() (id uuid.UUID, exists bool) { + if m.category != nil { + return *m.category, true + } + return +} + +// CategoryIDs returns the "category" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CategoryID instead. It exists only for internal usage by the builders. +func (m *PostMutation) CategoryIDs() (ids []uuid.UUID) { + if id := m.category; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCategory resets all changes to the "category" edge. +func (m *PostMutation) ResetCategory() { + m.category = nil + m.clearedcategory = false +} + +// SetProfileID sets the "profile" edge to the Profile entity by id. +func (m *PostMutation) SetProfileID(id uuid.UUID) { + m.profile = &id +} + +// ClearProfile clears the "profile" edge to the Profile entity. +func (m *PostMutation) ClearProfile() { + m.clearedprofile = true +} + +// ProfileCleared reports if the "profile" edge to the Profile entity was cleared. +func (m *PostMutation) ProfileCleared() bool { + return m.clearedprofile +} + +// ProfileID returns the "profile" edge ID in the mutation. +func (m *PostMutation) ProfileID() (id uuid.UUID, exists bool) { + if m.profile != nil { + return *m.profile, true + } + return +} + +// ProfileIDs returns the "profile" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ProfileID instead. It exists only for internal usage by the builders. +func (m *PostMutation) ProfileIDs() (ids []uuid.UUID) { + if id := m.profile; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetProfile resets all changes to the "profile" edge. +func (m *PostMutation) ResetProfile() { + m.profile = nil + m.clearedprofile = false +} + +// Where appends a list predicates to the PostMutation builder. +func (m *PostMutation) Where(ps ...predicate.Post) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the PostMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *PostMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Post, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *PostMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *PostMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Post). +func (m *PostMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *PostMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.created_at != nil { + fields = append(fields, post.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, post.FieldUpdatedAt) + } + if m.expires != nil { + fields = append(fields, post.FieldExpires) + } + if m.expire_time != nil { + fields = append(fields, post.FieldExpireTime) + } + if m.title != nil { + fields = append(fields, post.FieldTitle) + } + if m.body != nil { + fields = append(fields, post.FieldBody) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *PostMutation) Field(name string) (ent.Value, bool) { + switch name { + case post.FieldCreatedAt: + return m.CreatedAt() + case post.FieldUpdatedAt: + return m.UpdatedAt() + case post.FieldExpires: + return m.Expires() + case post.FieldExpireTime: + return m.ExpireTime() + case post.FieldTitle: + return m.Title() + case post.FieldBody: + return m.Body() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *PostMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case post.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case post.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case post.FieldExpires: + return m.OldExpires(ctx) + case post.FieldExpireTime: + return m.OldExpireTime(ctx) + case post.FieldTitle: + return m.OldTitle(ctx) + case post.FieldBody: + return m.OldBody(ctx) + } + return nil, fmt.Errorf("unknown Post field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *PostMutation) SetField(name string, value ent.Value) error { + switch name { + case post.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case post.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case post.FieldExpires: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetExpires(v) + return nil + case post.FieldExpireTime: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetExpireTime(v) + return nil + case post.FieldTitle: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTitle(v) + return nil + case post.FieldBody: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBody(v) + return nil + } + return fmt.Errorf("unknown Post field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *PostMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *PostMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *PostMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Post numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *PostMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(post.FieldUpdatedAt) { + fields = append(fields, post.FieldUpdatedAt) + } + if m.FieldCleared(post.FieldExpireTime) { + fields = append(fields, post.FieldExpireTime) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *PostMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *PostMutation) ClearField(name string) error { + switch name { + case post.FieldUpdatedAt: + m.ClearUpdatedAt() + return nil + case post.FieldExpireTime: + m.ClearExpireTime() + return nil + } + return fmt.Errorf("unknown Post nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *PostMutation) ResetField(name string) error { + switch name { + case post.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case post.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case post.FieldExpires: + m.ResetExpires() + return nil + case post.FieldExpireTime: + m.ResetExpireTime() + return nil + case post.FieldTitle: + m.ResetTitle() + return nil + case post.FieldBody: + m.ResetBody() + return nil + } + return fmt.Errorf("unknown Post field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *PostMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.category != nil { + edges = append(edges, post.EdgeCategory) + } + if m.profile != nil { + edges = append(edges, post.EdgeProfile) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *PostMutation) AddedIDs(name string) []ent.Value { + switch name { + case post.EdgeCategory: + if id := m.category; id != nil { + return []ent.Value{*id} + } + case post.EdgeProfile: + if id := m.profile; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *PostMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *PostMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *PostMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedcategory { + edges = append(edges, post.EdgeCategory) + } + if m.clearedprofile { + edges = append(edges, post.EdgeProfile) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *PostMutation) EdgeCleared(name string) bool { + switch name { + case post.EdgeCategory: + return m.clearedcategory + case post.EdgeProfile: + return m.clearedprofile + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *PostMutation) ClearEdge(name string) error { + switch name { + case post.EdgeCategory: + m.ClearCategory() + return nil + case post.EdgeProfile: + m.ClearProfile() + return nil + } + return fmt.Errorf("unknown Post unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *PostMutation) ResetEdge(name string) error { + switch name { + case post.EdgeCategory: + m.ResetCategory() + return nil + case post.EdgeProfile: + m.ResetProfile() + return nil + } + return fmt.Errorf("unknown Post edge %s", name) +} + +// ProfileMutation represents an operation that mutates the Profile nodes in the graph. +type ProfileMutation struct { + config + op Op + typ string + id *uuid.UUID + created_at *time.Time + updated_at *time.Time + name *string + address *string + phone *string + clearedFields map[string]struct{} + posts map[uuid.UUID]struct{} + removedposts map[uuid.UUID]struct{} + clearedposts bool + done bool + oldValue func(context.Context) (*Profile, error) + predicates []predicate.Profile +} + +var _ ent.Mutation = (*ProfileMutation)(nil) + +// profileOption allows management of the mutation configuration using functional options. +type profileOption func(*ProfileMutation) + +// newProfileMutation creates new mutation for the Profile entity. +func newProfileMutation(c config, op Op, opts ...profileOption) *ProfileMutation { + m := &ProfileMutation{ + config: c, + op: op, + typ: TypeProfile, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withProfileID sets the ID field of the mutation. +func withProfileID(id uuid.UUID) profileOption { + return func(m *ProfileMutation) { + var ( + err error + once sync.Once + value *Profile + ) + m.oldValue = func(ctx context.Context) (*Profile, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Profile.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withProfile sets the old Profile of the mutation. +func withProfile(node *Profile) profileOption { + return func(m *ProfileMutation) { + m.oldValue = func(context.Context) (*Profile, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m ProfileMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ProfileMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Profile entities. +func (m *ProfileMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *ProfileMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *ProfileMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Profile.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCreatedAt sets the "created_at" field. +func (m *ProfileMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ProfileMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Profile entity. +// If the Profile 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 *ProfileMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ProfileMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *ProfileMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ProfileMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Profile entity. +// If the Profile 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 *ProfileMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (m *ProfileMutation) ClearUpdatedAt() { + m.updated_at = nil + m.clearedFields[profile.FieldUpdatedAt] = struct{}{} +} + +// UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. +func (m *ProfileMutation) UpdatedAtCleared() bool { + _, ok := m.clearedFields[profile.FieldUpdatedAt] + return ok +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ProfileMutation) ResetUpdatedAt() { + m.updated_at = nil + delete(m.clearedFields, profile.FieldUpdatedAt) +} + +// SetName sets the "name" field. +func (m *ProfileMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *ProfileMutation) 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 Profile entity. +// If the Profile 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 *ProfileMutation) 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 *ProfileMutation) ClearName() { + m.name = nil + m.clearedFields[profile.FieldName] = struct{}{} +} + +// NameCleared returns if the "name" field was cleared in this mutation. +func (m *ProfileMutation) NameCleared() bool { + _, ok := m.clearedFields[profile.FieldName] + return ok +} + +// ResetName resets all changes to the "name" field. +func (m *ProfileMutation) ResetName() { + m.name = nil + delete(m.clearedFields, profile.FieldName) +} + +// SetAddress sets the "address" field. +func (m *ProfileMutation) SetAddress(s string) { + m.address = &s +} + +// Address returns the value of the "address" field in the mutation. +func (m *ProfileMutation) Address() (r string, exists bool) { + v := m.address + if v == nil { + return + } + return *v, true +} + +// OldAddress returns the old "address" field's value of the Profile entity. +// If the Profile 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 *ProfileMutation) OldAddress(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAddress is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAddress requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAddress: %w", err) + } + return oldValue.Address, nil +} + +// ClearAddress clears the value of the "address" field. +func (m *ProfileMutation) ClearAddress() { + m.address = nil + m.clearedFields[profile.FieldAddress] = struct{}{} +} + +// AddressCleared returns if the "address" field was cleared in this mutation. +func (m *ProfileMutation) AddressCleared() bool { + _, ok := m.clearedFields[profile.FieldAddress] + return ok +} + +// ResetAddress resets all changes to the "address" field. +func (m *ProfileMutation) ResetAddress() { + m.address = nil + delete(m.clearedFields, profile.FieldAddress) +} + +// SetPhone sets the "phone" field. +func (m *ProfileMutation) SetPhone(s string) { + m.phone = &s +} + +// Phone returns the value of the "phone" field in the mutation. +func (m *ProfileMutation) Phone() (r string, exists bool) { + v := m.phone + if v == nil { + return + } + return *v, true +} + +// OldPhone returns the old "phone" field's value of the Profile entity. +// If the Profile 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 *ProfileMutation) OldPhone(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPhone is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPhone requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPhone: %w", err) + } + return oldValue.Phone, nil +} + +// ClearPhone clears the value of the "phone" field. +func (m *ProfileMutation) ClearPhone() { + m.phone = nil + m.clearedFields[profile.FieldPhone] = struct{}{} +} + +// PhoneCleared returns if the "phone" field was cleared in this mutation. +func (m *ProfileMutation) PhoneCleared() bool { + _, ok := m.clearedFields[profile.FieldPhone] + return ok +} + +// ResetPhone resets all changes to the "phone" field. +func (m *ProfileMutation) ResetPhone() { + m.phone = nil + delete(m.clearedFields, profile.FieldPhone) +} + +// AddPostIDs adds the "posts" edge to the Post entity by ids. +func (m *ProfileMutation) AddPostIDs(ids ...uuid.UUID) { + if m.posts == nil { + m.posts = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.posts[ids[i]] = struct{}{} + } +} + +// ClearPosts clears the "posts" edge to the Post entity. +func (m *ProfileMutation) ClearPosts() { + m.clearedposts = true +} + +// PostsCleared reports if the "posts" edge to the Post entity was cleared. +func (m *ProfileMutation) PostsCleared() bool { + return m.clearedposts +} + +// RemovePostIDs removes the "posts" edge to the Post entity by IDs. +func (m *ProfileMutation) RemovePostIDs(ids ...uuid.UUID) { + if m.removedposts == nil { + m.removedposts = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.posts, ids[i]) + m.removedposts[ids[i]] = struct{}{} + } +} + +// RemovedPosts returns the removed IDs of the "posts" edge to the Post entity. +func (m *ProfileMutation) RemovedPostsIDs() (ids []uuid.UUID) { + for id := range m.removedposts { + ids = append(ids, id) + } + return +} + +// PostsIDs returns the "posts" edge IDs in the mutation. +func (m *ProfileMutation) PostsIDs() (ids []uuid.UUID) { + for id := range m.posts { + ids = append(ids, id) + } + return +} + +// ResetPosts resets all changes to the "posts" edge. +func (m *ProfileMutation) ResetPosts() { + m.posts = nil + m.clearedposts = false + m.removedposts = nil +} + +// Where appends a list predicates to the ProfileMutation builder. +func (m *ProfileMutation) Where(ps ...predicate.Profile) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ProfileMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ProfileMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Profile, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ProfileMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ProfileMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Profile). +func (m *ProfileMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *ProfileMutation) Fields() []string { + fields := make([]string, 0, 5) + if m.created_at != nil { + fields = append(fields, profile.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, profile.FieldUpdatedAt) + } + if m.name != nil { + fields = append(fields, profile.FieldName) + } + if m.address != nil { + fields = append(fields, profile.FieldAddress) + } + if m.phone != nil { + fields = append(fields, profile.FieldPhone) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *ProfileMutation) Field(name string) (ent.Value, bool) { + switch name { + case profile.FieldCreatedAt: + return m.CreatedAt() + case profile.FieldUpdatedAt: + return m.UpdatedAt() + case profile.FieldName: + return m.Name() + case profile.FieldAddress: + return m.Address() + case profile.FieldPhone: + return m.Phone() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ProfileMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case profile.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case profile.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case profile.FieldName: + return m.OldName(ctx) + case profile.FieldAddress: + return m.OldAddress(ctx) + case profile.FieldPhone: + return m.OldPhone(ctx) + } + return nil, fmt.Errorf("unknown Profile field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ProfileMutation) SetField(name string, value ent.Value) error { + switch name { + case profile.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case profile.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case profile.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case profile.FieldAddress: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAddress(v) + return nil + case profile.FieldPhone: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPhone(v) + return nil + } + return fmt.Errorf("unknown Profile field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ProfileMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *ProfileMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ProfileMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Profile numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ProfileMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(profile.FieldUpdatedAt) { + fields = append(fields, profile.FieldUpdatedAt) + } + if m.FieldCleared(profile.FieldName) { + fields = append(fields, profile.FieldName) + } + if m.FieldCleared(profile.FieldAddress) { + fields = append(fields, profile.FieldAddress) + } + if m.FieldCleared(profile.FieldPhone) { + fields = append(fields, profile.FieldPhone) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ProfileMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *ProfileMutation) ClearField(name string) error { + switch name { + case profile.FieldUpdatedAt: + m.ClearUpdatedAt() + return nil + case profile.FieldName: + m.ClearName() + return nil + case profile.FieldAddress: + m.ClearAddress() + return nil + case profile.FieldPhone: + m.ClearPhone() + return nil + } + return fmt.Errorf("unknown Profile nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *ProfileMutation) ResetField(name string) error { + switch name { + case profile.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case profile.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case profile.FieldName: + m.ResetName() + return nil + case profile.FieldAddress: + m.ResetAddress() + return nil + case profile.FieldPhone: + m.ResetPhone() + return nil + } + return fmt.Errorf("unknown Profile field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ProfileMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.posts != nil { + edges = append(edges, profile.EdgePosts) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ProfileMutation) AddedIDs(name string) []ent.Value { + switch name { + case profile.EdgePosts: + ids := make([]ent.Value, 0, len(m.posts)) + for id := range m.posts { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ProfileMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + if m.removedposts != nil { + edges = append(edges, profile.EdgePosts) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ProfileMutation) RemovedIDs(name string) []ent.Value { + switch name { + case profile.EdgePosts: + ids := make([]ent.Value, 0, len(m.removedposts)) + for id := range m.removedposts { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ProfileMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedposts { + edges = append(edges, profile.EdgePosts) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ProfileMutation) EdgeCleared(name string) bool { + switch name { + case profile.EdgePosts: + return m.clearedposts + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *ProfileMutation) ClearEdge(name string) error { + switch name { + } + return fmt.Errorf("unknown Profile unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *ProfileMutation) ResetEdge(name string) error { + switch name { + case profile.EdgePosts: + m.ResetPosts() + return nil + } + return fmt.Errorf("unknown Profile edge %s", name) +} diff --git a/ent/post.go b/ent/post.go new file mode 100644 index 0000000..dc76d6f --- /dev/null +++ b/ent/post.go @@ -0,0 +1,237 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" +) + +// Post is the model entity for the Post schema. +type Post struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Expires holds the value of the "expires" field. + Expires bool `json:"expires,omitempty"` + // ExpireTime holds the value of the "expire_time" field. + ExpireTime *time.Time `json:"expire_time,omitempty"` + // Title holds the value of the "title" field. + Title string `json:"title,omitempty"` + // Body holds the value of the "body" field. + Body string `json:"body,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the PostQuery when eager-loading is set. + Edges PostEdges `json:"edges"` + category_posts *uuid.UUID + profile_posts *uuid.UUID + selectValues sql.SelectValues +} + +// PostEdges holds the relations/edges for other nodes in the graph. +type PostEdges struct { + // Category holds the value of the category edge. + Category *Category `json:"category,omitempty"` + // Profile holds the value of the profile edge. + Profile *Profile `json:"profile,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool + // totalCount holds the count of the edges above. + totalCount [2]map[string]int +} + +// CategoryOrErr returns the Category value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e PostEdges) CategoryOrErr() (*Category, error) { + if e.Category != nil { + return e.Category, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: category.Label} + } + return nil, &NotLoadedError{edge: "category"} +} + +// ProfileOrErr returns the Profile value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e PostEdges) ProfileOrErr() (*Profile, error) { + if e.Profile != nil { + return e.Profile, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: profile.Label} + } + return nil, &NotLoadedError{edge: "profile"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Post) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case post.FieldExpires: + values[i] = new(sql.NullBool) + case post.FieldTitle, post.FieldBody: + values[i] = new(sql.NullString) + case post.FieldCreatedAt, post.FieldUpdatedAt, post.FieldExpireTime: + values[i] = new(sql.NullTime) + case post.FieldID: + values[i] = new(uuid.UUID) + case post.ForeignKeys[0]: // category_posts + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + case post.ForeignKeys[1]: // profile_posts + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Post fields. +func (po *Post) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case post.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + po.ID = *value + } + case post.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + po.CreatedAt = value.Time + } + case post.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + po.UpdatedAt = value.Time + } + case post.FieldExpires: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field expires", values[i]) + } else if value.Valid { + po.Expires = value.Bool + } + case post.FieldExpireTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field expire_time", values[i]) + } else if value.Valid { + po.ExpireTime = new(time.Time) + *po.ExpireTime = value.Time + } + case post.FieldTitle: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field title", values[i]) + } else if value.Valid { + po.Title = value.String + } + case post.FieldBody: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field body", values[i]) + } else if value.Valid { + po.Body = value.String + } + case post.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field category_posts", values[i]) + } else if value.Valid { + po.category_posts = new(uuid.UUID) + *po.category_posts = *value.S.(*uuid.UUID) + } + case post.ForeignKeys[1]: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field profile_posts", values[i]) + } else if value.Valid { + po.profile_posts = new(uuid.UUID) + *po.profile_posts = *value.S.(*uuid.UUID) + } + default: + po.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Post. +// This includes values selected through modifiers, order, etc. +func (po *Post) Value(name string) (ent.Value, error) { + return po.selectValues.Get(name) +} + +// QueryCategory queries the "category" edge of the Post entity. +func (po *Post) QueryCategory() *CategoryQuery { + return NewPostClient(po.config).QueryCategory(po) +} + +// QueryProfile queries the "profile" edge of the Post entity. +func (po *Post) QueryProfile() *ProfileQuery { + return NewPostClient(po.config).QueryProfile(po) +} + +// Update returns a builder for updating this Post. +// Note that you need to call Post.Unwrap() before calling this method if this Post +// was returned from a transaction, and the transaction was committed or rolled back. +func (po *Post) Update() *PostUpdateOne { + return NewPostClient(po.config).UpdateOne(po) +} + +// Unwrap unwraps the Post entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (po *Post) Unwrap() *Post { + _tx, ok := po.config.driver.(*txDriver) + if !ok { + panic("ent: Post is not a transactional entity") + } + po.config.driver = _tx.drv + return po +} + +// String implements the fmt.Stringer. +func (po *Post) String() string { + var builder strings.Builder + builder.WriteString("Post(") + builder.WriteString(fmt.Sprintf("id=%v, ", po.ID)) + builder.WriteString("created_at=") + builder.WriteString(po.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(po.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("expires=") + builder.WriteString(fmt.Sprintf("%v", po.Expires)) + builder.WriteString(", ") + if v := po.ExpireTime; v != nil { + builder.WriteString("expire_time=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", ") + builder.WriteString("title=") + builder.WriteString(po.Title) + builder.WriteString(", ") + builder.WriteString("body=") + builder.WriteString(po.Body) + builder.WriteByte(')') + return builder.String() +} + +// Posts is a parsable slice of Post. +type Posts []*Post diff --git a/ent/post/post.go b/ent/post/post.go new file mode 100644 index 0000000..f55f461 --- /dev/null +++ b/ent/post/post.go @@ -0,0 +1,166 @@ +// Code generated by ent, DO NOT EDIT. + +package post + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the post type in the database. + Label = "post" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldExpires holds the string denoting the expires field in the database. + FieldExpires = "expires" + // FieldExpireTime holds the string denoting the expire_time field in the database. + FieldExpireTime = "expire_time" + // FieldTitle holds the string denoting the title field in the database. + FieldTitle = "title" + // FieldBody holds the string denoting the body field in the database. + FieldBody = "body" + // EdgeCategory holds the string denoting the category edge name in mutations. + EdgeCategory = "category" + // EdgeProfile holds the string denoting the profile edge name in mutations. + EdgeProfile = "profile" + // Table holds the table name of the post in the database. + Table = "posts" + // CategoryTable is the table that holds the category relation/edge. + CategoryTable = "posts" + // CategoryInverseTable is the table name for the Category entity. + // It exists in this package in order to avoid circular dependency with the "category" package. + CategoryInverseTable = "categories" + // CategoryColumn is the table column denoting the category relation/edge. + CategoryColumn = "category_posts" + // ProfileTable is the table that holds the profile relation/edge. + ProfileTable = "posts" + // ProfileInverseTable is the table name for the Profile entity. + // It exists in this package in order to avoid circular dependency with the "profile" package. + ProfileInverseTable = "profiles" + // ProfileColumn is the table column denoting the profile relation/edge. + ProfileColumn = "profile_posts" +) + +// Columns holds all SQL columns for post fields. +var Columns = []string{ + FieldID, + FieldCreatedAt, + FieldUpdatedAt, + FieldExpires, + FieldExpireTime, + FieldTitle, + FieldBody, +} + +// ForeignKeys holds the SQL foreign-keys that are owned by the "posts" +// table and are not defined as standalone fields in the schema. +var ForeignKeys = []string{ + "category_posts", + "profile_posts", +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + for i := range ForeignKeys { + if column == ForeignKeys[i] { + return true + } + } + return false +} + +var ( + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultExpires holds the default value on creation for the "expires" field. + DefaultExpires bool + // TitleValidator is a validator for the "title" field. It is called by the builders before save. + TitleValidator func(string) error + // BodyValidator is a validator for the "body" field. It is called by the builders before save. + BodyValidator func(string) error + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the Post queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByExpires orders the results by the expires field. +func ByExpires(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldExpires, opts...).ToFunc() +} + +// ByExpireTime orders the results by the expire_time field. +func ByExpireTime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldExpireTime, opts...).ToFunc() +} + +// ByTitle orders the results by the title field. +func ByTitle(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTitle, opts...).ToFunc() +} + +// ByBody orders the results by the body field. +func ByBody(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBody, opts...).ToFunc() +} + +// ByCategoryField orders the results by category field. +func ByCategoryField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCategoryStep(), sql.OrderByField(field, opts...)) + } +} + +// ByProfileField orders the results by profile field. +func ByProfileField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newProfileStep(), sql.OrderByField(field, opts...)) + } +} +func newCategoryStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CategoryInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, CategoryTable, CategoryColumn), + ) +} +func newProfileStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ProfileInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ProfileTable, ProfileColumn), + ) +} diff --git a/ent/post/where.go b/ent/post/where.go new file mode 100644 index 0000000..d2a7863 --- /dev/null +++ b/ent/post/where.go @@ -0,0 +1,428 @@ +// Code generated by ent, DO NOT EDIT. + +package post + +import ( + "time" + + "code.icod.de/dalu/ka/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Post { + return predicate.Post(sql.FieldLTE(FieldID, id)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// Expires applies equality check predicate on the "expires" field. It's identical to ExpiresEQ. +func Expires(v bool) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldExpires, v)) +} + +// ExpireTime applies equality check predicate on the "expire_time" field. It's identical to ExpireTimeEQ. +func ExpireTime(v time.Time) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldExpireTime, v)) +} + +// Title applies equality check predicate on the "title" field. It's identical to TitleEQ. +func Title(v string) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldTitle, v)) +} + +// Body applies equality check predicate on the "body" field. It's identical to BodyEQ. +func Body(v string) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldBody, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Post { + return predicate.Post(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Post { + return predicate.Post(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Post { + return predicate.Post(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Post { + return predicate.Post(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Post { + return predicate.Post(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Post { + return predicate.Post(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Post { + return predicate.Post(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Post { + return predicate.Post(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Post { + return predicate.Post(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Post { + return predicate.Post(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Post { + return predicate.Post(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Post { + return predicate.Post(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Post { + return predicate.Post(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Post { + return predicate.Post(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field. +func UpdatedAtIsNil() predicate.Post { + return predicate.Post(sql.FieldIsNull(FieldUpdatedAt)) +} + +// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field. +func UpdatedAtNotNil() predicate.Post { + return predicate.Post(sql.FieldNotNull(FieldUpdatedAt)) +} + +// ExpiresEQ applies the EQ predicate on the "expires" field. +func ExpiresEQ(v bool) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldExpires, v)) +} + +// ExpiresNEQ applies the NEQ predicate on the "expires" field. +func ExpiresNEQ(v bool) predicate.Post { + return predicate.Post(sql.FieldNEQ(FieldExpires, v)) +} + +// ExpireTimeEQ applies the EQ predicate on the "expire_time" field. +func ExpireTimeEQ(v time.Time) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldExpireTime, v)) +} + +// ExpireTimeNEQ applies the NEQ predicate on the "expire_time" field. +func ExpireTimeNEQ(v time.Time) predicate.Post { + return predicate.Post(sql.FieldNEQ(FieldExpireTime, v)) +} + +// ExpireTimeIn applies the In predicate on the "expire_time" field. +func ExpireTimeIn(vs ...time.Time) predicate.Post { + return predicate.Post(sql.FieldIn(FieldExpireTime, vs...)) +} + +// ExpireTimeNotIn applies the NotIn predicate on the "expire_time" field. +func ExpireTimeNotIn(vs ...time.Time) predicate.Post { + return predicate.Post(sql.FieldNotIn(FieldExpireTime, vs...)) +} + +// ExpireTimeGT applies the GT predicate on the "expire_time" field. +func ExpireTimeGT(v time.Time) predicate.Post { + return predicate.Post(sql.FieldGT(FieldExpireTime, v)) +} + +// ExpireTimeGTE applies the GTE predicate on the "expire_time" field. +func ExpireTimeGTE(v time.Time) predicate.Post { + return predicate.Post(sql.FieldGTE(FieldExpireTime, v)) +} + +// ExpireTimeLT applies the LT predicate on the "expire_time" field. +func ExpireTimeLT(v time.Time) predicate.Post { + return predicate.Post(sql.FieldLT(FieldExpireTime, v)) +} + +// ExpireTimeLTE applies the LTE predicate on the "expire_time" field. +func ExpireTimeLTE(v time.Time) predicate.Post { + return predicate.Post(sql.FieldLTE(FieldExpireTime, v)) +} + +// ExpireTimeIsNil applies the IsNil predicate on the "expire_time" field. +func ExpireTimeIsNil() predicate.Post { + return predicate.Post(sql.FieldIsNull(FieldExpireTime)) +} + +// ExpireTimeNotNil applies the NotNil predicate on the "expire_time" field. +func ExpireTimeNotNil() predicate.Post { + return predicate.Post(sql.FieldNotNull(FieldExpireTime)) +} + +// TitleEQ applies the EQ predicate on the "title" field. +func TitleEQ(v string) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldTitle, v)) +} + +// TitleNEQ applies the NEQ predicate on the "title" field. +func TitleNEQ(v string) predicate.Post { + return predicate.Post(sql.FieldNEQ(FieldTitle, v)) +} + +// TitleIn applies the In predicate on the "title" field. +func TitleIn(vs ...string) predicate.Post { + return predicate.Post(sql.FieldIn(FieldTitle, vs...)) +} + +// TitleNotIn applies the NotIn predicate on the "title" field. +func TitleNotIn(vs ...string) predicate.Post { + return predicate.Post(sql.FieldNotIn(FieldTitle, vs...)) +} + +// TitleGT applies the GT predicate on the "title" field. +func TitleGT(v string) predicate.Post { + return predicate.Post(sql.FieldGT(FieldTitle, v)) +} + +// TitleGTE applies the GTE predicate on the "title" field. +func TitleGTE(v string) predicate.Post { + return predicate.Post(sql.FieldGTE(FieldTitle, v)) +} + +// TitleLT applies the LT predicate on the "title" field. +func TitleLT(v string) predicate.Post { + return predicate.Post(sql.FieldLT(FieldTitle, v)) +} + +// TitleLTE applies the LTE predicate on the "title" field. +func TitleLTE(v string) predicate.Post { + return predicate.Post(sql.FieldLTE(FieldTitle, v)) +} + +// TitleContains applies the Contains predicate on the "title" field. +func TitleContains(v string) predicate.Post { + return predicate.Post(sql.FieldContains(FieldTitle, v)) +} + +// TitleHasPrefix applies the HasPrefix predicate on the "title" field. +func TitleHasPrefix(v string) predicate.Post { + return predicate.Post(sql.FieldHasPrefix(FieldTitle, v)) +} + +// TitleHasSuffix applies the HasSuffix predicate on the "title" field. +func TitleHasSuffix(v string) predicate.Post { + return predicate.Post(sql.FieldHasSuffix(FieldTitle, v)) +} + +// TitleEqualFold applies the EqualFold predicate on the "title" field. +func TitleEqualFold(v string) predicate.Post { + return predicate.Post(sql.FieldEqualFold(FieldTitle, v)) +} + +// TitleContainsFold applies the ContainsFold predicate on the "title" field. +func TitleContainsFold(v string) predicate.Post { + return predicate.Post(sql.FieldContainsFold(FieldTitle, v)) +} + +// BodyEQ applies the EQ predicate on the "body" field. +func BodyEQ(v string) predicate.Post { + return predicate.Post(sql.FieldEQ(FieldBody, v)) +} + +// BodyNEQ applies the NEQ predicate on the "body" field. +func BodyNEQ(v string) predicate.Post { + return predicate.Post(sql.FieldNEQ(FieldBody, v)) +} + +// BodyIn applies the In predicate on the "body" field. +func BodyIn(vs ...string) predicate.Post { + return predicate.Post(sql.FieldIn(FieldBody, vs...)) +} + +// BodyNotIn applies the NotIn predicate on the "body" field. +func BodyNotIn(vs ...string) predicate.Post { + return predicate.Post(sql.FieldNotIn(FieldBody, vs...)) +} + +// BodyGT applies the GT predicate on the "body" field. +func BodyGT(v string) predicate.Post { + return predicate.Post(sql.FieldGT(FieldBody, v)) +} + +// BodyGTE applies the GTE predicate on the "body" field. +func BodyGTE(v string) predicate.Post { + return predicate.Post(sql.FieldGTE(FieldBody, v)) +} + +// BodyLT applies the LT predicate on the "body" field. +func BodyLT(v string) predicate.Post { + return predicate.Post(sql.FieldLT(FieldBody, v)) +} + +// BodyLTE applies the LTE predicate on the "body" field. +func BodyLTE(v string) predicate.Post { + return predicate.Post(sql.FieldLTE(FieldBody, v)) +} + +// BodyContains applies the Contains predicate on the "body" field. +func BodyContains(v string) predicate.Post { + return predicate.Post(sql.FieldContains(FieldBody, v)) +} + +// BodyHasPrefix applies the HasPrefix predicate on the "body" field. +func BodyHasPrefix(v string) predicate.Post { + return predicate.Post(sql.FieldHasPrefix(FieldBody, v)) +} + +// BodyHasSuffix applies the HasSuffix predicate on the "body" field. +func BodyHasSuffix(v string) predicate.Post { + return predicate.Post(sql.FieldHasSuffix(FieldBody, v)) +} + +// BodyEqualFold applies the EqualFold predicate on the "body" field. +func BodyEqualFold(v string) predicate.Post { + return predicate.Post(sql.FieldEqualFold(FieldBody, v)) +} + +// BodyContainsFold applies the ContainsFold predicate on the "body" field. +func BodyContainsFold(v string) predicate.Post { + return predicate.Post(sql.FieldContainsFold(FieldBody, v)) +} + +// HasCategory applies the HasEdge predicate on the "category" edge. +func HasCategory() predicate.Post { + return predicate.Post(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, CategoryTable, CategoryColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCategoryWith applies the HasEdge predicate on the "category" edge with a given conditions (other predicates). +func HasCategoryWith(preds ...predicate.Category) predicate.Post { + return predicate.Post(func(s *sql.Selector) { + step := newCategoryStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasProfile applies the HasEdge predicate on the "profile" edge. +func HasProfile() predicate.Post { + return predicate.Post(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ProfileTable, ProfileColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasProfileWith applies the HasEdge predicate on the "profile" edge with a given conditions (other predicates). +func HasProfileWith(preds ...predicate.Profile) predicate.Post { + return predicate.Post(func(s *sql.Selector) { + step := newProfileStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Post) predicate.Post { + return predicate.Post(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Post) predicate.Post { + return predicate.Post(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Post) predicate.Post { + return predicate.Post(sql.NotPredicates(p)) +} diff --git a/ent/post_create.go b/ent/post_create.go new file mode 100644 index 0000000..36124d8 --- /dev/null +++ b/ent/post_create.go @@ -0,0 +1,401 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// PostCreate is the builder for creating a Post entity. +type PostCreate struct { + config + mutation *PostMutation + hooks []Hook +} + +// SetCreatedAt sets the "created_at" field. +func (pc *PostCreate) SetCreatedAt(t time.Time) *PostCreate { + pc.mutation.SetCreatedAt(t) + return pc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (pc *PostCreate) SetNillableCreatedAt(t *time.Time) *PostCreate { + if t != nil { + pc.SetCreatedAt(*t) + } + return pc +} + +// SetUpdatedAt sets the "updated_at" field. +func (pc *PostCreate) SetUpdatedAt(t time.Time) *PostCreate { + pc.mutation.SetUpdatedAt(t) + return pc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (pc *PostCreate) SetNillableUpdatedAt(t *time.Time) *PostCreate { + if t != nil { + pc.SetUpdatedAt(*t) + } + return pc +} + +// SetExpires sets the "expires" field. +func (pc *PostCreate) SetExpires(b bool) *PostCreate { + pc.mutation.SetExpires(b) + return pc +} + +// SetNillableExpires sets the "expires" field if the given value is not nil. +func (pc *PostCreate) SetNillableExpires(b *bool) *PostCreate { + if b != nil { + pc.SetExpires(*b) + } + return pc +} + +// SetExpireTime sets the "expire_time" field. +func (pc *PostCreate) SetExpireTime(t time.Time) *PostCreate { + pc.mutation.SetExpireTime(t) + return pc +} + +// SetNillableExpireTime sets the "expire_time" field if the given value is not nil. +func (pc *PostCreate) SetNillableExpireTime(t *time.Time) *PostCreate { + if t != nil { + pc.SetExpireTime(*t) + } + return pc +} + +// SetTitle sets the "title" field. +func (pc *PostCreate) SetTitle(s string) *PostCreate { + pc.mutation.SetTitle(s) + return pc +} + +// SetBody sets the "body" field. +func (pc *PostCreate) SetBody(s string) *PostCreate { + pc.mutation.SetBody(s) + return pc +} + +// SetID sets the "id" field. +func (pc *PostCreate) SetID(u uuid.UUID) *PostCreate { + pc.mutation.SetID(u) + return pc +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (pc *PostCreate) SetNillableID(u *uuid.UUID) *PostCreate { + if u != nil { + pc.SetID(*u) + } + return pc +} + +// SetCategoryID sets the "category" edge to the Category entity by ID. +func (pc *PostCreate) SetCategoryID(id uuid.UUID) *PostCreate { + pc.mutation.SetCategoryID(id) + return pc +} + +// SetNillableCategoryID sets the "category" edge to the Category entity by ID if the given value is not nil. +func (pc *PostCreate) SetNillableCategoryID(id *uuid.UUID) *PostCreate { + if id != nil { + pc = pc.SetCategoryID(*id) + } + return pc +} + +// SetCategory sets the "category" edge to the Category entity. +func (pc *PostCreate) SetCategory(c *Category) *PostCreate { + return pc.SetCategoryID(c.ID) +} + +// SetProfileID sets the "profile" edge to the Profile entity by ID. +func (pc *PostCreate) SetProfileID(id uuid.UUID) *PostCreate { + pc.mutation.SetProfileID(id) + return pc +} + +// SetNillableProfileID sets the "profile" edge to the Profile entity by ID if the given value is not nil. +func (pc *PostCreate) SetNillableProfileID(id *uuid.UUID) *PostCreate { + if id != nil { + pc = pc.SetProfileID(*id) + } + return pc +} + +// SetProfile sets the "profile" edge to the Profile entity. +func (pc *PostCreate) SetProfile(p *Profile) *PostCreate { + return pc.SetProfileID(p.ID) +} + +// Mutation returns the PostMutation object of the builder. +func (pc *PostCreate) Mutation() *PostMutation { + return pc.mutation +} + +// Save creates the Post in the database. +func (pc *PostCreate) Save(ctx context.Context) (*Post, error) { + pc.defaults() + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (pc *PostCreate) SaveX(ctx context.Context) *Post { + v, err := pc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (pc *PostCreate) Exec(ctx context.Context) error { + _, err := pc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (pc *PostCreate) ExecX(ctx context.Context) { + if err := pc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (pc *PostCreate) defaults() { + if _, ok := pc.mutation.CreatedAt(); !ok { + v := post.DefaultCreatedAt() + pc.mutation.SetCreatedAt(v) + } + if _, ok := pc.mutation.UpdatedAt(); !ok { + v := post.DefaultUpdatedAt() + pc.mutation.SetUpdatedAt(v) + } + if _, ok := pc.mutation.Expires(); !ok { + v := post.DefaultExpires + pc.mutation.SetExpires(v) + } + if _, ok := pc.mutation.ID(); !ok { + v := post.DefaultID() + pc.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (pc *PostCreate) check() error { + if _, ok := pc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Post.created_at"`)} + } + if _, ok := pc.mutation.Expires(); !ok { + return &ValidationError{Name: "expires", err: errors.New(`ent: missing required field "Post.expires"`)} + } + if _, ok := pc.mutation.Title(); !ok { + return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Post.title"`)} + } + if v, ok := pc.mutation.Title(); ok { + if err := post.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Post.title": %w`, err)} + } + } + if _, ok := pc.mutation.Body(); !ok { + return &ValidationError{Name: "body", err: errors.New(`ent: missing required field "Post.body"`)} + } + if v, ok := pc.mutation.Body(); ok { + if err := post.BodyValidator(v); err != nil { + return &ValidationError{Name: "body", err: fmt.Errorf(`ent: validator failed for field "Post.body": %w`, err)} + } + } + return nil +} + +func (pc *PostCreate) sqlSave(ctx context.Context) (*Post, error) { + if err := pc.check(); err != nil { + return nil, err + } + _node, _spec := pc.createSpec() + if err := sqlgraph.CreateNode(ctx, pc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + pc.mutation.id = &_node.ID + pc.mutation.done = true + return _node, nil +} + +func (pc *PostCreate) createSpec() (*Post, *sqlgraph.CreateSpec) { + var ( + _node = &Post{config: pc.config} + _spec = sqlgraph.NewCreateSpec(post.Table, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID)) + ) + if id, ok := pc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := pc.mutation.CreatedAt(); ok { + _spec.SetField(post.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := pc.mutation.UpdatedAt(); ok { + _spec.SetField(post.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := pc.mutation.Expires(); ok { + _spec.SetField(post.FieldExpires, field.TypeBool, value) + _node.Expires = value + } + if value, ok := pc.mutation.ExpireTime(); ok { + _spec.SetField(post.FieldExpireTime, field.TypeTime, value) + _node.ExpireTime = &value + } + if value, ok := pc.mutation.Title(); ok { + _spec.SetField(post.FieldTitle, field.TypeString, value) + _node.Title = value + } + if value, ok := pc.mutation.Body(); ok { + _spec.SetField(post.FieldBody, field.TypeString, value) + _node.Body = value + } + if nodes := pc.mutation.CategoryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.CategoryTable, + Columns: []string{post.CategoryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.category_posts = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := pc.mutation.ProfileIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.ProfileTable, + Columns: []string{post.ProfileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.profile_posts = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// PostCreateBulk is the builder for creating many Post entities in bulk. +type PostCreateBulk struct { + config + err error + builders []*PostCreate +} + +// Save creates the Post entities in the database. +func (pcb *PostCreateBulk) Save(ctx context.Context) ([]*Post, error) { + if pcb.err != nil { + return nil, pcb.err + } + specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) + nodes := make([]*Post, len(pcb.builders)) + mutators := make([]Mutator, len(pcb.builders)) + for i := range pcb.builders { + func(i int, root context.Context) { + builder := pcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*PostMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, pcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, pcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, pcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (pcb *PostCreateBulk) SaveX(ctx context.Context) []*Post { + v, err := pcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (pcb *PostCreateBulk) Exec(ctx context.Context) error { + _, err := pcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (pcb *PostCreateBulk) ExecX(ctx context.Context) { + if err := pcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/post_delete.go b/ent/post_delete.go new file mode 100644 index 0000000..cf3401d --- /dev/null +++ b/ent/post_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// PostDelete is the builder for deleting a Post entity. +type PostDelete struct { + config + hooks []Hook + mutation *PostMutation +} + +// Where appends a list predicates to the PostDelete builder. +func (pd *PostDelete) Where(ps ...predicate.Post) *PostDelete { + pd.mutation.Where(ps...) + return pd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (pd *PostDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (pd *PostDelete) ExecX(ctx context.Context) int { + n, err := pd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (pd *PostDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(post.Table, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID)) + if ps := pd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, pd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + pd.mutation.done = true + return affected, err +} + +// PostDeleteOne is the builder for deleting a single Post entity. +type PostDeleteOne struct { + pd *PostDelete +} + +// Where appends a list predicates to the PostDelete builder. +func (pdo *PostDeleteOne) Where(ps ...predicate.Post) *PostDeleteOne { + pdo.pd.mutation.Where(ps...) + return pdo +} + +// Exec executes the deletion query. +func (pdo *PostDeleteOne) Exec(ctx context.Context) error { + n, err := pdo.pd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{post.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (pdo *PostDeleteOne) ExecX(ctx context.Context) { + if err := pdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/post_query.go b/ent/post_query.go new file mode 100644 index 0000000..e45e627 --- /dev/null +++ b/ent/post_query.go @@ -0,0 +1,703 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// PostQuery is the builder for querying Post entities. +type PostQuery struct { + config + ctx *QueryContext + order []post.OrderOption + inters []Interceptor + predicates []predicate.Post + withCategory *CategoryQuery + withProfile *ProfileQuery + withFKs bool + modifiers []func(*sql.Selector) + loadTotal []func(context.Context, []*Post) error + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the PostQuery builder. +func (pq *PostQuery) Where(ps ...predicate.Post) *PostQuery { + pq.predicates = append(pq.predicates, ps...) + return pq +} + +// Limit the number of records to be returned by this query. +func (pq *PostQuery) Limit(limit int) *PostQuery { + pq.ctx.Limit = &limit + return pq +} + +// Offset to start from. +func (pq *PostQuery) Offset(offset int) *PostQuery { + pq.ctx.Offset = &offset + return pq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (pq *PostQuery) Unique(unique bool) *PostQuery { + pq.ctx.Unique = &unique + return pq +} + +// Order specifies how the records should be ordered. +func (pq *PostQuery) Order(o ...post.OrderOption) *PostQuery { + pq.order = append(pq.order, o...) + return pq +} + +// QueryCategory chains the current query on the "category" edge. +func (pq *PostQuery) QueryCategory() *CategoryQuery { + query := (&CategoryClient{config: pq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := pq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := pq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(post.Table, post.FieldID, selector), + sqlgraph.To(category.Table, category.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, post.CategoryTable, post.CategoryColumn), + ) + fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryProfile chains the current query on the "profile" edge. +func (pq *PostQuery) QueryProfile() *ProfileQuery { + query := (&ProfileClient{config: pq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := pq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := pq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(post.Table, post.FieldID, selector), + sqlgraph.To(profile.Table, profile.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, post.ProfileTable, post.ProfileColumn), + ) + fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Post entity from the query. +// Returns a *NotFoundError when no Post was found. +func (pq *PostQuery) First(ctx context.Context) (*Post, error) { + nodes, err := pq.Limit(1).All(setContextOp(ctx, pq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{post.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (pq *PostQuery) FirstX(ctx context.Context) *Post { + node, err := pq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Post ID from the query. +// Returns a *NotFoundError when no Post ID was found. +func (pq *PostQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = pq.Limit(1).IDs(setContextOp(ctx, pq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{post.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (pq *PostQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := pq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Post entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Post entity is found. +// Returns a *NotFoundError when no Post entities are found. +func (pq *PostQuery) Only(ctx context.Context) (*Post, error) { + nodes, err := pq.Limit(2).All(setContextOp(ctx, pq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{post.Label} + default: + return nil, &NotSingularError{post.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (pq *PostQuery) OnlyX(ctx context.Context) *Post { + node, err := pq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Post ID in the query. +// Returns a *NotSingularError when more than one Post ID is found. +// Returns a *NotFoundError when no entities are found. +func (pq *PostQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = pq.Limit(2).IDs(setContextOp(ctx, pq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{post.Label} + default: + err = &NotSingularError{post.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (pq *PostQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := pq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Posts. +func (pq *PostQuery) All(ctx context.Context) ([]*Post, error) { + ctx = setContextOp(ctx, pq.ctx, ent.OpQueryAll) + if err := pq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Post, *PostQuery]() + return withInterceptors[[]*Post](ctx, pq, qr, pq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (pq *PostQuery) AllX(ctx context.Context) []*Post { + nodes, err := pq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Post IDs. +func (pq *PostQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if pq.ctx.Unique == nil && pq.path != nil { + pq.Unique(true) + } + ctx = setContextOp(ctx, pq.ctx, ent.OpQueryIDs) + if err = pq.Select(post.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (pq *PostQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := pq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (pq *PostQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, pq.ctx, ent.OpQueryCount) + if err := pq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, pq, querierCount[*PostQuery](), pq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (pq *PostQuery) CountX(ctx context.Context) int { + count, err := pq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (pq *PostQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, pq.ctx, ent.OpQueryExist) + switch _, err := pq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (pq *PostQuery) ExistX(ctx context.Context) bool { + exist, err := pq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the PostQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (pq *PostQuery) Clone() *PostQuery { + if pq == nil { + return nil + } + return &PostQuery{ + config: pq.config, + ctx: pq.ctx.Clone(), + order: append([]post.OrderOption{}, pq.order...), + inters: append([]Interceptor{}, pq.inters...), + predicates: append([]predicate.Post{}, pq.predicates...), + withCategory: pq.withCategory.Clone(), + withProfile: pq.withProfile.Clone(), + // clone intermediate query. + sql: pq.sql.Clone(), + path: pq.path, + } +} + +// WithCategory tells the query-builder to eager-load the nodes that are connected to +// the "category" edge. The optional arguments are used to configure the query builder of the edge. +func (pq *PostQuery) WithCategory(opts ...func(*CategoryQuery)) *PostQuery { + query := (&CategoryClient{config: pq.config}).Query() + for _, opt := range opts { + opt(query) + } + pq.withCategory = query + return pq +} + +// WithProfile tells the query-builder to eager-load the nodes that are connected to +// the "profile" edge. The optional arguments are used to configure the query builder of the edge. +func (pq *PostQuery) WithProfile(opts ...func(*ProfileQuery)) *PostQuery { + query := (&ProfileClient{config: pq.config}).Query() + for _, opt := range opts { + opt(query) + } + pq.withProfile = query + return pq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Post.Query(). +// GroupBy(post.FieldCreatedAt). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (pq *PostQuery) GroupBy(field string, fields ...string) *PostGroupBy { + pq.ctx.Fields = append([]string{field}, fields...) + grbuild := &PostGroupBy{build: pq} + grbuild.flds = &pq.ctx.Fields + grbuild.label = post.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// } +// +// client.Post.Query(). +// Select(post.FieldCreatedAt). +// Scan(ctx, &v) +func (pq *PostQuery) Select(fields ...string) *PostSelect { + pq.ctx.Fields = append(pq.ctx.Fields, fields...) + sbuild := &PostSelect{PostQuery: pq} + sbuild.label = post.Label + sbuild.flds, sbuild.scan = &pq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a PostSelect configured with the given aggregations. +func (pq *PostQuery) Aggregate(fns ...AggregateFunc) *PostSelect { + return pq.Select().Aggregate(fns...) +} + +func (pq *PostQuery) prepareQuery(ctx context.Context) error { + for _, inter := range pq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, pq); err != nil { + return err + } + } + } + for _, f := range pq.ctx.Fields { + if !post.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if pq.path != nil { + prev, err := pq.path(ctx) + if err != nil { + return err + } + pq.sql = prev + } + return nil +} + +func (pq *PostQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Post, error) { + var ( + nodes = []*Post{} + withFKs = pq.withFKs + _spec = pq.querySpec() + loadedTypes = [2]bool{ + pq.withCategory != nil, + pq.withProfile != nil, + } + ) + if pq.withCategory != nil || pq.withProfile != nil { + withFKs = true + } + if withFKs { + _spec.Node.Columns = append(_spec.Node.Columns, post.ForeignKeys...) + } + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Post).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Post{config: pq.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(pq.modifiers) > 0 { + _spec.Modifiers = pq.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, pq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := pq.withCategory; query != nil { + if err := pq.loadCategory(ctx, query, nodes, nil, + func(n *Post, e *Category) { n.Edges.Category = e }); err != nil { + return nil, err + } + } + if query := pq.withProfile; query != nil { + if err := pq.loadProfile(ctx, query, nodes, nil, + func(n *Post, e *Profile) { n.Edges.Profile = e }); err != nil { + return nil, err + } + } + for i := range pq.loadTotal { + if err := pq.loadTotal[i](ctx, nodes); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (pq *PostQuery) loadCategory(ctx context.Context, query *CategoryQuery, nodes []*Post, init func(*Post), assign func(*Post, *Category)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*Post) + for i := range nodes { + if nodes[i].category_posts == nil { + continue + } + fk := *nodes[i].category_posts + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(category.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "category_posts" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (pq *PostQuery) loadProfile(ctx context.Context, query *ProfileQuery, nodes []*Post, init func(*Post), assign func(*Post, *Profile)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*Post) + for i := range nodes { + if nodes[i].profile_posts == nil { + continue + } + fk := *nodes[i].profile_posts + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(profile.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "profile_posts" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (pq *PostQuery) sqlCount(ctx context.Context) (int, error) { + _spec := pq.querySpec() + if len(pq.modifiers) > 0 { + _spec.Modifiers = pq.modifiers + } + _spec.Node.Columns = pq.ctx.Fields + if len(pq.ctx.Fields) > 0 { + _spec.Unique = pq.ctx.Unique != nil && *pq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, pq.driver, _spec) +} + +func (pq *PostQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID)) + _spec.From = pq.sql + if unique := pq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if pq.path != nil { + _spec.Unique = true + } + if fields := pq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, post.FieldID) + for i := range fields { + if fields[i] != post.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := pq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := pq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := pq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := pq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (pq *PostQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(pq.driver.Dialect()) + t1 := builder.Table(post.Table) + columns := pq.ctx.Fields + if len(columns) == 0 { + columns = post.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if pq.sql != nil { + selector = pq.sql + selector.Select(selector.Columns(columns...)...) + } + if pq.ctx.Unique != nil && *pq.ctx.Unique { + selector.Distinct() + } + for _, p := range pq.predicates { + p(selector) + } + for _, p := range pq.order { + p(selector) + } + if offset := pq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := pq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// PostGroupBy is the group-by builder for Post entities. +type PostGroupBy struct { + selector + build *PostQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (pgb *PostGroupBy) Aggregate(fns ...AggregateFunc) *PostGroupBy { + pgb.fns = append(pgb.fns, fns...) + return pgb +} + +// Scan applies the selector query and scans the result into the given value. +func (pgb *PostGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, pgb.build.ctx, ent.OpQueryGroupBy) + if err := pgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*PostQuery, *PostGroupBy](ctx, pgb.build, pgb, pgb.build.inters, v) +} + +func (pgb *PostGroupBy) sqlScan(ctx context.Context, root *PostQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(pgb.fns)) + for _, fn := range pgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*pgb.flds)+len(pgb.fns)) + for _, f := range *pgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*pgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := pgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// PostSelect is the builder for selecting fields of Post entities. +type PostSelect struct { + *PostQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ps *PostSelect) Aggregate(fns ...AggregateFunc) *PostSelect { + ps.fns = append(ps.fns, fns...) + return ps +} + +// Scan applies the selector query and scans the result into the given value. +func (ps *PostSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ps.ctx, ent.OpQuerySelect) + if err := ps.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*PostQuery, *PostSelect](ctx, ps.PostQuery, ps, ps.inters, v) +} + +func (ps *PostSelect) sqlScan(ctx context.Context, root *PostQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ps.fns)) + for _, fn := range ps.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ps.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := ps.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/post_update.go b/ent/post_update.go new file mode 100644 index 0000000..35dee59 --- /dev/null +++ b/ent/post_update.go @@ -0,0 +1,639 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// PostUpdate is the builder for updating Post entities. +type PostUpdate struct { + config + hooks []Hook + mutation *PostMutation +} + +// Where appends a list predicates to the PostUpdate builder. +func (pu *PostUpdate) Where(ps ...predicate.Post) *PostUpdate { + pu.mutation.Where(ps...) + return pu +} + +// SetUpdatedAt sets the "updated_at" field. +func (pu *PostUpdate) SetUpdatedAt(t time.Time) *PostUpdate { + pu.mutation.SetUpdatedAt(t) + return pu +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (pu *PostUpdate) ClearUpdatedAt() *PostUpdate { + pu.mutation.ClearUpdatedAt() + return pu +} + +// SetExpires sets the "expires" field. +func (pu *PostUpdate) SetExpires(b bool) *PostUpdate { + pu.mutation.SetExpires(b) + return pu +} + +// SetNillableExpires sets the "expires" field if the given value is not nil. +func (pu *PostUpdate) SetNillableExpires(b *bool) *PostUpdate { + if b != nil { + pu.SetExpires(*b) + } + return pu +} + +// SetExpireTime sets the "expire_time" field. +func (pu *PostUpdate) SetExpireTime(t time.Time) *PostUpdate { + pu.mutation.SetExpireTime(t) + return pu +} + +// SetNillableExpireTime sets the "expire_time" field if the given value is not nil. +func (pu *PostUpdate) SetNillableExpireTime(t *time.Time) *PostUpdate { + if t != nil { + pu.SetExpireTime(*t) + } + return pu +} + +// ClearExpireTime clears the value of the "expire_time" field. +func (pu *PostUpdate) ClearExpireTime() *PostUpdate { + pu.mutation.ClearExpireTime() + return pu +} + +// SetTitle sets the "title" field. +func (pu *PostUpdate) SetTitle(s string) *PostUpdate { + pu.mutation.SetTitle(s) + return pu +} + +// SetNillableTitle sets the "title" field if the given value is not nil. +func (pu *PostUpdate) SetNillableTitle(s *string) *PostUpdate { + if s != nil { + pu.SetTitle(*s) + } + return pu +} + +// SetBody sets the "body" field. +func (pu *PostUpdate) SetBody(s string) *PostUpdate { + pu.mutation.SetBody(s) + return pu +} + +// SetNillableBody sets the "body" field if the given value is not nil. +func (pu *PostUpdate) SetNillableBody(s *string) *PostUpdate { + if s != nil { + pu.SetBody(*s) + } + return pu +} + +// SetCategoryID sets the "category" edge to the Category entity by ID. +func (pu *PostUpdate) SetCategoryID(id uuid.UUID) *PostUpdate { + pu.mutation.SetCategoryID(id) + return pu +} + +// SetNillableCategoryID sets the "category" edge to the Category entity by ID if the given value is not nil. +func (pu *PostUpdate) SetNillableCategoryID(id *uuid.UUID) *PostUpdate { + if id != nil { + pu = pu.SetCategoryID(*id) + } + return pu +} + +// SetCategory sets the "category" edge to the Category entity. +func (pu *PostUpdate) SetCategory(c *Category) *PostUpdate { + return pu.SetCategoryID(c.ID) +} + +// SetProfileID sets the "profile" edge to the Profile entity by ID. +func (pu *PostUpdate) SetProfileID(id uuid.UUID) *PostUpdate { + pu.mutation.SetProfileID(id) + return pu +} + +// SetNillableProfileID sets the "profile" edge to the Profile entity by ID if the given value is not nil. +func (pu *PostUpdate) SetNillableProfileID(id *uuid.UUID) *PostUpdate { + if id != nil { + pu = pu.SetProfileID(*id) + } + return pu +} + +// SetProfile sets the "profile" edge to the Profile entity. +func (pu *PostUpdate) SetProfile(p *Profile) *PostUpdate { + return pu.SetProfileID(p.ID) +} + +// Mutation returns the PostMutation object of the builder. +func (pu *PostUpdate) Mutation() *PostMutation { + return pu.mutation +} + +// ClearCategory clears the "category" edge to the Category entity. +func (pu *PostUpdate) ClearCategory() *PostUpdate { + pu.mutation.ClearCategory() + return pu +} + +// ClearProfile clears the "profile" edge to the Profile entity. +func (pu *PostUpdate) ClearProfile() *PostUpdate { + pu.mutation.ClearProfile() + return pu +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (pu *PostUpdate) Save(ctx context.Context) (int, error) { + pu.defaults() + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (pu *PostUpdate) SaveX(ctx context.Context) int { + affected, err := pu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (pu *PostUpdate) Exec(ctx context.Context) error { + _, err := pu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (pu *PostUpdate) ExecX(ctx context.Context) { + if err := pu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (pu *PostUpdate) defaults() { + if _, ok := pu.mutation.UpdatedAt(); !ok && !pu.mutation.UpdatedAtCleared() { + v := post.UpdateDefaultUpdatedAt() + pu.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (pu *PostUpdate) check() error { + if v, ok := pu.mutation.Title(); ok { + if err := post.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Post.title": %w`, err)} + } + } + if v, ok := pu.mutation.Body(); ok { + if err := post.BodyValidator(v); err != nil { + return &ValidationError{Name: "body", err: fmt.Errorf(`ent: validator failed for field "Post.body": %w`, err)} + } + } + return nil +} + +func (pu *PostUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := pu.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID)) + if ps := pu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := pu.mutation.UpdatedAt(); ok { + _spec.SetField(post.FieldUpdatedAt, field.TypeTime, value) + } + if pu.mutation.UpdatedAtCleared() { + _spec.ClearField(post.FieldUpdatedAt, field.TypeTime) + } + if value, ok := pu.mutation.Expires(); ok { + _spec.SetField(post.FieldExpires, field.TypeBool, value) + } + if value, ok := pu.mutation.ExpireTime(); ok { + _spec.SetField(post.FieldExpireTime, field.TypeTime, value) + } + if pu.mutation.ExpireTimeCleared() { + _spec.ClearField(post.FieldExpireTime, field.TypeTime) + } + if value, ok := pu.mutation.Title(); ok { + _spec.SetField(post.FieldTitle, field.TypeString, value) + } + if value, ok := pu.mutation.Body(); ok { + _spec.SetField(post.FieldBody, field.TypeString, value) + } + if pu.mutation.CategoryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.CategoryTable, + Columns: []string{post.CategoryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := pu.mutation.CategoryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.CategoryTable, + Columns: []string{post.CategoryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if pu.mutation.ProfileCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.ProfileTable, + Columns: []string{post.ProfileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := pu.mutation.ProfileIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.ProfileTable, + Columns: []string{post.ProfileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{post.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + pu.mutation.done = true + return n, nil +} + +// PostUpdateOne is the builder for updating a single Post entity. +type PostUpdateOne struct { + config + fields []string + hooks []Hook + mutation *PostMutation +} + +// SetUpdatedAt sets the "updated_at" field. +func (puo *PostUpdateOne) SetUpdatedAt(t time.Time) *PostUpdateOne { + puo.mutation.SetUpdatedAt(t) + return puo +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (puo *PostUpdateOne) ClearUpdatedAt() *PostUpdateOne { + puo.mutation.ClearUpdatedAt() + return puo +} + +// SetExpires sets the "expires" field. +func (puo *PostUpdateOne) SetExpires(b bool) *PostUpdateOne { + puo.mutation.SetExpires(b) + return puo +} + +// SetNillableExpires sets the "expires" field if the given value is not nil. +func (puo *PostUpdateOne) SetNillableExpires(b *bool) *PostUpdateOne { + if b != nil { + puo.SetExpires(*b) + } + return puo +} + +// SetExpireTime sets the "expire_time" field. +func (puo *PostUpdateOne) SetExpireTime(t time.Time) *PostUpdateOne { + puo.mutation.SetExpireTime(t) + return puo +} + +// SetNillableExpireTime sets the "expire_time" field if the given value is not nil. +func (puo *PostUpdateOne) SetNillableExpireTime(t *time.Time) *PostUpdateOne { + if t != nil { + puo.SetExpireTime(*t) + } + return puo +} + +// ClearExpireTime clears the value of the "expire_time" field. +func (puo *PostUpdateOne) ClearExpireTime() *PostUpdateOne { + puo.mutation.ClearExpireTime() + return puo +} + +// SetTitle sets the "title" field. +func (puo *PostUpdateOne) SetTitle(s string) *PostUpdateOne { + puo.mutation.SetTitle(s) + return puo +} + +// SetNillableTitle sets the "title" field if the given value is not nil. +func (puo *PostUpdateOne) SetNillableTitle(s *string) *PostUpdateOne { + if s != nil { + puo.SetTitle(*s) + } + return puo +} + +// SetBody sets the "body" field. +func (puo *PostUpdateOne) SetBody(s string) *PostUpdateOne { + puo.mutation.SetBody(s) + return puo +} + +// SetNillableBody sets the "body" field if the given value is not nil. +func (puo *PostUpdateOne) SetNillableBody(s *string) *PostUpdateOne { + if s != nil { + puo.SetBody(*s) + } + return puo +} + +// SetCategoryID sets the "category" edge to the Category entity by ID. +func (puo *PostUpdateOne) SetCategoryID(id uuid.UUID) *PostUpdateOne { + puo.mutation.SetCategoryID(id) + return puo +} + +// SetNillableCategoryID sets the "category" edge to the Category entity by ID if the given value is not nil. +func (puo *PostUpdateOne) SetNillableCategoryID(id *uuid.UUID) *PostUpdateOne { + if id != nil { + puo = puo.SetCategoryID(*id) + } + return puo +} + +// SetCategory sets the "category" edge to the Category entity. +func (puo *PostUpdateOne) SetCategory(c *Category) *PostUpdateOne { + return puo.SetCategoryID(c.ID) +} + +// SetProfileID sets the "profile" edge to the Profile entity by ID. +func (puo *PostUpdateOne) SetProfileID(id uuid.UUID) *PostUpdateOne { + puo.mutation.SetProfileID(id) + return puo +} + +// SetNillableProfileID sets the "profile" edge to the Profile entity by ID if the given value is not nil. +func (puo *PostUpdateOne) SetNillableProfileID(id *uuid.UUID) *PostUpdateOne { + if id != nil { + puo = puo.SetProfileID(*id) + } + return puo +} + +// SetProfile sets the "profile" edge to the Profile entity. +func (puo *PostUpdateOne) SetProfile(p *Profile) *PostUpdateOne { + return puo.SetProfileID(p.ID) +} + +// Mutation returns the PostMutation object of the builder. +func (puo *PostUpdateOne) Mutation() *PostMutation { + return puo.mutation +} + +// ClearCategory clears the "category" edge to the Category entity. +func (puo *PostUpdateOne) ClearCategory() *PostUpdateOne { + puo.mutation.ClearCategory() + return puo +} + +// ClearProfile clears the "profile" edge to the Profile entity. +func (puo *PostUpdateOne) ClearProfile() *PostUpdateOne { + puo.mutation.ClearProfile() + return puo +} + +// Where appends a list predicates to the PostUpdate builder. +func (puo *PostUpdateOne) Where(ps ...predicate.Post) *PostUpdateOne { + puo.mutation.Where(ps...) + return puo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (puo *PostUpdateOne) Select(field string, fields ...string) *PostUpdateOne { + puo.fields = append([]string{field}, fields...) + return puo +} + +// Save executes the query and returns the updated Post entity. +func (puo *PostUpdateOne) Save(ctx context.Context) (*Post, error) { + puo.defaults() + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (puo *PostUpdateOne) SaveX(ctx context.Context) *Post { + node, err := puo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (puo *PostUpdateOne) Exec(ctx context.Context) error { + _, err := puo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (puo *PostUpdateOne) ExecX(ctx context.Context) { + if err := puo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (puo *PostUpdateOne) defaults() { + if _, ok := puo.mutation.UpdatedAt(); !ok && !puo.mutation.UpdatedAtCleared() { + v := post.UpdateDefaultUpdatedAt() + puo.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (puo *PostUpdateOne) check() error { + if v, ok := puo.mutation.Title(); ok { + if err := post.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Post.title": %w`, err)} + } + } + if v, ok := puo.mutation.Body(); ok { + if err := post.BodyValidator(v); err != nil { + return &ValidationError{Name: "body", err: fmt.Errorf(`ent: validator failed for field "Post.body": %w`, err)} + } + } + return nil +} + +func (puo *PostUpdateOne) sqlSave(ctx context.Context) (_node *Post, err error) { + if err := puo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID)) + id, ok := puo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Post.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := puo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, post.FieldID) + for _, f := range fields { + if !post.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != post.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := puo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := puo.mutation.UpdatedAt(); ok { + _spec.SetField(post.FieldUpdatedAt, field.TypeTime, value) + } + if puo.mutation.UpdatedAtCleared() { + _spec.ClearField(post.FieldUpdatedAt, field.TypeTime) + } + if value, ok := puo.mutation.Expires(); ok { + _spec.SetField(post.FieldExpires, field.TypeBool, value) + } + if value, ok := puo.mutation.ExpireTime(); ok { + _spec.SetField(post.FieldExpireTime, field.TypeTime, value) + } + if puo.mutation.ExpireTimeCleared() { + _spec.ClearField(post.FieldExpireTime, field.TypeTime) + } + if value, ok := puo.mutation.Title(); ok { + _spec.SetField(post.FieldTitle, field.TypeString, value) + } + if value, ok := puo.mutation.Body(); ok { + _spec.SetField(post.FieldBody, field.TypeString, value) + } + if puo.mutation.CategoryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.CategoryTable, + Columns: []string{post.CategoryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := puo.mutation.CategoryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.CategoryTable, + Columns: []string{post.CategoryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if puo.mutation.ProfileCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.ProfileTable, + Columns: []string{post.ProfileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := puo.mutation.ProfileIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: post.ProfileTable, + Columns: []string{post.ProfileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Post{config: puo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{post.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + puo.mutation.done = true + return _node, nil +} diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go new file mode 100644 index 0000000..0b5ab18 --- /dev/null +++ b/ent/predicate/predicate.go @@ -0,0 +1,16 @@ +// Code generated by ent, DO NOT EDIT. + +package predicate + +import ( + "entgo.io/ent/dialect/sql" +) + +// Category is the predicate function for category builders. +type Category func(*sql.Selector) + +// Post is the predicate function for post builders. +type Post func(*sql.Selector) + +// Profile is the predicate function for profile builders. +type Profile func(*sql.Selector) diff --git a/ent/privacy/privacy.go b/ent/privacy/privacy.go new file mode 100644 index 0000000..d60713f --- /dev/null +++ b/ent/privacy/privacy.go @@ -0,0 +1,243 @@ +// Code generated by ent, DO NOT EDIT. + +package privacy + +import ( + "context" + + "code.icod.de/dalu/ka/ent" + + "entgo.io/ent/entql" + "entgo.io/ent/privacy" +) + +var ( + // Allow may be returned by rules to indicate that the policy + // evaluation should terminate with allow decision. + Allow = privacy.Allow + + // Deny may be returned by rules to indicate that the policy + // evaluation should terminate with deny decision. + Deny = privacy.Deny + + // Skip may be returned by rules to indicate that the policy + // evaluation should continue to the next rule. + Skip = privacy.Skip +) + +// Allowf returns a formatted wrapped Allow decision. +func Allowf(format string, a ...any) error { + return privacy.Allowf(format, a...) +} + +// Denyf returns a formatted wrapped Deny decision. +func Denyf(format string, a ...any) error { + return privacy.Denyf(format, a...) +} + +// Skipf returns a formatted wrapped Skip decision. +func Skipf(format string, a ...any) error { + return privacy.Skipf(format, a...) +} + +// DecisionContext creates a new context from the given parent context with +// a policy decision attach to it. +func DecisionContext(parent context.Context, decision error) context.Context { + return privacy.DecisionContext(parent, decision) +} + +// DecisionFromContext retrieves the policy decision from the context. +func DecisionFromContext(ctx context.Context) (error, bool) { + return privacy.DecisionFromContext(ctx) +} + +type ( + // Policy groups query and mutation policies. + Policy = privacy.Policy + + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule = privacy.QueryRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy = privacy.QueryPolicy + + // MutationRule defines the interface which decides whether a + // mutation is allowed and optionally modifies it. + MutationRule = privacy.MutationRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy = privacy.MutationPolicy + // MutationRuleFunc type is an adapter which allows the use of + // ordinary functions as mutation rules. + MutationRuleFunc = privacy.MutationRuleFunc + + // QueryMutationRule is an interface which groups query and mutation rules. + QueryMutationRule = privacy.QueryMutationRule +) + +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error + +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) +} + +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { + return privacy.AlwaysAllowRule() +} + +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { + return privacy.AlwaysDenyRule() +} + +// ContextQueryMutationRule creates a query/mutation rule from a context eval func. +func ContextQueryMutationRule(eval func(context.Context) error) QueryMutationRule { + return privacy.ContextQueryMutationRule(eval) +} + +// OnMutationOperation evaluates the given rule only on a given mutation operation. +func OnMutationOperation(rule MutationRule, op ent.Op) MutationRule { + return privacy.OnMutationOperation(rule, op) +} + +// DenyMutationOperationRule returns a rule denying specified mutation operation. +func DenyMutationOperationRule(op ent.Op) MutationRule { + rule := MutationRuleFunc(func(_ context.Context, m ent.Mutation) error { + return Denyf("ent/privacy: operation %s is not allowed", m.Op()) + }) + return OnMutationOperation(rule, op) +} + +// The CategoryQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CategoryQueryRuleFunc func(context.Context, *ent.CategoryQuery) error + +// EvalQuery return f(ctx, q). +func (f CategoryQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CategoryQuery); ok { + return f(ctx, q) + } + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CategoryQuery", q) +} + +// The CategoryMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CategoryMutationRuleFunc func(context.Context, *ent.CategoryMutation) error + +// EvalMutation calls f(ctx, m). +func (f CategoryMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { + if m, ok := m.(*ent.CategoryMutation); ok { + return f(ctx, m) + } + return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CategoryMutation", m) +} + +// The PostQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PostQueryRuleFunc func(context.Context, *ent.PostQuery) error + +// EvalQuery return f(ctx, q). +func (f PostQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.PostQuery); ok { + return f(ctx, q) + } + return Denyf("ent/privacy: unexpected query type %T, expect *ent.PostQuery", q) +} + +// The PostMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PostMutationRuleFunc func(context.Context, *ent.PostMutation) error + +// EvalMutation calls f(ctx, m). +func (f PostMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { + if m, ok := m.(*ent.PostMutation); ok { + return f(ctx, m) + } + return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.PostMutation", m) +} + +// The ProfileQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type ProfileQueryRuleFunc func(context.Context, *ent.ProfileQuery) error + +// EvalQuery return f(ctx, q). +func (f ProfileQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.ProfileQuery); ok { + return f(ctx, q) + } + return Denyf("ent/privacy: unexpected query type %T, expect *ent.ProfileQuery", q) +} + +// The ProfileMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type ProfileMutationRuleFunc func(context.Context, *ent.ProfileMutation) error + +// EvalMutation calls f(ctx, m). +func (f ProfileMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { + if m, ok := m.(*ent.ProfileMutation); ok { + return f(ctx, m) + } + return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ProfileMutation", m) +} + +type ( + // Filter is the interface that wraps the Where function + // for filtering nodes in queries and mutations. + Filter interface { + // Where applies a filter on the executed query/mutation. + Where(entql.P) + } + + // The FilterFunc type is an adapter that allows the use of ordinary + // functions as filters for query and mutation types. + FilterFunc func(context.Context, Filter) error +) + +// EvalQuery calls f(ctx, q) if the query implements the Filter interface, otherwise it is denied. +func (f FilterFunc) EvalQuery(ctx context.Context, q ent.Query) error { + fr, err := queryFilter(q) + if err != nil { + return err + } + return f(ctx, fr) +} + +// EvalMutation calls f(ctx, q) if the mutation implements the Filter interface, otherwise it is denied. +func (f FilterFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { + fr, err := mutationFilter(m) + if err != nil { + return err + } + return f(ctx, fr) +} + +var _ QueryMutationRule = FilterFunc(nil) + +func queryFilter(q ent.Query) (Filter, error) { + switch q := q.(type) { + case *ent.CategoryQuery: + return q.Filter(), nil + case *ent.PostQuery: + return q.Filter(), nil + case *ent.ProfileQuery: + return q.Filter(), nil + default: + return nil, Denyf("ent/privacy: unexpected query type %T for query filter", q) + } +} + +func mutationFilter(m ent.Mutation) (Filter, error) { + switch m := m.(type) { + case *ent.CategoryMutation: + return m.Filter(), nil + case *ent.PostMutation: + return m.Filter(), nil + case *ent.ProfileMutation: + return m.Filter(), nil + default: + return nil, Denyf("ent/privacy: unexpected mutation type %T for mutation filter", m) + } +} diff --git a/ent/profile.go b/ent/profile.go new file mode 100644 index 0000000..518b1b2 --- /dev/null +++ b/ent/profile.go @@ -0,0 +1,205 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" +) + +// Profile is the model entity for the Profile schema. +type Profile struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Address holds the value of the "address" field. + Address string `json:"address,omitempty"` + // Phone holds the value of the "phone" field. + Phone string `json:"phone,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the ProfileQuery when eager-loading is set. + Edges ProfileEdges `json:"edges"` + selectValues sql.SelectValues +} + +// ProfileEdges holds the relations/edges for other nodes in the graph. +type ProfileEdges struct { + // Posts holds the value of the posts edge. + Posts []*Post `json:"posts,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool + // totalCount holds the count of the edges above. + totalCount [1]map[string]int + + namedPosts map[string][]*Post +} + +// PostsOrErr returns the Posts value or an error if the edge +// was not loaded in eager-loading. +func (e ProfileEdges) PostsOrErr() ([]*Post, error) { + if e.loadedTypes[0] { + return e.Posts, nil + } + return nil, &NotLoadedError{edge: "posts"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Profile) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case profile.FieldName, profile.FieldAddress, profile.FieldPhone: + values[i] = new(sql.NullString) + case profile.FieldCreatedAt, profile.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case profile.FieldID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Profile fields. +func (pr *Profile) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case profile.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + pr.ID = *value + } + case profile.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + pr.CreatedAt = value.Time + } + case profile.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + pr.UpdatedAt = value.Time + } + case profile.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + pr.Name = value.String + } + case profile.FieldAddress: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field address", values[i]) + } else if value.Valid { + pr.Address = value.String + } + case profile.FieldPhone: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field phone", values[i]) + } else if value.Valid { + pr.Phone = value.String + } + default: + pr.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Profile. +// This includes values selected through modifiers, order, etc. +func (pr *Profile) Value(name string) (ent.Value, error) { + return pr.selectValues.Get(name) +} + +// QueryPosts queries the "posts" edge of the Profile entity. +func (pr *Profile) QueryPosts() *PostQuery { + return NewProfileClient(pr.config).QueryPosts(pr) +} + +// Update returns a builder for updating this Profile. +// Note that you need to call Profile.Unwrap() before calling this method if this Profile +// was returned from a transaction, and the transaction was committed or rolled back. +func (pr *Profile) Update() *ProfileUpdateOne { + return NewProfileClient(pr.config).UpdateOne(pr) +} + +// Unwrap unwraps the Profile entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (pr *Profile) Unwrap() *Profile { + _tx, ok := pr.config.driver.(*txDriver) + if !ok { + panic("ent: Profile is not a transactional entity") + } + pr.config.driver = _tx.drv + return pr +} + +// String implements the fmt.Stringer. +func (pr *Profile) String() string { + var builder strings.Builder + builder.WriteString("Profile(") + builder.WriteString(fmt.Sprintf("id=%v, ", pr.ID)) + builder.WriteString("created_at=") + builder.WriteString(pr.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(pr.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(pr.Name) + builder.WriteString(", ") + builder.WriteString("address=") + builder.WriteString(pr.Address) + builder.WriteString(", ") + builder.WriteString("phone=") + builder.WriteString(pr.Phone) + builder.WriteByte(')') + return builder.String() +} + +// NamedPosts returns the Posts named value or an error if the edge was not +// loaded in eager-loading with this name. +func (pr *Profile) NamedPosts(name string) ([]*Post, error) { + if pr.Edges.namedPosts == nil { + return nil, &NotLoadedError{edge: name} + } + nodes, ok := pr.Edges.namedPosts[name] + if !ok { + return nil, &NotLoadedError{edge: name} + } + return nodes, nil +} + +func (pr *Profile) appendNamedPosts(name string, edges ...*Post) { + if pr.Edges.namedPosts == nil { + pr.Edges.namedPosts = make(map[string][]*Post) + } + if len(edges) == 0 { + pr.Edges.namedPosts[name] = []*Post{} + } else { + pr.Edges.namedPosts[name] = append(pr.Edges.namedPosts[name], edges...) + } +} + +// Profiles is a parsable slice of Profile. +type Profiles []*Profile diff --git a/ent/profile/profile.go b/ent/profile/profile.go new file mode 100644 index 0000000..32e0ba6 --- /dev/null +++ b/ent/profile/profile.go @@ -0,0 +1,124 @@ +// Code generated by ent, DO NOT EDIT. + +package profile + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the profile type in the database. + Label = "profile" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldAddress holds the string denoting the address field in the database. + FieldAddress = "address" + // FieldPhone holds the string denoting the phone field in the database. + FieldPhone = "phone" + // EdgePosts holds the string denoting the posts edge name in mutations. + EdgePosts = "posts" + // Table holds the table name of the profile in the database. + Table = "profiles" + // PostsTable is the table that holds the posts relation/edge. + PostsTable = "posts" + // PostsInverseTable is the table name for the Post entity. + // It exists in this package in order to avoid circular dependency with the "post" package. + PostsInverseTable = "posts" + // PostsColumn is the table column denoting the posts relation/edge. + PostsColumn = "profile_posts" +) + +// Columns holds all SQL columns for profile fields. +var Columns = []string{ + FieldID, + FieldCreatedAt, + FieldUpdatedAt, + FieldName, + FieldAddress, + FieldPhone, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the Profile queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByAddress orders the results by the address field. +func ByAddress(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAddress, opts...).ToFunc() +} + +// ByPhone orders the results by the phone field. +func ByPhone(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPhone, opts...).ToFunc() +} + +// ByPostsCount orders the results by posts count. +func ByPostsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newPostsStep(), opts...) + } +} + +// ByPosts orders the results by posts terms. +func ByPosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newPostsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newPostsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(PostsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, PostsTable, PostsColumn), + ) +} diff --git a/ent/profile/where.go b/ent/profile/where.go new file mode 100644 index 0000000..b7a7832 --- /dev/null +++ b/ent/profile/where.go @@ -0,0 +1,435 @@ +// Code generated by ent, DO NOT EDIT. + +package profile + +import ( + "time" + + "code.icod.de/dalu/ka/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Profile { + return predicate.Profile(sql.FieldLTE(FieldID, id)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldName, v)) +} + +// Address applies equality check predicate on the "address" field. It's identical to AddressEQ. +func Address(v string) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldAddress, v)) +} + +// Phone applies equality check predicate on the "phone" field. It's identical to PhoneEQ. +func Phone(v string) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldPhone, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Profile { + return predicate.Profile(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Profile { + return predicate.Profile(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Profile { + return predicate.Profile(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Profile { + return predicate.Profile(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Profile { + return predicate.Profile(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field. +func UpdatedAtIsNil() predicate.Profile { + return predicate.Profile(sql.FieldIsNull(FieldUpdatedAt)) +} + +// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field. +func UpdatedAtNotNil() predicate.Profile { + return predicate.Profile(sql.FieldNotNull(FieldUpdatedAt)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Profile { + return predicate.Profile(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Profile { + return predicate.Profile(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Profile { + return predicate.Profile(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Profile { + return predicate.Profile(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Profile { + return predicate.Profile(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Profile { + return predicate.Profile(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Profile { + return predicate.Profile(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Profile { + return predicate.Profile(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Profile { + return predicate.Profile(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Profile { + return predicate.Profile(sql.FieldHasSuffix(FieldName, v)) +} + +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.Profile { + return predicate.Profile(sql.FieldIsNull(FieldName)) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.Profile { + return predicate.Profile(sql.FieldNotNull(FieldName)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Profile { + return predicate.Profile(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Profile { + return predicate.Profile(sql.FieldContainsFold(FieldName, v)) +} + +// AddressEQ applies the EQ predicate on the "address" field. +func AddressEQ(v string) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldAddress, v)) +} + +// AddressNEQ applies the NEQ predicate on the "address" field. +func AddressNEQ(v string) predicate.Profile { + return predicate.Profile(sql.FieldNEQ(FieldAddress, v)) +} + +// AddressIn applies the In predicate on the "address" field. +func AddressIn(vs ...string) predicate.Profile { + return predicate.Profile(sql.FieldIn(FieldAddress, vs...)) +} + +// AddressNotIn applies the NotIn predicate on the "address" field. +func AddressNotIn(vs ...string) predicate.Profile { + return predicate.Profile(sql.FieldNotIn(FieldAddress, vs...)) +} + +// AddressGT applies the GT predicate on the "address" field. +func AddressGT(v string) predicate.Profile { + return predicate.Profile(sql.FieldGT(FieldAddress, v)) +} + +// AddressGTE applies the GTE predicate on the "address" field. +func AddressGTE(v string) predicate.Profile { + return predicate.Profile(sql.FieldGTE(FieldAddress, v)) +} + +// AddressLT applies the LT predicate on the "address" field. +func AddressLT(v string) predicate.Profile { + return predicate.Profile(sql.FieldLT(FieldAddress, v)) +} + +// AddressLTE applies the LTE predicate on the "address" field. +func AddressLTE(v string) predicate.Profile { + return predicate.Profile(sql.FieldLTE(FieldAddress, v)) +} + +// AddressContains applies the Contains predicate on the "address" field. +func AddressContains(v string) predicate.Profile { + return predicate.Profile(sql.FieldContains(FieldAddress, v)) +} + +// AddressHasPrefix applies the HasPrefix predicate on the "address" field. +func AddressHasPrefix(v string) predicate.Profile { + return predicate.Profile(sql.FieldHasPrefix(FieldAddress, v)) +} + +// AddressHasSuffix applies the HasSuffix predicate on the "address" field. +func AddressHasSuffix(v string) predicate.Profile { + return predicate.Profile(sql.FieldHasSuffix(FieldAddress, v)) +} + +// AddressIsNil applies the IsNil predicate on the "address" field. +func AddressIsNil() predicate.Profile { + return predicate.Profile(sql.FieldIsNull(FieldAddress)) +} + +// AddressNotNil applies the NotNil predicate on the "address" field. +func AddressNotNil() predicate.Profile { + return predicate.Profile(sql.FieldNotNull(FieldAddress)) +} + +// AddressEqualFold applies the EqualFold predicate on the "address" field. +func AddressEqualFold(v string) predicate.Profile { + return predicate.Profile(sql.FieldEqualFold(FieldAddress, v)) +} + +// AddressContainsFold applies the ContainsFold predicate on the "address" field. +func AddressContainsFold(v string) predicate.Profile { + return predicate.Profile(sql.FieldContainsFold(FieldAddress, v)) +} + +// PhoneEQ applies the EQ predicate on the "phone" field. +func PhoneEQ(v string) predicate.Profile { + return predicate.Profile(sql.FieldEQ(FieldPhone, v)) +} + +// PhoneNEQ applies the NEQ predicate on the "phone" field. +func PhoneNEQ(v string) predicate.Profile { + return predicate.Profile(sql.FieldNEQ(FieldPhone, v)) +} + +// PhoneIn applies the In predicate on the "phone" field. +func PhoneIn(vs ...string) predicate.Profile { + return predicate.Profile(sql.FieldIn(FieldPhone, vs...)) +} + +// PhoneNotIn applies the NotIn predicate on the "phone" field. +func PhoneNotIn(vs ...string) predicate.Profile { + return predicate.Profile(sql.FieldNotIn(FieldPhone, vs...)) +} + +// PhoneGT applies the GT predicate on the "phone" field. +func PhoneGT(v string) predicate.Profile { + return predicate.Profile(sql.FieldGT(FieldPhone, v)) +} + +// PhoneGTE applies the GTE predicate on the "phone" field. +func PhoneGTE(v string) predicate.Profile { + return predicate.Profile(sql.FieldGTE(FieldPhone, v)) +} + +// PhoneLT applies the LT predicate on the "phone" field. +func PhoneLT(v string) predicate.Profile { + return predicate.Profile(sql.FieldLT(FieldPhone, v)) +} + +// PhoneLTE applies the LTE predicate on the "phone" field. +func PhoneLTE(v string) predicate.Profile { + return predicate.Profile(sql.FieldLTE(FieldPhone, v)) +} + +// PhoneContains applies the Contains predicate on the "phone" field. +func PhoneContains(v string) predicate.Profile { + return predicate.Profile(sql.FieldContains(FieldPhone, v)) +} + +// PhoneHasPrefix applies the HasPrefix predicate on the "phone" field. +func PhoneHasPrefix(v string) predicate.Profile { + return predicate.Profile(sql.FieldHasPrefix(FieldPhone, v)) +} + +// PhoneHasSuffix applies the HasSuffix predicate on the "phone" field. +func PhoneHasSuffix(v string) predicate.Profile { + return predicate.Profile(sql.FieldHasSuffix(FieldPhone, v)) +} + +// PhoneIsNil applies the IsNil predicate on the "phone" field. +func PhoneIsNil() predicate.Profile { + return predicate.Profile(sql.FieldIsNull(FieldPhone)) +} + +// PhoneNotNil applies the NotNil predicate on the "phone" field. +func PhoneNotNil() predicate.Profile { + return predicate.Profile(sql.FieldNotNull(FieldPhone)) +} + +// PhoneEqualFold applies the EqualFold predicate on the "phone" field. +func PhoneEqualFold(v string) predicate.Profile { + return predicate.Profile(sql.FieldEqualFold(FieldPhone, v)) +} + +// PhoneContainsFold applies the ContainsFold predicate on the "phone" field. +func PhoneContainsFold(v string) predicate.Profile { + return predicate.Profile(sql.FieldContainsFold(FieldPhone, v)) +} + +// HasPosts applies the HasEdge predicate on the "posts" edge. +func HasPosts() predicate.Profile { + return predicate.Profile(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, PostsTable, PostsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasPostsWith applies the HasEdge predicate on the "posts" edge with a given conditions (other predicates). +func HasPostsWith(preds ...predicate.Post) predicate.Profile { + return predicate.Profile(func(s *sql.Selector) { + step := newPostsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Profile) predicate.Profile { + return predicate.Profile(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Profile) predicate.Profile { + return predicate.Profile(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Profile) predicate.Profile { + return predicate.Profile(sql.NotPredicates(p)) +} diff --git a/ent/profile_create.go b/ent/profile_create.go new file mode 100644 index 0000000..cb134e0 --- /dev/null +++ b/ent/profile_create.go @@ -0,0 +1,334 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// ProfileCreate is the builder for creating a Profile entity. +type ProfileCreate struct { + config + mutation *ProfileMutation + hooks []Hook +} + +// SetCreatedAt sets the "created_at" field. +func (pc *ProfileCreate) SetCreatedAt(t time.Time) *ProfileCreate { + pc.mutation.SetCreatedAt(t) + return pc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (pc *ProfileCreate) SetNillableCreatedAt(t *time.Time) *ProfileCreate { + if t != nil { + pc.SetCreatedAt(*t) + } + return pc +} + +// SetUpdatedAt sets the "updated_at" field. +func (pc *ProfileCreate) SetUpdatedAt(t time.Time) *ProfileCreate { + pc.mutation.SetUpdatedAt(t) + return pc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (pc *ProfileCreate) SetNillableUpdatedAt(t *time.Time) *ProfileCreate { + if t != nil { + pc.SetUpdatedAt(*t) + } + return pc +} + +// SetName sets the "name" field. +func (pc *ProfileCreate) SetName(s string) *ProfileCreate { + pc.mutation.SetName(s) + return pc +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (pc *ProfileCreate) SetNillableName(s *string) *ProfileCreate { + if s != nil { + pc.SetName(*s) + } + return pc +} + +// SetAddress sets the "address" field. +func (pc *ProfileCreate) SetAddress(s string) *ProfileCreate { + pc.mutation.SetAddress(s) + return pc +} + +// SetNillableAddress sets the "address" field if the given value is not nil. +func (pc *ProfileCreate) SetNillableAddress(s *string) *ProfileCreate { + if s != nil { + pc.SetAddress(*s) + } + return pc +} + +// SetPhone sets the "phone" field. +func (pc *ProfileCreate) SetPhone(s string) *ProfileCreate { + pc.mutation.SetPhone(s) + return pc +} + +// SetNillablePhone sets the "phone" field if the given value is not nil. +func (pc *ProfileCreate) SetNillablePhone(s *string) *ProfileCreate { + if s != nil { + pc.SetPhone(*s) + } + return pc +} + +// SetID sets the "id" field. +func (pc *ProfileCreate) SetID(u uuid.UUID) *ProfileCreate { + pc.mutation.SetID(u) + return pc +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (pc *ProfileCreate) SetNillableID(u *uuid.UUID) *ProfileCreate { + if u != nil { + pc.SetID(*u) + } + return pc +} + +// AddPostIDs adds the "posts" edge to the Post entity by IDs. +func (pc *ProfileCreate) AddPostIDs(ids ...uuid.UUID) *ProfileCreate { + pc.mutation.AddPostIDs(ids...) + return pc +} + +// AddPosts adds the "posts" edges to the Post entity. +func (pc *ProfileCreate) AddPosts(p ...*Post) *ProfileCreate { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return pc.AddPostIDs(ids...) +} + +// Mutation returns the ProfileMutation object of the builder. +func (pc *ProfileCreate) Mutation() *ProfileMutation { + return pc.mutation +} + +// Save creates the Profile in the database. +func (pc *ProfileCreate) Save(ctx context.Context) (*Profile, error) { + pc.defaults() + return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (pc *ProfileCreate) SaveX(ctx context.Context) *Profile { + v, err := pc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (pc *ProfileCreate) Exec(ctx context.Context) error { + _, err := pc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (pc *ProfileCreate) ExecX(ctx context.Context) { + if err := pc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (pc *ProfileCreate) defaults() { + if _, ok := pc.mutation.CreatedAt(); !ok { + v := profile.DefaultCreatedAt() + pc.mutation.SetCreatedAt(v) + } + if _, ok := pc.mutation.UpdatedAt(); !ok { + v := profile.DefaultUpdatedAt() + pc.mutation.SetUpdatedAt(v) + } + if _, ok := pc.mutation.ID(); !ok { + v := profile.DefaultID() + pc.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (pc *ProfileCreate) check() error { + if _, ok := pc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Profile.created_at"`)} + } + return nil +} + +func (pc *ProfileCreate) sqlSave(ctx context.Context) (*Profile, error) { + if err := pc.check(); err != nil { + return nil, err + } + _node, _spec := pc.createSpec() + if err := sqlgraph.CreateNode(ctx, pc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + pc.mutation.id = &_node.ID + pc.mutation.done = true + return _node, nil +} + +func (pc *ProfileCreate) createSpec() (*Profile, *sqlgraph.CreateSpec) { + var ( + _node = &Profile{config: pc.config} + _spec = sqlgraph.NewCreateSpec(profile.Table, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID)) + ) + if id, ok := pc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := pc.mutation.CreatedAt(); ok { + _spec.SetField(profile.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := pc.mutation.UpdatedAt(); ok { + _spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := pc.mutation.Name(); ok { + _spec.SetField(profile.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := pc.mutation.Address(); ok { + _spec.SetField(profile.FieldAddress, field.TypeString, value) + _node.Address = value + } + if value, ok := pc.mutation.Phone(); ok { + _spec.SetField(profile.FieldPhone, field.TypeString, value) + _node.Phone = value + } + if nodes := pc.mutation.PostsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: profile.PostsTable, + Columns: []string{profile.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// ProfileCreateBulk is the builder for creating many Profile entities in bulk. +type ProfileCreateBulk struct { + config + err error + builders []*ProfileCreate +} + +// Save creates the Profile entities in the database. +func (pcb *ProfileCreateBulk) Save(ctx context.Context) ([]*Profile, error) { + if pcb.err != nil { + return nil, pcb.err + } + specs := make([]*sqlgraph.CreateSpec, len(pcb.builders)) + nodes := make([]*Profile, len(pcb.builders)) + mutators := make([]Mutator, len(pcb.builders)) + for i := range pcb.builders { + func(i int, root context.Context) { + builder := pcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*ProfileMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, pcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, pcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, pcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (pcb *ProfileCreateBulk) SaveX(ctx context.Context) []*Profile { + v, err := pcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (pcb *ProfileCreateBulk) Exec(ctx context.Context) error { + _, err := pcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (pcb *ProfileCreateBulk) ExecX(ctx context.Context) { + if err := pcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/profile_delete.go b/ent/profile_delete.go new file mode 100644 index 0000000..3871d3a --- /dev/null +++ b/ent/profile_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "code.icod.de/dalu/ka/ent/predicate" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ProfileDelete is the builder for deleting a Profile entity. +type ProfileDelete struct { + config + hooks []Hook + mutation *ProfileMutation +} + +// Where appends a list predicates to the ProfileDelete builder. +func (pd *ProfileDelete) Where(ps ...predicate.Profile) *ProfileDelete { + pd.mutation.Where(ps...) + return pd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (pd *ProfileDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (pd *ProfileDelete) ExecX(ctx context.Context) int { + n, err := pd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (pd *ProfileDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(profile.Table, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID)) + if ps := pd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, pd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + pd.mutation.done = true + return affected, err +} + +// ProfileDeleteOne is the builder for deleting a single Profile entity. +type ProfileDeleteOne struct { + pd *ProfileDelete +} + +// Where appends a list predicates to the ProfileDelete builder. +func (pdo *ProfileDeleteOne) Where(ps ...predicate.Profile) *ProfileDeleteOne { + pdo.pd.mutation.Where(ps...) + return pdo +} + +// Exec executes the deletion query. +func (pdo *ProfileDeleteOne) Exec(ctx context.Context) error { + n, err := pdo.pd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{profile.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (pdo *ProfileDeleteOne) ExecX(ctx context.Context) { + if err := pdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/profile_query.go b/ent/profile_query.go new file mode 100644 index 0000000..4b8a6bb --- /dev/null +++ b/ent/profile_query.go @@ -0,0 +1,643 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// ProfileQuery is the builder for querying Profile entities. +type ProfileQuery struct { + config + ctx *QueryContext + order []profile.OrderOption + inters []Interceptor + predicates []predicate.Profile + withPosts *PostQuery + modifiers []func(*sql.Selector) + loadTotal []func(context.Context, []*Profile) error + withNamedPosts map[string]*PostQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the ProfileQuery builder. +func (pq *ProfileQuery) Where(ps ...predicate.Profile) *ProfileQuery { + pq.predicates = append(pq.predicates, ps...) + return pq +} + +// Limit the number of records to be returned by this query. +func (pq *ProfileQuery) Limit(limit int) *ProfileQuery { + pq.ctx.Limit = &limit + return pq +} + +// Offset to start from. +func (pq *ProfileQuery) Offset(offset int) *ProfileQuery { + pq.ctx.Offset = &offset + return pq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (pq *ProfileQuery) Unique(unique bool) *ProfileQuery { + pq.ctx.Unique = &unique + return pq +} + +// Order specifies how the records should be ordered. +func (pq *ProfileQuery) Order(o ...profile.OrderOption) *ProfileQuery { + pq.order = append(pq.order, o...) + return pq +} + +// QueryPosts chains the current query on the "posts" edge. +func (pq *ProfileQuery) QueryPosts() *PostQuery { + query := (&PostClient{config: pq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := pq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := pq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(profile.Table, profile.FieldID, selector), + sqlgraph.To(post.Table, post.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, profile.PostsTable, profile.PostsColumn), + ) + fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Profile entity from the query. +// Returns a *NotFoundError when no Profile was found. +func (pq *ProfileQuery) First(ctx context.Context) (*Profile, error) { + nodes, err := pq.Limit(1).All(setContextOp(ctx, pq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{profile.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (pq *ProfileQuery) FirstX(ctx context.Context) *Profile { + node, err := pq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Profile ID from the query. +// Returns a *NotFoundError when no Profile ID was found. +func (pq *ProfileQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = pq.Limit(1).IDs(setContextOp(ctx, pq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{profile.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (pq *ProfileQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := pq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Profile entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Profile entity is found. +// Returns a *NotFoundError when no Profile entities are found. +func (pq *ProfileQuery) Only(ctx context.Context) (*Profile, error) { + nodes, err := pq.Limit(2).All(setContextOp(ctx, pq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{profile.Label} + default: + return nil, &NotSingularError{profile.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (pq *ProfileQuery) OnlyX(ctx context.Context) *Profile { + node, err := pq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Profile ID in the query. +// Returns a *NotSingularError when more than one Profile ID is found. +// Returns a *NotFoundError when no entities are found. +func (pq *ProfileQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = pq.Limit(2).IDs(setContextOp(ctx, pq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{profile.Label} + default: + err = &NotSingularError{profile.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (pq *ProfileQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := pq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Profiles. +func (pq *ProfileQuery) All(ctx context.Context) ([]*Profile, error) { + ctx = setContextOp(ctx, pq.ctx, ent.OpQueryAll) + if err := pq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Profile, *ProfileQuery]() + return withInterceptors[[]*Profile](ctx, pq, qr, pq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (pq *ProfileQuery) AllX(ctx context.Context) []*Profile { + nodes, err := pq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Profile IDs. +func (pq *ProfileQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if pq.ctx.Unique == nil && pq.path != nil { + pq.Unique(true) + } + ctx = setContextOp(ctx, pq.ctx, ent.OpQueryIDs) + if err = pq.Select(profile.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (pq *ProfileQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := pq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (pq *ProfileQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, pq.ctx, ent.OpQueryCount) + if err := pq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, pq, querierCount[*ProfileQuery](), pq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (pq *ProfileQuery) CountX(ctx context.Context) int { + count, err := pq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (pq *ProfileQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, pq.ctx, ent.OpQueryExist) + switch _, err := pq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (pq *ProfileQuery) ExistX(ctx context.Context) bool { + exist, err := pq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ProfileQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (pq *ProfileQuery) Clone() *ProfileQuery { + if pq == nil { + return nil + } + return &ProfileQuery{ + config: pq.config, + ctx: pq.ctx.Clone(), + order: append([]profile.OrderOption{}, pq.order...), + inters: append([]Interceptor{}, pq.inters...), + predicates: append([]predicate.Profile{}, pq.predicates...), + withPosts: pq.withPosts.Clone(), + // clone intermediate query. + sql: pq.sql.Clone(), + path: pq.path, + } +} + +// WithPosts tells the query-builder to eager-load the nodes that are connected to +// the "posts" edge. The optional arguments are used to configure the query builder of the edge. +func (pq *ProfileQuery) WithPosts(opts ...func(*PostQuery)) *ProfileQuery { + query := (&PostClient{config: pq.config}).Query() + for _, opt := range opts { + opt(query) + } + pq.withPosts = query + return pq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Profile.Query(). +// GroupBy(profile.FieldCreatedAt). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (pq *ProfileQuery) GroupBy(field string, fields ...string) *ProfileGroupBy { + pq.ctx.Fields = append([]string{field}, fields...) + grbuild := &ProfileGroupBy{build: pq} + grbuild.flds = &pq.ctx.Fields + grbuild.label = profile.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// } +// +// client.Profile.Query(). +// Select(profile.FieldCreatedAt). +// Scan(ctx, &v) +func (pq *ProfileQuery) Select(fields ...string) *ProfileSelect { + pq.ctx.Fields = append(pq.ctx.Fields, fields...) + sbuild := &ProfileSelect{ProfileQuery: pq} + sbuild.label = profile.Label + sbuild.flds, sbuild.scan = &pq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ProfileSelect configured with the given aggregations. +func (pq *ProfileQuery) Aggregate(fns ...AggregateFunc) *ProfileSelect { + return pq.Select().Aggregate(fns...) +} + +func (pq *ProfileQuery) prepareQuery(ctx context.Context) error { + for _, inter := range pq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, pq); err != nil { + return err + } + } + } + for _, f := range pq.ctx.Fields { + if !profile.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if pq.path != nil { + prev, err := pq.path(ctx) + if err != nil { + return err + } + pq.sql = prev + } + return nil +} + +func (pq *ProfileQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Profile, error) { + var ( + nodes = []*Profile{} + _spec = pq.querySpec() + loadedTypes = [1]bool{ + pq.withPosts != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Profile).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Profile{config: pq.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(pq.modifiers) > 0 { + _spec.Modifiers = pq.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, pq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := pq.withPosts; query != nil { + if err := pq.loadPosts(ctx, query, nodes, + func(n *Profile) { n.Edges.Posts = []*Post{} }, + func(n *Profile, e *Post) { n.Edges.Posts = append(n.Edges.Posts, e) }); err != nil { + return nil, err + } + } + for name, query := range pq.withNamedPosts { + if err := pq.loadPosts(ctx, query, nodes, + func(n *Profile) { n.appendNamedPosts(name) }, + func(n *Profile, e *Post) { n.appendNamedPosts(name, e) }); err != nil { + return nil, err + } + } + for i := range pq.loadTotal { + if err := pq.loadTotal[i](ctx, nodes); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (pq *ProfileQuery) loadPosts(ctx context.Context, query *PostQuery, nodes []*Profile, init func(*Profile), assign func(*Profile, *Post)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Profile) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + query.withFKs = true + query.Where(predicate.Post(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(profile.PostsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.profile_posts + if fk == nil { + return fmt.Errorf(`foreign-key "profile_posts" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "profile_posts" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} + +func (pq *ProfileQuery) sqlCount(ctx context.Context) (int, error) { + _spec := pq.querySpec() + if len(pq.modifiers) > 0 { + _spec.Modifiers = pq.modifiers + } + _spec.Node.Columns = pq.ctx.Fields + if len(pq.ctx.Fields) > 0 { + _spec.Unique = pq.ctx.Unique != nil && *pq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, pq.driver, _spec) +} + +func (pq *ProfileQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(profile.Table, profile.Columns, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID)) + _spec.From = pq.sql + if unique := pq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if pq.path != nil { + _spec.Unique = true + } + if fields := pq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, profile.FieldID) + for i := range fields { + if fields[i] != profile.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := pq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := pq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := pq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := pq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (pq *ProfileQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(pq.driver.Dialect()) + t1 := builder.Table(profile.Table) + columns := pq.ctx.Fields + if len(columns) == 0 { + columns = profile.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if pq.sql != nil { + selector = pq.sql + selector.Select(selector.Columns(columns...)...) + } + if pq.ctx.Unique != nil && *pq.ctx.Unique { + selector.Distinct() + } + for _, p := range pq.predicates { + p(selector) + } + for _, p := range pq.order { + p(selector) + } + if offset := pq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := pq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// WithNamedPosts tells the query-builder to eager-load the nodes that are connected to the "posts" +// edge with the given name. The optional arguments are used to configure the query builder of the edge. +func (pq *ProfileQuery) WithNamedPosts(name string, opts ...func(*PostQuery)) *ProfileQuery { + query := (&PostClient{config: pq.config}).Query() + for _, opt := range opts { + opt(query) + } + if pq.withNamedPosts == nil { + pq.withNamedPosts = make(map[string]*PostQuery) + } + pq.withNamedPosts[name] = query + return pq +} + +// ProfileGroupBy is the group-by builder for Profile entities. +type ProfileGroupBy struct { + selector + build *ProfileQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (pgb *ProfileGroupBy) Aggregate(fns ...AggregateFunc) *ProfileGroupBy { + pgb.fns = append(pgb.fns, fns...) + return pgb +} + +// Scan applies the selector query and scans the result into the given value. +func (pgb *ProfileGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, pgb.build.ctx, ent.OpQueryGroupBy) + if err := pgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*ProfileQuery, *ProfileGroupBy](ctx, pgb.build, pgb, pgb.build.inters, v) +} + +func (pgb *ProfileGroupBy) sqlScan(ctx context.Context, root *ProfileQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(pgb.fns)) + for _, fn := range pgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*pgb.flds)+len(pgb.fns)) + for _, f := range *pgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*pgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := pgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// ProfileSelect is the builder for selecting fields of Profile entities. +type ProfileSelect struct { + *ProfileQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ps *ProfileSelect) Aggregate(fns ...AggregateFunc) *ProfileSelect { + ps.fns = append(ps.fns, fns...) + return ps +} + +// Scan applies the selector query and scans the result into the given value. +func (ps *ProfileSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ps.ctx, ent.OpQuerySelect) + if err := ps.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*ProfileQuery, *ProfileSelect](ctx, ps.ProfileQuery, ps, ps.inters, v) +} + +func (ps *ProfileSelect) sqlScan(ctx context.Context, root *ProfileQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ps.fns)) + for _, fn := range ps.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ps.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := ps.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/profile_update.go b/ent/profile_update.go new file mode 100644 index 0000000..195e6b3 --- /dev/null +++ b/ent/profile_update.go @@ -0,0 +1,550 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/predicate" + "code.icod.de/dalu/ka/ent/profile" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// ProfileUpdate is the builder for updating Profile entities. +type ProfileUpdate struct { + config + hooks []Hook + mutation *ProfileMutation +} + +// Where appends a list predicates to the ProfileUpdate builder. +func (pu *ProfileUpdate) Where(ps ...predicate.Profile) *ProfileUpdate { + pu.mutation.Where(ps...) + return pu +} + +// SetUpdatedAt sets the "updated_at" field. +func (pu *ProfileUpdate) SetUpdatedAt(t time.Time) *ProfileUpdate { + pu.mutation.SetUpdatedAt(t) + return pu +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (pu *ProfileUpdate) ClearUpdatedAt() *ProfileUpdate { + pu.mutation.ClearUpdatedAt() + return pu +} + +// SetName sets the "name" field. +func (pu *ProfileUpdate) SetName(s string) *ProfileUpdate { + pu.mutation.SetName(s) + return pu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (pu *ProfileUpdate) SetNillableName(s *string) *ProfileUpdate { + if s != nil { + pu.SetName(*s) + } + return pu +} + +// ClearName clears the value of the "name" field. +func (pu *ProfileUpdate) ClearName() *ProfileUpdate { + pu.mutation.ClearName() + return pu +} + +// SetAddress sets the "address" field. +func (pu *ProfileUpdate) SetAddress(s string) *ProfileUpdate { + pu.mutation.SetAddress(s) + return pu +} + +// SetNillableAddress sets the "address" field if the given value is not nil. +func (pu *ProfileUpdate) SetNillableAddress(s *string) *ProfileUpdate { + if s != nil { + pu.SetAddress(*s) + } + return pu +} + +// ClearAddress clears the value of the "address" field. +func (pu *ProfileUpdate) ClearAddress() *ProfileUpdate { + pu.mutation.ClearAddress() + return pu +} + +// SetPhone sets the "phone" field. +func (pu *ProfileUpdate) SetPhone(s string) *ProfileUpdate { + pu.mutation.SetPhone(s) + return pu +} + +// SetNillablePhone sets the "phone" field if the given value is not nil. +func (pu *ProfileUpdate) SetNillablePhone(s *string) *ProfileUpdate { + if s != nil { + pu.SetPhone(*s) + } + return pu +} + +// ClearPhone clears the value of the "phone" field. +func (pu *ProfileUpdate) ClearPhone() *ProfileUpdate { + pu.mutation.ClearPhone() + return pu +} + +// AddPostIDs adds the "posts" edge to the Post entity by IDs. +func (pu *ProfileUpdate) AddPostIDs(ids ...uuid.UUID) *ProfileUpdate { + pu.mutation.AddPostIDs(ids...) + return pu +} + +// AddPosts adds the "posts" edges to the Post entity. +func (pu *ProfileUpdate) AddPosts(p ...*Post) *ProfileUpdate { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return pu.AddPostIDs(ids...) +} + +// Mutation returns the ProfileMutation object of the builder. +func (pu *ProfileUpdate) Mutation() *ProfileMutation { + return pu.mutation +} + +// ClearPosts clears all "posts" edges to the Post entity. +func (pu *ProfileUpdate) ClearPosts() *ProfileUpdate { + pu.mutation.ClearPosts() + return pu +} + +// RemovePostIDs removes the "posts" edge to Post entities by IDs. +func (pu *ProfileUpdate) RemovePostIDs(ids ...uuid.UUID) *ProfileUpdate { + pu.mutation.RemovePostIDs(ids...) + return pu +} + +// RemovePosts removes "posts" edges to Post entities. +func (pu *ProfileUpdate) RemovePosts(p ...*Post) *ProfileUpdate { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return pu.RemovePostIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (pu *ProfileUpdate) Save(ctx context.Context) (int, error) { + pu.defaults() + return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (pu *ProfileUpdate) SaveX(ctx context.Context) int { + affected, err := pu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (pu *ProfileUpdate) Exec(ctx context.Context) error { + _, err := pu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (pu *ProfileUpdate) ExecX(ctx context.Context) { + if err := pu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (pu *ProfileUpdate) defaults() { + if _, ok := pu.mutation.UpdatedAt(); !ok && !pu.mutation.UpdatedAtCleared() { + v := profile.UpdateDefaultUpdatedAt() + pu.mutation.SetUpdatedAt(v) + } +} + +func (pu *ProfileUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := sqlgraph.NewUpdateSpec(profile.Table, profile.Columns, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID)) + if ps := pu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := pu.mutation.UpdatedAt(); ok { + _spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value) + } + if pu.mutation.UpdatedAtCleared() { + _spec.ClearField(profile.FieldUpdatedAt, field.TypeTime) + } + if value, ok := pu.mutation.Name(); ok { + _spec.SetField(profile.FieldName, field.TypeString, value) + } + if pu.mutation.NameCleared() { + _spec.ClearField(profile.FieldName, field.TypeString) + } + if value, ok := pu.mutation.Address(); ok { + _spec.SetField(profile.FieldAddress, field.TypeString, value) + } + if pu.mutation.AddressCleared() { + _spec.ClearField(profile.FieldAddress, field.TypeString) + } + if value, ok := pu.mutation.Phone(); ok { + _spec.SetField(profile.FieldPhone, field.TypeString, value) + } + if pu.mutation.PhoneCleared() { + _spec.ClearField(profile.FieldPhone, field.TypeString) + } + if pu.mutation.PostsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: profile.PostsTable, + Columns: []string{profile.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := pu.mutation.RemovedPostsIDs(); len(nodes) > 0 && !pu.mutation.PostsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: profile.PostsTable, + Columns: []string{profile.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := pu.mutation.PostsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: profile.PostsTable, + Columns: []string{profile.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{profile.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + pu.mutation.done = true + return n, nil +} + +// ProfileUpdateOne is the builder for updating a single Profile entity. +type ProfileUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ProfileMutation +} + +// SetUpdatedAt sets the "updated_at" field. +func (puo *ProfileUpdateOne) SetUpdatedAt(t time.Time) *ProfileUpdateOne { + puo.mutation.SetUpdatedAt(t) + return puo +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (puo *ProfileUpdateOne) ClearUpdatedAt() *ProfileUpdateOne { + puo.mutation.ClearUpdatedAt() + return puo +} + +// SetName sets the "name" field. +func (puo *ProfileUpdateOne) SetName(s string) *ProfileUpdateOne { + puo.mutation.SetName(s) + return puo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (puo *ProfileUpdateOne) SetNillableName(s *string) *ProfileUpdateOne { + if s != nil { + puo.SetName(*s) + } + return puo +} + +// ClearName clears the value of the "name" field. +func (puo *ProfileUpdateOne) ClearName() *ProfileUpdateOne { + puo.mutation.ClearName() + return puo +} + +// SetAddress sets the "address" field. +func (puo *ProfileUpdateOne) SetAddress(s string) *ProfileUpdateOne { + puo.mutation.SetAddress(s) + return puo +} + +// SetNillableAddress sets the "address" field if the given value is not nil. +func (puo *ProfileUpdateOne) SetNillableAddress(s *string) *ProfileUpdateOne { + if s != nil { + puo.SetAddress(*s) + } + return puo +} + +// ClearAddress clears the value of the "address" field. +func (puo *ProfileUpdateOne) ClearAddress() *ProfileUpdateOne { + puo.mutation.ClearAddress() + return puo +} + +// SetPhone sets the "phone" field. +func (puo *ProfileUpdateOne) SetPhone(s string) *ProfileUpdateOne { + puo.mutation.SetPhone(s) + return puo +} + +// SetNillablePhone sets the "phone" field if the given value is not nil. +func (puo *ProfileUpdateOne) SetNillablePhone(s *string) *ProfileUpdateOne { + if s != nil { + puo.SetPhone(*s) + } + return puo +} + +// ClearPhone clears the value of the "phone" field. +func (puo *ProfileUpdateOne) ClearPhone() *ProfileUpdateOne { + puo.mutation.ClearPhone() + return puo +} + +// AddPostIDs adds the "posts" edge to the Post entity by IDs. +func (puo *ProfileUpdateOne) AddPostIDs(ids ...uuid.UUID) *ProfileUpdateOne { + puo.mutation.AddPostIDs(ids...) + return puo +} + +// AddPosts adds the "posts" edges to the Post entity. +func (puo *ProfileUpdateOne) AddPosts(p ...*Post) *ProfileUpdateOne { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return puo.AddPostIDs(ids...) +} + +// Mutation returns the ProfileMutation object of the builder. +func (puo *ProfileUpdateOne) Mutation() *ProfileMutation { + return puo.mutation +} + +// ClearPosts clears all "posts" edges to the Post entity. +func (puo *ProfileUpdateOne) ClearPosts() *ProfileUpdateOne { + puo.mutation.ClearPosts() + return puo +} + +// RemovePostIDs removes the "posts" edge to Post entities by IDs. +func (puo *ProfileUpdateOne) RemovePostIDs(ids ...uuid.UUID) *ProfileUpdateOne { + puo.mutation.RemovePostIDs(ids...) + return puo +} + +// RemovePosts removes "posts" edges to Post entities. +func (puo *ProfileUpdateOne) RemovePosts(p ...*Post) *ProfileUpdateOne { + ids := make([]uuid.UUID, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return puo.RemovePostIDs(ids...) +} + +// Where appends a list predicates to the ProfileUpdate builder. +func (puo *ProfileUpdateOne) Where(ps ...predicate.Profile) *ProfileUpdateOne { + puo.mutation.Where(ps...) + return puo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (puo *ProfileUpdateOne) Select(field string, fields ...string) *ProfileUpdateOne { + puo.fields = append([]string{field}, fields...) + return puo +} + +// Save executes the query and returns the updated Profile entity. +func (puo *ProfileUpdateOne) Save(ctx context.Context) (*Profile, error) { + puo.defaults() + return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (puo *ProfileUpdateOne) SaveX(ctx context.Context) *Profile { + node, err := puo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (puo *ProfileUpdateOne) Exec(ctx context.Context) error { + _, err := puo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (puo *ProfileUpdateOne) ExecX(ctx context.Context) { + if err := puo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (puo *ProfileUpdateOne) defaults() { + if _, ok := puo.mutation.UpdatedAt(); !ok && !puo.mutation.UpdatedAtCleared() { + v := profile.UpdateDefaultUpdatedAt() + puo.mutation.SetUpdatedAt(v) + } +} + +func (puo *ProfileUpdateOne) sqlSave(ctx context.Context) (_node *Profile, err error) { + _spec := sqlgraph.NewUpdateSpec(profile.Table, profile.Columns, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID)) + id, ok := puo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Profile.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := puo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, profile.FieldID) + for _, f := range fields { + if !profile.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != profile.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := puo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := puo.mutation.UpdatedAt(); ok { + _spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value) + } + if puo.mutation.UpdatedAtCleared() { + _spec.ClearField(profile.FieldUpdatedAt, field.TypeTime) + } + if value, ok := puo.mutation.Name(); ok { + _spec.SetField(profile.FieldName, field.TypeString, value) + } + if puo.mutation.NameCleared() { + _spec.ClearField(profile.FieldName, field.TypeString) + } + if value, ok := puo.mutation.Address(); ok { + _spec.SetField(profile.FieldAddress, field.TypeString, value) + } + if puo.mutation.AddressCleared() { + _spec.ClearField(profile.FieldAddress, field.TypeString) + } + if value, ok := puo.mutation.Phone(); ok { + _spec.SetField(profile.FieldPhone, field.TypeString, value) + } + if puo.mutation.PhoneCleared() { + _spec.ClearField(profile.FieldPhone, field.TypeString) + } + if puo.mutation.PostsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: profile.PostsTable, + Columns: []string{profile.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := puo.mutation.RemovedPostsIDs(); len(nodes) > 0 && !puo.mutation.PostsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: profile.PostsTable, + Columns: []string{profile.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := puo.mutation.PostsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: profile.PostsTable, + Columns: []string{profile.PostsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Profile{config: puo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{profile.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + puo.mutation.done = true + return _node, nil +} diff --git a/ent/runtime.go b/ent/runtime.go new file mode 100644 index 0000000..8944487 --- /dev/null +++ b/ent/runtime.go @@ -0,0 +1,83 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "time" + + "code.icod.de/dalu/ka/ent/category" + "code.icod.de/dalu/ka/ent/post" + "code.icod.de/dalu/ka/ent/profile" + "code.icod.de/dalu/ka/ent/schema" + "github.com/google/uuid" +) + +// The init function reads all schema descriptors with runtime code +// (default values, validators, hooks and policies) and stitches it +// to their package variables. +func init() { + categoryFields := schema.Category{}.Fields() + _ = categoryFields + // categoryDescCreatedAt is the schema descriptor for created_at field. + categoryDescCreatedAt := categoryFields[1].Descriptor() + // category.DefaultCreatedAt holds the default value on creation for the created_at field. + category.DefaultCreatedAt = categoryDescCreatedAt.Default.(func() time.Time) + // categoryDescUpdatedAt is the schema descriptor for updated_at field. + categoryDescUpdatedAt := categoryFields[2].Descriptor() + // category.DefaultUpdatedAt holds the default value on creation for the updated_at field. + category.DefaultUpdatedAt = categoryDescUpdatedAt.Default.(func() time.Time) + // category.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + category.UpdateDefaultUpdatedAt = categoryDescUpdatedAt.UpdateDefault.(func() time.Time) + // categoryDescTitle is the schema descriptor for title field. + categoryDescTitle := categoryFields[3].Descriptor() + // category.TitleValidator is a validator for the "title" field. It is called by the builders before save. + category.TitleValidator = categoryDescTitle.Validators[0].(func(string) error) + // categoryDescID is the schema descriptor for id field. + categoryDescID := categoryFields[0].Descriptor() + // category.DefaultID holds the default value on creation for the id field. + category.DefaultID = categoryDescID.Default.(func() uuid.UUID) + postFields := schema.Post{}.Fields() + _ = postFields + // postDescCreatedAt is the schema descriptor for created_at field. + postDescCreatedAt := postFields[1].Descriptor() + // post.DefaultCreatedAt holds the default value on creation for the created_at field. + post.DefaultCreatedAt = postDescCreatedAt.Default.(func() time.Time) + // postDescUpdatedAt is the schema descriptor for updated_at field. + postDescUpdatedAt := postFields[2].Descriptor() + // post.DefaultUpdatedAt holds the default value on creation for the updated_at field. + post.DefaultUpdatedAt = postDescUpdatedAt.Default.(func() time.Time) + // post.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + post.UpdateDefaultUpdatedAt = postDescUpdatedAt.UpdateDefault.(func() time.Time) + // postDescExpires is the schema descriptor for expires field. + postDescExpires := postFields[3].Descriptor() + // post.DefaultExpires holds the default value on creation for the expires field. + post.DefaultExpires = postDescExpires.Default.(bool) + // postDescTitle is the schema descriptor for title field. + postDescTitle := postFields[5].Descriptor() + // post.TitleValidator is a validator for the "title" field. It is called by the builders before save. + post.TitleValidator = postDescTitle.Validators[0].(func(string) error) + // postDescBody is the schema descriptor for body field. + postDescBody := postFields[6].Descriptor() + // post.BodyValidator is a validator for the "body" field. It is called by the builders before save. + post.BodyValidator = postDescBody.Validators[0].(func(string) error) + // postDescID is the schema descriptor for id field. + postDescID := postFields[0].Descriptor() + // post.DefaultID holds the default value on creation for the id field. + post.DefaultID = postDescID.Default.(func() uuid.UUID) + profileFields := schema.Profile{}.Fields() + _ = profileFields + // profileDescCreatedAt is the schema descriptor for created_at field. + profileDescCreatedAt := profileFields[1].Descriptor() + // profile.DefaultCreatedAt holds the default value on creation for the created_at field. + profile.DefaultCreatedAt = profileDescCreatedAt.Default.(func() time.Time) + // profileDescUpdatedAt is the schema descriptor for updated_at field. + profileDescUpdatedAt := profileFields[2].Descriptor() + // profile.DefaultUpdatedAt holds the default value on creation for the updated_at field. + profile.DefaultUpdatedAt = profileDescUpdatedAt.Default.(func() time.Time) + // profile.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + profile.UpdateDefaultUpdatedAt = profileDescUpdatedAt.UpdateDefault.(func() time.Time) + // profileDescID is the schema descriptor for id field. + profileDescID := profileFields[0].Descriptor() + // profile.DefaultID holds the default value on creation for the id field. + profile.DefaultID = profileDescID.Default.(func() uuid.UUID) +} diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go new file mode 100644 index 0000000..36e5229 --- /dev/null +++ b/ent/runtime/runtime.go @@ -0,0 +1,10 @@ +// Code generated by ent, DO NOT EDIT. + +package runtime + +// The schema-stitching logic is generated in code.icod.de/dalu/ka/ent/runtime.go + +const ( + Version = "v0.14.1" // Version of ent codegen. + Sum = "h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s=" // Sum of ent codegen. +) diff --git a/ent/tx.go b/ent/tx.go new file mode 100644 index 0000000..a604315 --- /dev/null +++ b/ent/tx.go @@ -0,0 +1,216 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "sync" + + "entgo.io/ent/dialect" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // Category is the client for interacting with the Category builders. + Category *CategoryClient + // Post is the client for interacting with the Post builders. + Post *PostClient + // Profile is the client for interacting with the Profile builders. + Profile *ProfileClient + + // lazily loaded. + client *Client + clientOnce sync.Once + // ctx lives for the life of the transaction. It is + // the same context used by the underlying connection. + ctx context.Context +} + +type ( + // Committer is the interface that wraps the Commit method. + Committer interface { + Commit(context.Context, *Tx) error + } + + // The CommitFunc type is an adapter to allow the use of ordinary + // function as a Committer. If f is a function with the appropriate + // signature, CommitFunc(f) is a Committer that calls f. + CommitFunc func(context.Context, *Tx) error + + // CommitHook defines the "commit middleware". A function that gets a Committer + // and returns a Committer. For example: + // + // hook := func(next ent.Committer) ent.Committer { + // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Commit(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + CommitHook func(Committer) Committer +) + +// Commit calls f(ctx, m). +func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + txDriver := tx.config.driver.(*txDriver) + var fn Committer = CommitFunc(func(context.Context, *Tx) error { + return txDriver.tx.Commit() + }) + txDriver.mu.Lock() + hooks := append([]CommitHook(nil), txDriver.onCommit...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Commit(tx.ctx, tx) +} + +// OnCommit adds a hook to call on commit. +func (tx *Tx) OnCommit(f CommitHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onCommit = append(txDriver.onCommit, f) + txDriver.mu.Unlock() +} + +type ( + // Rollbacker is the interface that wraps the Rollback method. + Rollbacker interface { + Rollback(context.Context, *Tx) error + } + + // The RollbackFunc type is an adapter to allow the use of ordinary + // function as a Rollbacker. If f is a function with the appropriate + // signature, RollbackFunc(f) is a Rollbacker that calls f. + RollbackFunc func(context.Context, *Tx) error + + // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker + // and returns a Rollbacker. For example: + // + // hook := func(next ent.Rollbacker) ent.Rollbacker { + // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Rollback(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + RollbackHook func(Rollbacker) Rollbacker +) + +// Rollback calls f(ctx, m). +func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + txDriver := tx.config.driver.(*txDriver) + var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { + return txDriver.tx.Rollback() + }) + txDriver.mu.Lock() + hooks := append([]RollbackHook(nil), txDriver.onRollback...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Rollback(tx.ctx, tx) +} + +// OnRollback adds a hook to call on rollback. +func (tx *Tx) OnRollback(f RollbackHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onRollback = append(txDriver.onRollback, f) + txDriver.mu.Unlock() +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + tx.clientOnce.Do(func() { + tx.client = &Client{config: tx.config} + tx.client.init() + }) + return tx.client +} + +func (tx *Tx) init() { + tx.Category = NewCategoryClient(tx.config) + tx.Post = NewPostClient(tx.config) + tx.Profile = NewProfileClient(tx.config) +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: Category.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that txDriver is not goroutine safe. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // tx is the underlying transaction. + tx dialect.Tx + // completion hooks. + mu sync.Mutex + onCommit []CommitHook + onRollback []RollbackHook +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil) diff --git a/go.mod b/go.mod index 4f584b2..5b94776 100644 --- a/go.mod +++ b/go.mod @@ -2,36 +2,40 @@ module code.icod.de/dalu/ka go 1.23.1 -require entgo.io/ent v0.14.1 +require ( + entgo.io/ent v0.14.1 + github.com/99designs/gqlgen v0.17.55 + github.com/google/uuid v1.6.0 + github.com/hashicorp/go-multierror v1.1.1 + github.com/vektah/gqlparser/v2 v2.5.17 +) require ( - ariga.io/atlas v0.25.1-0.20240717145915-af51d3945208 // indirect - github.com/99designs/gqlgen v0.17.48 // indirect - github.com/agext/levenshtein v1.2.1 // indirect - github.com/agnivade/levenshtein v1.1.1 // indirect - github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + ariga.io/atlas v0.28.0 // indirect + github.com/agext/levenshtein v1.2.3 // indirect + github.com/agnivade/levenshtein v1.2.0 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect - github.com/go-openapi/inflect v0.19.0 // indirect + github.com/bmatcuk/doublestar v1.3.4 // indirect + github.com/go-openapi/inflect v0.21.0 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/hashicorp/hcl/v2 v2.13.0 // indirect - github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/hcl/v2 v2.22.0 // indirect + github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/sosodev/duration v1.3.1 // indirect - github.com/vektah/gqlparser/v2 v2.5.12 // indirect - github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect + github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/zclconf/go-cty v1.14.4 // indirect - golang.org/x/exp v0.0.0-20221230185412-738e83a70c30 // indirect - golang.org/x/mod v0.20.0 // indirect + github.com/zclconf/go-cty v1.15.0 // indirect + golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect + golang.org/x/mod v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/text v0.15.0 // indirect - golang.org/x/tools v0.24.0 // indirect + golang.org/x/text v0.19.0 // indirect + golang.org/x/tools v0.25.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) require ( entgo.io/contrib v0.6.0 github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/cobra v1.8.1 // indirect + github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 // indirect ) diff --git a/go.sum b/go.sum index 1e807d1..50a29fa 100644 --- a/go.sum +++ b/go.sum @@ -1,75 +1,95 @@ -ariga.io/atlas v0.25.1-0.20240717145915-af51d3945208 h1:ixs1c/fAXGS3mTdalyKQrtvfkFjgChih/unX66YTzYk= -ariga.io/atlas v0.25.1-0.20240717145915-af51d3945208/go.mod h1:KPLc7Zj+nzoXfWshrcY1RwlOh94dsATQEy4UPrF2RkM= +ariga.io/atlas v0.28.0 h1:qmn9tUyJypJkIw+X3ECUwDtkMTiFupgstHbjRN4xGH0= +ariga.io/atlas v0.28.0/go.mod h1:LOOp18LCL9r+VifvVlJqgYJwYl271rrXD9/wIyzJ8sw= entgo.io/contrib v0.6.0 h1:xfo4TbJE7sJZWx7BV7YrpSz7IPFvS8MzL3fnfzZjKvQ= entgo.io/contrib v0.6.0/go.mod h1:3qWIseJ/9Wx2Hu5zVh15FDzv7d/UvKNcYKdViywWCQg= entgo.io/ent v0.14.1 h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s= entgo.io/ent v0.14.1/go.mod h1:MH6XLG0KXpkcDQhKiHfANZSzR55TJyPL5IGNpI8wpco= -github.com/99designs/gqlgen v0.17.48 h1:Wgk7n9PIdnmpsC1aJJV4eiZCGkAkoamKOtXAp/crpzQ= -github.com/99designs/gqlgen v0.17.48/go.mod h1:hYeQ+ygPbcapbaHtHMbZ1DHMVNT+1tGU+fI+Hy4kqIo= -github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= -github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= -github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= -github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= -github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= -github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/99designs/gqlgen v0.17.55 h1:3vzrNWYyzSZjGDFo68e5j9sSauLxfKvLp+6ioRokVtM= +github.com/99designs/gqlgen v0.17.55/go.mod h1:3Bq768f8hgVPGZxL8aY9MaYmbxa6llPM/qu1IGH1EJo= +github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= +github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/agnivade/levenshtein v1.2.0 h1:U9L4IOT0Y3i0TIlUIDJ7rVUziKi/zPbrJGaFrtYH3SY= +github.com/agnivade/levenshtein v1.2.0/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= +github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= +github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= -github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= -github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= +github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7cNTs5R6Hk4V2lcmLz2NsG2VnInyNo= +github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= +github.com/go-openapi/inflect v0.21.0 h1:FoBjBTQEcbg2cJUWX6uwL9OyIW8eqc9k4KhN4lfbeYk= +github.com/go-openapi/inflect v0.21.0/go.mod h1:INezMuUu7SJQc2AyR3WO0DqqYUJSj8Kb4hBd7WtjlAw= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= -github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= +github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= -github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= +github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= +github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4= github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/vektah/gqlparser/v2 v2.5.12 h1:COMhVVnql6RoaF7+aTBWiTADdpLGyZWU3K/NwW0ph98= -github.com/vektah/gqlparser/v2 v2.5.12/go.mod h1:WQQjFc+I1YIzoPvZBhUQX7waZgg3pMLi0r8KymvAE2w= -github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= -github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vektah/gqlparser/v2 v2.5.17 h1:9At7WblLV7/36nulgekUgIaqHZWn5hxqluxrxGUhOmI= +github.com/vektah/gqlparser/v2 v2.5.17/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww= +github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= +github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= -github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -golang.org/x/exp v0.0.0-20221230185412-738e83a70c30 h1:m9O6OTJ627iFnN2JIWfdqlZCzneRO6EEBsHXI25P8ws= -golang.org/x/exp v0.0.0-20221230185412-738e83a70c30/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= -golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= -golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= +github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE= +golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/gqlgen.yml b/gqlgen.yml index b1dd6f0..e06e8ac 100644 --- a/gqlgen.yml +++ b/gqlgen.yml @@ -1,7 +1,7 @@ # schema tells gqlgen when the GraphQL schema is located. schema: - ent.graphql - - exyu.graphql + - ka.graphql # Where should the generated server code go? exec: @@ -14,7 +14,6 @@ resolver: layout: follow-schema dir: graph package: graph - filename_template: "{name}.resolvers.go" # gqlgen will search for any type names in the schema in these go packages # if they match it will use them, otherwise it will generate them. @@ -23,8 +22,8 @@ resolver: # provided package. If they match it will use them, otherwise it will generate new. autobind: - code.icod.de/dalu/ka/ent - - code.icod.de/dalu/ka/ent/post - code.icod.de/dalu/ka/ent/category + - code.icod.de/dalu/ka/ent/post - code.icod.de/dalu/ka/ent/profile # This section declares type mapping between the GraphQL and Go type systems. diff --git a/graph/ent.resolvers.go b/graph/ent.resolvers.go new file mode 100644 index 0000000..4a478b3 --- /dev/null +++ b/graph/ent.resolvers.go @@ -0,0 +1,44 @@ +package graph + +// This file will be automatically regenerated based on the schema, any resolver implementations +// will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.55 + +import ( + "context" + + "code.icod.de/dalu/ka/ent" + "code.icod.de/dalu/ka/graph/generated" + "entgo.io/contrib/entgql" + "github.com/google/uuid" +) + +// Node is the resolver for the node field. +func (r *queryResolver) Node(ctx context.Context, id uuid.UUID) (ent.Noder, error) { + return r.client.Noder(ctx, id) +} + +// Nodes is the resolver for the nodes field. +func (r *queryResolver) Nodes(ctx context.Context, ids []uuid.UUID) ([]ent.Noder, error) { + return r.client.Noders(ctx, ids) +} + +// Categories is the resolver for the categories field. +func (r *queryResolver) Categories(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.CategoryOrder, where *ent.CategoryWhereInput) (*ent.CategoryConnection, error) { + return r.client.Category.Query().Paginate(ctx, after, first, before, last, ent.WithCategoryOrder(orderBy), ent.WithCategoryFilter(where.Filter)) +} + +// Posts is the resolver for the posts field. +func (r *queryResolver) Posts(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.PostOrder, where *ent.PostWhereInput) (*ent.PostConnection, error) { + return r.client.Post.Query().Paginate(ctx, after, first, before, last, ent.WithPostOrder(orderBy), ent.WithPostFilter(where.Filter)) +} + +// Profiles is the resolver for the profiles field. +func (r *queryResolver) Profiles(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.ProfileOrder, where *ent.ProfileWhereInput) (*ent.ProfileConnection, error) { + return r.client.Profile.Query().Paginate(ctx, after, first, before, last, ent.WithProfileOrder(orderBy), ent.WithProfileFilter(where.Filter)) +} + +// Query returns generated.QueryResolver implementation. +func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} } + +type queryResolver struct{ *Resolver } diff --git a/graph/generated/ent.generated.go b/graph/generated/ent.generated.go new file mode 100644 index 0000000..5592f74 --- /dev/null +++ b/graph/generated/ent.generated.go @@ -0,0 +1,6749 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package generated + +import ( + "context" + "errors" + "fmt" + "strconv" + "sync" + "sync/atomic" + "time" + + "code.icod.de/dalu/ka/ent" + "entgo.io/contrib/entgql" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + "github.com/google/uuid" + "github.com/vektah/gqlparser/v2/ast" +) + +// region ************************** generated!.gotpl ************************** + +type QueryResolver interface { + Node(ctx context.Context, id uuid.UUID) (ent.Noder, error) + Nodes(ctx context.Context, ids []uuid.UUID) ([]ent.Noder, error) + Categories(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.CategoryOrder, where *ent.CategoryWhereInput) (*ent.CategoryConnection, error) + Posts(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.PostOrder, where *ent.PostWhereInput) (*ent.PostConnection, error) + Profiles(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.ProfileOrder, where *ent.ProfileWhereInput) (*ent.ProfileConnection, error) +} + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Category_posts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field_Category_posts_argsAfter(ctx, rawArgs) + if err != nil { + return nil, err + } + args["after"] = arg0 + arg1, err := ec.field_Category_posts_argsFirst(ctx, rawArgs) + if err != nil { + return nil, err + } + args["first"] = arg1 + arg2, err := ec.field_Category_posts_argsBefore(ctx, rawArgs) + if err != nil { + return nil, err + } + args["before"] = arg2 + arg3, err := ec.field_Category_posts_argsLast(ctx, rawArgs) + if err != nil { + return nil, err + } + args["last"] = arg3 + arg4, err := ec.field_Category_posts_argsOrderBy(ctx, rawArgs) + if err != nil { + return nil, err + } + args["orderBy"] = arg4 + arg5, err := ec.field_Category_posts_argsWhere(ctx, rawArgs) + if err != nil { + return nil, err + } + args["where"] = arg5 + return args, nil +} +func (ec *executionContext) field_Category_posts_argsAfter( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["after"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + if tmp, ok := rawArgs["after"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Category_posts_argsFirst( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["first"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + if tmp, ok := rawArgs["first"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Category_posts_argsBefore( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["before"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("before")) + if tmp, ok := rawArgs["before"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Category_posts_argsLast( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["last"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("last")) + if tmp, ok := rawArgs["last"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Category_posts_argsOrderBy( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.PostOrder, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["orderBy"] + if !ok { + var zeroVal *ent.PostOrder + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("orderBy")) + if tmp, ok := rawArgs["orderBy"]; ok { + return ec.unmarshalOPostOrder2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostOrder(ctx, tmp) + } + + var zeroVal *ent.PostOrder + return zeroVal, nil +} + +func (ec *executionContext) field_Category_posts_argsWhere( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.PostWhereInput, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["where"] + if !ok { + var zeroVal *ent.PostWhereInput + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("where")) + if tmp, ok := rawArgs["where"]; ok { + return ec.unmarshalOPostWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInput(ctx, tmp) + } + + var zeroVal *ent.PostWhereInput + return zeroVal, nil +} + +func (ec *executionContext) field_Profile_posts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field_Profile_posts_argsAfter(ctx, rawArgs) + if err != nil { + return nil, err + } + args["after"] = arg0 + arg1, err := ec.field_Profile_posts_argsFirst(ctx, rawArgs) + if err != nil { + return nil, err + } + args["first"] = arg1 + arg2, err := ec.field_Profile_posts_argsBefore(ctx, rawArgs) + if err != nil { + return nil, err + } + args["before"] = arg2 + arg3, err := ec.field_Profile_posts_argsLast(ctx, rawArgs) + if err != nil { + return nil, err + } + args["last"] = arg3 + arg4, err := ec.field_Profile_posts_argsOrderBy(ctx, rawArgs) + if err != nil { + return nil, err + } + args["orderBy"] = arg4 + arg5, err := ec.field_Profile_posts_argsWhere(ctx, rawArgs) + if err != nil { + return nil, err + } + args["where"] = arg5 + return args, nil +} +func (ec *executionContext) field_Profile_posts_argsAfter( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["after"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + if tmp, ok := rawArgs["after"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Profile_posts_argsFirst( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["first"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + if tmp, ok := rawArgs["first"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Profile_posts_argsBefore( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["before"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("before")) + if tmp, ok := rawArgs["before"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Profile_posts_argsLast( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["last"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("last")) + if tmp, ok := rawArgs["last"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Profile_posts_argsOrderBy( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.PostOrder, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["orderBy"] + if !ok { + var zeroVal *ent.PostOrder + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("orderBy")) + if tmp, ok := rawArgs["orderBy"]; ok { + return ec.unmarshalOPostOrder2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostOrder(ctx, tmp) + } + + var zeroVal *ent.PostOrder + return zeroVal, nil +} + +func (ec *executionContext) field_Profile_posts_argsWhere( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.PostWhereInput, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["where"] + if !ok { + var zeroVal *ent.PostWhereInput + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("where")) + if tmp, ok := rawArgs["where"]; ok { + return ec.unmarshalOPostWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInput(ctx, tmp) + } + + var zeroVal *ent.PostWhereInput + return zeroVal, nil +} + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field_Query___type_argsName(ctx, rawArgs) + if err != nil { + return nil, err + } + args["name"] = arg0 + return args, nil +} +func (ec *executionContext) field_Query___type_argsName( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["name"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + if tmp, ok := rawArgs["name"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_categories_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field_Query_categories_argsAfter(ctx, rawArgs) + if err != nil { + return nil, err + } + args["after"] = arg0 + arg1, err := ec.field_Query_categories_argsFirst(ctx, rawArgs) + if err != nil { + return nil, err + } + args["first"] = arg1 + arg2, err := ec.field_Query_categories_argsBefore(ctx, rawArgs) + if err != nil { + return nil, err + } + args["before"] = arg2 + arg3, err := ec.field_Query_categories_argsLast(ctx, rawArgs) + if err != nil { + return nil, err + } + args["last"] = arg3 + arg4, err := ec.field_Query_categories_argsOrderBy(ctx, rawArgs) + if err != nil { + return nil, err + } + args["orderBy"] = arg4 + arg5, err := ec.field_Query_categories_argsWhere(ctx, rawArgs) + if err != nil { + return nil, err + } + args["where"] = arg5 + return args, nil +} +func (ec *executionContext) field_Query_categories_argsAfter( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["after"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + if tmp, ok := rawArgs["after"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Query_categories_argsFirst( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["first"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + if tmp, ok := rawArgs["first"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Query_categories_argsBefore( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["before"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("before")) + if tmp, ok := rawArgs["before"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Query_categories_argsLast( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["last"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("last")) + if tmp, ok := rawArgs["last"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Query_categories_argsOrderBy( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.CategoryOrder, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["orderBy"] + if !ok { + var zeroVal *ent.CategoryOrder + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("orderBy")) + if tmp, ok := rawArgs["orderBy"]; ok { + return ec.unmarshalOCategoryOrder2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryOrder(ctx, tmp) + } + + var zeroVal *ent.CategoryOrder + return zeroVal, nil +} + +func (ec *executionContext) field_Query_categories_argsWhere( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.CategoryWhereInput, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["where"] + if !ok { + var zeroVal *ent.CategoryWhereInput + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("where")) + if tmp, ok := rawArgs["where"]; ok { + return ec.unmarshalOCategoryWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInput(ctx, tmp) + } + + var zeroVal *ent.CategoryWhereInput + return zeroVal, nil +} + +func (ec *executionContext) field_Query_node_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field_Query_node_argsID(ctx, rawArgs) + if err != nil { + return nil, err + } + args["id"] = arg0 + return args, nil +} +func (ec *executionContext) field_Query_node_argsID( + ctx context.Context, + rawArgs map[string]interface{}, +) (uuid.UUID, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["id"] + if !ok { + var zeroVal uuid.UUID + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + if tmp, ok := rawArgs["id"]; ok { + return ec.unmarshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, tmp) + } + + var zeroVal uuid.UUID + return zeroVal, nil +} + +func (ec *executionContext) field_Query_nodes_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field_Query_nodes_argsIds(ctx, rawArgs) + if err != nil { + return nil, err + } + args["ids"] = arg0 + return args, nil +} +func (ec *executionContext) field_Query_nodes_argsIds( + ctx context.Context, + rawArgs map[string]interface{}, +) ([]uuid.UUID, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["ids"] + if !ok { + var zeroVal []uuid.UUID + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("ids")) + if tmp, ok := rawArgs["ids"]; ok { + return ec.unmarshalNID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, tmp) + } + + var zeroVal []uuid.UUID + return zeroVal, nil +} + +func (ec *executionContext) field_Query_posts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field_Query_posts_argsAfter(ctx, rawArgs) + if err != nil { + return nil, err + } + args["after"] = arg0 + arg1, err := ec.field_Query_posts_argsFirst(ctx, rawArgs) + if err != nil { + return nil, err + } + args["first"] = arg1 + arg2, err := ec.field_Query_posts_argsBefore(ctx, rawArgs) + if err != nil { + return nil, err + } + args["before"] = arg2 + arg3, err := ec.field_Query_posts_argsLast(ctx, rawArgs) + if err != nil { + return nil, err + } + args["last"] = arg3 + arg4, err := ec.field_Query_posts_argsOrderBy(ctx, rawArgs) + if err != nil { + return nil, err + } + args["orderBy"] = arg4 + arg5, err := ec.field_Query_posts_argsWhere(ctx, rawArgs) + if err != nil { + return nil, err + } + args["where"] = arg5 + return args, nil +} +func (ec *executionContext) field_Query_posts_argsAfter( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["after"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + if tmp, ok := rawArgs["after"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Query_posts_argsFirst( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["first"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + if tmp, ok := rawArgs["first"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Query_posts_argsBefore( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["before"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("before")) + if tmp, ok := rawArgs["before"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Query_posts_argsLast( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["last"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("last")) + if tmp, ok := rawArgs["last"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Query_posts_argsOrderBy( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.PostOrder, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["orderBy"] + if !ok { + var zeroVal *ent.PostOrder + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("orderBy")) + if tmp, ok := rawArgs["orderBy"]; ok { + return ec.unmarshalOPostOrder2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostOrder(ctx, tmp) + } + + var zeroVal *ent.PostOrder + return zeroVal, nil +} + +func (ec *executionContext) field_Query_posts_argsWhere( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.PostWhereInput, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["where"] + if !ok { + var zeroVal *ent.PostWhereInput + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("where")) + if tmp, ok := rawArgs["where"]; ok { + return ec.unmarshalOPostWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInput(ctx, tmp) + } + + var zeroVal *ent.PostWhereInput + return zeroVal, nil +} + +func (ec *executionContext) field_Query_profiles_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field_Query_profiles_argsAfter(ctx, rawArgs) + if err != nil { + return nil, err + } + args["after"] = arg0 + arg1, err := ec.field_Query_profiles_argsFirst(ctx, rawArgs) + if err != nil { + return nil, err + } + args["first"] = arg1 + arg2, err := ec.field_Query_profiles_argsBefore(ctx, rawArgs) + if err != nil { + return nil, err + } + args["before"] = arg2 + arg3, err := ec.field_Query_profiles_argsLast(ctx, rawArgs) + if err != nil { + return nil, err + } + args["last"] = arg3 + arg4, err := ec.field_Query_profiles_argsOrderBy(ctx, rawArgs) + if err != nil { + return nil, err + } + args["orderBy"] = arg4 + arg5, err := ec.field_Query_profiles_argsWhere(ctx, rawArgs) + if err != nil { + return nil, err + } + args["where"] = arg5 + return args, nil +} +func (ec *executionContext) field_Query_profiles_argsAfter( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["after"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + if tmp, ok := rawArgs["after"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Query_profiles_argsFirst( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["first"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + if tmp, ok := rawArgs["first"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Query_profiles_argsBefore( + ctx context.Context, + rawArgs map[string]interface{}, +) (*entgql.Cursor[uuid.UUID], error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["before"] + if !ok { + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("before")) + if tmp, ok := rawArgs["before"]; ok { + return ec.unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, tmp) + } + + var zeroVal *entgql.Cursor[uuid.UUID] + return zeroVal, nil +} + +func (ec *executionContext) field_Query_profiles_argsLast( + ctx context.Context, + rawArgs map[string]interface{}, +) (*int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["last"] + if !ok { + var zeroVal *int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("last")) + if tmp, ok := rawArgs["last"]; ok { + return ec.unmarshalOInt2ᚖint(ctx, tmp) + } + + var zeroVal *int + return zeroVal, nil +} + +func (ec *executionContext) field_Query_profiles_argsOrderBy( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.ProfileOrder, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["orderBy"] + if !ok { + var zeroVal *ent.ProfileOrder + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("orderBy")) + if tmp, ok := rawArgs["orderBy"]; ok { + return ec.unmarshalOProfileOrder2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileOrder(ctx, tmp) + } + + var zeroVal *ent.ProfileOrder + return zeroVal, nil +} + +func (ec *executionContext) field_Query_profiles_argsWhere( + ctx context.Context, + rawArgs map[string]interface{}, +) (*ent.ProfileWhereInput, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["where"] + if !ok { + var zeroVal *ent.ProfileWhereInput + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("where")) + if tmp, ok := rawArgs["where"]; ok { + return ec.unmarshalOProfileWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInput(ctx, tmp) + } + + var zeroVal *ent.ProfileWhereInput + return zeroVal, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region ************************** directives.gotpl ************************** + +// endregion ************************** directives.gotpl ************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _Category_id(ctx context.Context, field graphql.CollectedField, obj *ent.Category) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Category_id(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(uuid.UUID) + fc.Result = res + return ec.marshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Category_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Category", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Category_createdAt(ctx context.Context, field graphql.CollectedField, obj *ent.Category) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Category_createdAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.CreatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Category_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Category", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Category_updatedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Category) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Category_updatedAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.UpdatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Category_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Category", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Category_title(ctx context.Context, field graphql.CollectedField, obj *ent.Category) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Category_title(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Title, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Category_title(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Category", + 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) _Category_description(ctx context.Context, field graphql.CollectedField, obj *ent.Category) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Category_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, 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_Category_description(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Category", + 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) _Category_posts(ctx context.Context, field graphql.CollectedField, obj *ent.Category) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Category_posts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Posts(ctx, fc.Args["after"].(*entgql.Cursor[uuid.UUID]), fc.Args["first"].(*int), fc.Args["before"].(*entgql.Cursor[uuid.UUID]), fc.Args["last"].(*int), fc.Args["orderBy"].(*ent.PostOrder), fc.Args["where"].(*ent.PostWhereInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.PostConnection) + fc.Result = res + return ec.marshalNPostConnection2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Category_posts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Category", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "edges": + return ec.fieldContext_PostConnection_edges(ctx, field) + case "pageInfo": + return ec.fieldContext_PostConnection_pageInfo(ctx, field) + case "totalCount": + return ec.fieldContext_PostConnection_totalCount(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostConnection", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Category_posts_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _CategoryConnection_edges(ctx context.Context, field graphql.CollectedField, obj *ent.CategoryConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CategoryConnection_edges(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Edges, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*ent.CategoryEdge) + fc.Result = res + return ec.marshalOCategoryEdge2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryEdge(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CategoryConnection_edges(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CategoryConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "node": + return ec.fieldContext_CategoryEdge_node(ctx, field) + case "cursor": + return ec.fieldContext_CategoryEdge_cursor(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CategoryEdge", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _CategoryConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *ent.CategoryConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CategoryConnection_pageInfo(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PageInfo, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(entgql.PageInfo[uuid.UUID]) + fc.Result = res + return ec.marshalNPageInfo2entgoᚗioᚋcontribᚋentgqlᚐPageInfo(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CategoryConnection_pageInfo(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CategoryConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "hasNextPage": + return ec.fieldContext_PageInfo_hasNextPage(ctx, field) + case "hasPreviousPage": + return ec.fieldContext_PageInfo_hasPreviousPage(ctx, field) + case "startCursor": + return ec.fieldContext_PageInfo_startCursor(ctx, field) + case "endCursor": + return ec.fieldContext_PageInfo_endCursor(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PageInfo", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _CategoryConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *ent.CategoryConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CategoryConnection_totalCount(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.TotalCount, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CategoryConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CategoryConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CategoryEdge_node(ctx context.Context, field graphql.CollectedField, obj *ent.CategoryEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CategoryEdge_node(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Node, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ent.Category) + fc.Result = res + return ec.marshalOCategory2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategory(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CategoryEdge_node(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CategoryEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Category_id(ctx, field) + case "createdAt": + return ec.fieldContext_Category_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Category_updatedAt(ctx, field) + case "title": + return ec.fieldContext_Category_title(ctx, field) + case "description": + return ec.fieldContext_Category_description(ctx, field) + case "posts": + return ec.fieldContext_Category_posts(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Category", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _CategoryEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *ent.CategoryEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CategoryEdge_cursor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Cursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(entgql.Cursor[uuid.UUID]) + fc.Result = res + return ec.marshalNCursor2entgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CategoryEdge_cursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CategoryEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Cursor does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *entgql.PageInfo[uuid.UUID]) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PageInfo_hasNextPage(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.HasNextPage, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PageInfo_hasNextPage(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PageInfo_hasPreviousPage(ctx context.Context, field graphql.CollectedField, obj *entgql.PageInfo[uuid.UUID]) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PageInfo_hasPreviousPage(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.HasPreviousPage, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PageInfo_hasPreviousPage(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PageInfo_startCursor(ctx context.Context, field graphql.CollectedField, obj *entgql.PageInfo[uuid.UUID]) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PageInfo_startCursor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.StartCursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*entgql.Cursor[uuid.UUID]) + fc.Result = res + return ec.marshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PageInfo_startCursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Cursor does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *entgql.PageInfo[uuid.UUID]) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PageInfo_endCursor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EndCursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*entgql.Cursor[uuid.UUID]) + fc.Result = res + return ec.marshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PageInfo_endCursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Cursor does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Post_id(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_id(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(uuid.UUID) + fc.Result = res + return ec.marshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Post_createdAt(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_createdAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.CreatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Post_updatedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_updatedAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.UpdatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Post_expires(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_expires(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Expires, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_expires(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Post_expireTime(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_expireTime(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ExpireTime, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*time.Time) + fc.Result = res + return ec.marshalOTime2ᚖtimeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_expireTime(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Post_title(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_title(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Title, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_title(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + 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) _Post_body(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_body(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Body, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_body(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + 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) _Post_category(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_category(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Category(ctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ent.Category) + fc.Result = res + return ec.marshalOCategory2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategory(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_category(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Category_id(ctx, field) + case "createdAt": + return ec.fieldContext_Category_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Category_updatedAt(ctx, field) + case "title": + return ec.fieldContext_Category_title(ctx, field) + case "description": + return ec.fieldContext_Category_description(ctx, field) + case "posts": + return ec.fieldContext_Category_posts(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Category", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Post_profile(ctx context.Context, field graphql.CollectedField, obj *ent.Post) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Post_profile(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Profile(ctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ent.Profile) + fc.Result = res + return ec.marshalOProfile2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfile(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Post_profile(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Post", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Profile_id(ctx, field) + case "createdAt": + return ec.fieldContext_Profile_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Profile_updatedAt(ctx, field) + case "name": + return ec.fieldContext_Profile_name(ctx, field) + case "address": + return ec.fieldContext_Profile_address(ctx, field) + case "phone": + return ec.fieldContext_Profile_phone(ctx, field) + case "posts": + return ec.fieldContext_Profile_posts(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Profile", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _PostConnection_edges(ctx context.Context, field graphql.CollectedField, obj *ent.PostConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostConnection_edges(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Edges, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*ent.PostEdge) + fc.Result = res + return ec.marshalOPostEdge2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostEdge(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PostConnection_edges(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PostConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "node": + return ec.fieldContext_PostEdge_node(ctx, field) + case "cursor": + return ec.fieldContext_PostEdge_cursor(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostEdge", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _PostConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *ent.PostConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostConnection_pageInfo(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PageInfo, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(entgql.PageInfo[uuid.UUID]) + fc.Result = res + return ec.marshalNPageInfo2entgoᚗioᚋcontribᚋentgqlᚐPageInfo(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PostConnection_pageInfo(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PostConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "hasNextPage": + return ec.fieldContext_PageInfo_hasNextPage(ctx, field) + case "hasPreviousPage": + return ec.fieldContext_PageInfo_hasPreviousPage(ctx, field) + case "startCursor": + return ec.fieldContext_PageInfo_startCursor(ctx, field) + case "endCursor": + return ec.fieldContext_PageInfo_endCursor(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PageInfo", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _PostConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *ent.PostConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostConnection_totalCount(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.TotalCount, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PostConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PostConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PostEdge_node(ctx context.Context, field graphql.CollectedField, obj *ent.PostEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostEdge_node(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Node, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ent.Post) + fc.Result = res + return ec.marshalOPost2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPost(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PostEdge_node(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PostEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Post_id(ctx, field) + case "createdAt": + return ec.fieldContext_Post_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Post_updatedAt(ctx, field) + case "expires": + return ec.fieldContext_Post_expires(ctx, field) + case "expireTime": + return ec.fieldContext_Post_expireTime(ctx, field) + case "title": + return ec.fieldContext_Post_title(ctx, field) + case "body": + return ec.fieldContext_Post_body(ctx, field) + case "category": + return ec.fieldContext_Post_category(ctx, field) + case "profile": + return ec.fieldContext_Post_profile(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Post", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _PostEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *ent.PostEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostEdge_cursor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Cursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(entgql.Cursor[uuid.UUID]) + fc.Result = res + return ec.marshalNCursor2entgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PostEdge_cursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PostEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Cursor does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Profile_id(ctx context.Context, field graphql.CollectedField, obj *ent.Profile) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Profile_id(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(uuid.UUID) + fc.Result = res + return ec.marshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Profile_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Profile", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Profile_createdAt(ctx context.Context, field graphql.CollectedField, obj *ent.Profile) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Profile_createdAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.CreatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Profile_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Profile", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Profile_updatedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Profile) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Profile_updatedAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.UpdatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Profile_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Profile", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Profile_name(ctx context.Context, field graphql.CollectedField, obj *ent.Profile) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Profile_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) (interface{}, 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_Profile_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Profile", + 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) _Profile_address(ctx context.Context, field graphql.CollectedField, obj *ent.Profile) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Profile_address(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Address, 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_Profile_address(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Profile", + 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) _Profile_phone(ctx context.Context, field graphql.CollectedField, obj *ent.Profile) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Profile_phone(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Phone, 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_Profile_phone(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Profile", + 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) _Profile_posts(ctx context.Context, field graphql.CollectedField, obj *ent.Profile) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Profile_posts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Posts(ctx, fc.Args["after"].(*entgql.Cursor[uuid.UUID]), fc.Args["first"].(*int), fc.Args["before"].(*entgql.Cursor[uuid.UUID]), fc.Args["last"].(*int), fc.Args["orderBy"].(*ent.PostOrder), fc.Args["where"].(*ent.PostWhereInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.PostConnection) + fc.Result = res + return ec.marshalNPostConnection2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Profile_posts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Profile", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "edges": + return ec.fieldContext_PostConnection_edges(ctx, field) + case "pageInfo": + return ec.fieldContext_PostConnection_pageInfo(ctx, field) + case "totalCount": + return ec.fieldContext_PostConnection_totalCount(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostConnection", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Profile_posts_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _ProfileConnection_edges(ctx context.Context, field graphql.CollectedField, obj *ent.ProfileConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ProfileConnection_edges(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Edges, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*ent.ProfileEdge) + fc.Result = res + return ec.marshalOProfileEdge2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileEdge(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ProfileConnection_edges(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ProfileConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "node": + return ec.fieldContext_ProfileEdge_node(ctx, field) + case "cursor": + return ec.fieldContext_ProfileEdge_cursor(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type ProfileEdge", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _ProfileConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *ent.ProfileConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ProfileConnection_pageInfo(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PageInfo, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(entgql.PageInfo[uuid.UUID]) + fc.Result = res + return ec.marshalNPageInfo2entgoᚗioᚋcontribᚋentgqlᚐPageInfo(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ProfileConnection_pageInfo(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ProfileConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "hasNextPage": + return ec.fieldContext_PageInfo_hasNextPage(ctx, field) + case "hasPreviousPage": + return ec.fieldContext_PageInfo_hasPreviousPage(ctx, field) + case "startCursor": + return ec.fieldContext_PageInfo_startCursor(ctx, field) + case "endCursor": + return ec.fieldContext_PageInfo_endCursor(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PageInfo", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _ProfileConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *ent.ProfileConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ProfileConnection_totalCount(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.TotalCount, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ProfileConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ProfileConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _ProfileEdge_node(ctx context.Context, field graphql.CollectedField, obj *ent.ProfileEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ProfileEdge_node(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Node, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ent.Profile) + fc.Result = res + return ec.marshalOProfile2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfile(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ProfileEdge_node(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ProfileEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Profile_id(ctx, field) + case "createdAt": + return ec.fieldContext_Profile_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Profile_updatedAt(ctx, field) + case "name": + return ec.fieldContext_Profile_name(ctx, field) + case "address": + return ec.fieldContext_Profile_address(ctx, field) + case "phone": + return ec.fieldContext_Profile_phone(ctx, field) + case "posts": + return ec.fieldContext_Profile_posts(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Profile", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _ProfileEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *ent.ProfileEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ProfileEdge_cursor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Cursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(entgql.Cursor[uuid.UUID]) + fc.Result = res + return ec.marshalNCursor2entgoᚗioᚋcontribᚋentgqlᚐCursor(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ProfileEdge_cursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ProfileEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Cursor does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_node(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_node(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Node(rctx, fc.Args["id"].(uuid.UUID)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(ent.Noder) + fc.Result = res + return ec.marshalONode2codeᚗicodᚗdeᚋdaluᚋkaᚋentᚐNoder(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_node(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("FieldContext.Child cannot be called on type INTERFACE") + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_node_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Query_nodes(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_nodes(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Nodes(rctx, fc.Args["ids"].([]uuid.UUID)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]ent.Noder) + fc.Result = res + return ec.marshalNNode2ᚕcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐNoder(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_nodes(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("FieldContext.Child cannot be called on type INTERFACE") + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_nodes_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Query_categories(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_categories(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Categories(rctx, fc.Args["after"].(*entgql.Cursor[uuid.UUID]), fc.Args["first"].(*int), fc.Args["before"].(*entgql.Cursor[uuid.UUID]), fc.Args["last"].(*int), fc.Args["orderBy"].(*ent.CategoryOrder), fc.Args["where"].(*ent.CategoryWhereInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.CategoryConnection) + fc.Result = res + return ec.marshalNCategoryConnection2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_categories(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "edges": + return ec.fieldContext_CategoryConnection_edges(ctx, field) + case "pageInfo": + return ec.fieldContext_CategoryConnection_pageInfo(ctx, field) + case "totalCount": + return ec.fieldContext_CategoryConnection_totalCount(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CategoryConnection", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_categories_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Query_posts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_posts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Posts(rctx, fc.Args["after"].(*entgql.Cursor[uuid.UUID]), fc.Args["first"].(*int), fc.Args["before"].(*entgql.Cursor[uuid.UUID]), fc.Args["last"].(*int), fc.Args["orderBy"].(*ent.PostOrder), fc.Args["where"].(*ent.PostWhereInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.PostConnection) + fc.Result = res + return ec.marshalNPostConnection2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_posts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "edges": + return ec.fieldContext_PostConnection_edges(ctx, field) + case "pageInfo": + return ec.fieldContext_PostConnection_pageInfo(ctx, field) + case "totalCount": + return ec.fieldContext_PostConnection_totalCount(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostConnection", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_posts_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Query_profiles(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_profiles(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Profiles(rctx, fc.Args["after"].(*entgql.Cursor[uuid.UUID]), fc.Args["first"].(*int), fc.Args["before"].(*entgql.Cursor[uuid.UUID]), fc.Args["last"].(*int), fc.Args["orderBy"].(*ent.ProfileOrder), fc.Args["where"].(*ent.ProfileWhereInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.ProfileConnection) + fc.Result = res + return ec.marshalNProfileConnection2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_profiles(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "edges": + return ec.fieldContext_ProfileConnection_edges(ctx, field) + case "pageInfo": + return ec.fieldContext_ProfileConnection_pageInfo(ctx, field) + case "totalCount": + return ec.fieldContext_ProfileConnection_totalCount(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type ProfileConnection", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_profiles_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectType(fc.Args["name"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query___type_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___schema(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectSchema() + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Schema) + fc.Result = res + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___schema(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "description": + return ec.fieldContext___Schema_description(ctx, field) + case "types": + return ec.fieldContext___Schema_types(ctx, field) + case "queryType": + return ec.fieldContext___Schema_queryType(ctx, field) + case "mutationType": + return ec.fieldContext___Schema_mutationType(ctx, field) + case "subscriptionType": + return ec.fieldContext___Schema_subscriptionType(ctx, field) + case "directives": + return ec.fieldContext___Schema_directives(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Schema", field.Name) + }, + } + return fc, nil +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +func (ec *executionContext) unmarshalInputCategoryOrder(ctx context.Context, obj interface{}) (ent.CategoryOrder, error) { + var it ent.CategoryOrder + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + if _, present := asMap["direction"]; !present { + asMap["direction"] = "ASC" + } + + fieldsInOrder := [...]string{"direction", "field"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "direction": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("direction")) + data, err := ec.unmarshalNOrderDirection2entgoᚗioᚋcontribᚋentgqlᚐOrderDirection(ctx, v) + if err != nil { + return it, err + } + it.Direction = data + case "field": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("field")) + data, err := ec.unmarshalNCategoryOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryOrderField(ctx, v) + if err != nil { + return it, err + } + it.Field = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputCategoryWhereInput(ctx context.Context, obj interface{}) (ent.CategoryWhereInput, error) { + var it ent.CategoryWhereInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "updatedAt", "updatedAtNEQ", "updatedAtIn", "updatedAtNotIn", "updatedAtGT", "updatedAtGTE", "updatedAtLT", "updatedAtLTE", "updatedAtIsNil", "updatedAtNotNil", "title", "titleNEQ", "titleIn", "titleNotIn", "titleGT", "titleGTE", "titleLT", "titleLTE", "titleContains", "titleHasPrefix", "titleHasSuffix", "titleEqualFold", "titleContainsFold", "description", "descriptionNEQ", "descriptionIn", "descriptionNotIn", "descriptionGT", "descriptionGTE", "descriptionLT", "descriptionLTE", "descriptionContains", "descriptionHasPrefix", "descriptionHasSuffix", "descriptionIsNil", "descriptionNotNil", "descriptionEqualFold", "descriptionContainsFold", "hasPosts", "hasPostsWith"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "not": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("not")) + data, err := ec.unmarshalOCategoryWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInput(ctx, v) + if err != nil { + return it, err + } + it.Not = data + case "and": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("and")) + data, err := ec.unmarshalOCategoryWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.And = data + case "or": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("or")) + data, err := ec.unmarshalOCategoryWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.Or = data + case "id": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.ID = data + case "idNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idNEQ")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDNEQ = data + case "idIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idIn")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.IDIn = data + case "idNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idNotIn")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.IDNotIn = data + case "idGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idGT")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDGT = data + case "idGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idGTE")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDGTE = data + case "idLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idLT")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDLT = data + case "idLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idLTE")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDLTE = data + case "createdAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAt = data + case "createdAtNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNEQ")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtNEQ = data + case "createdAtIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtIn = data + case "createdAtNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNotIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtNotIn = data + case "createdAtGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtGT = data + case "createdAtGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtGTE = data + case "createdAtLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtLT = data + case "createdAtLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtLTE = data + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = data + case "updatedAtNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNEQ")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNEQ = data + case "updatedAtIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtIn = data + case "updatedAtNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNotIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNotIn = data + case "updatedAtGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtGT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtGT = data + case "updatedAtGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtGTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtGTE = data + case "updatedAtLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtLT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtLT = data + case "updatedAtLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtLTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtLTE = data + case "updatedAtIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtIsNil = data + case "updatedAtNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNotNil = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "titleNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleNEQ = data + case "titleIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.TitleIn = data + case "titleNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.TitleNotIn = data + case "titleGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleGT = data + case "titleGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleGTE = data + case "titleLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleLT = data + case "titleLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleLTE = data + case "titleContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleContains = data + case "titleHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleHasPrefix = data + case "titleHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleHasSuffix = data + case "titleEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleEqualFold = data + case "titleContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleContainsFold = data + case "description": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("description")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Description = data + case "descriptionNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionNEQ = data + case "descriptionIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.DescriptionIn = data + case "descriptionNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.DescriptionNotIn = data + case "descriptionGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionGT = data + case "descriptionGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionGTE = data + case "descriptionLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionLT = data + case "descriptionLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionLTE = data + case "descriptionContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionContains = data + case "descriptionHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionHasPrefix = data + case "descriptionHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionHasSuffix = data + case "descriptionIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.DescriptionIsNil = data + case "descriptionNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.DescriptionNotNil = data + case "descriptionEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionEqualFold = data + case "descriptionContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("descriptionContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.DescriptionContainsFold = data + case "hasPosts": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasPosts")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.HasPosts = data + case "hasPostsWith": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasPostsWith")) + data, err := ec.unmarshalOPostWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.HasPostsWith = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputCreateCategoryInput(ctx context.Context, obj interface{}) (ent.CreateCategoryInput, error) { + var it ent.CreateCategoryInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"createdAt", "updatedAt", "title", "description", "postIDs"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "createdAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAt = data + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "description": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("description")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Description = data + case "postIDs": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("postIDs")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.PostIDs = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputCreatePostInput(ctx context.Context, obj interface{}) (ent.CreatePostInput, error) { + var it ent.CreatePostInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"createdAt", "updatedAt", "expires", "expireTime", "title", "body", "categoryID", "profileID"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "createdAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAt = data + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = data + case "expires": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expires")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.Expires = data + case "expireTime": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTime")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.ExpireTime = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "body": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("body")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Body = data + case "categoryID": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("categoryID")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.CategoryID = data + case "profileID": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("profileID")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.ProfileID = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputCreateProfileInput(ctx context.Context, obj interface{}) (ent.CreateProfileInput, error) { + var it ent.CreateProfileInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"createdAt", "updatedAt", "name", "address", "phone", "postIDs"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "createdAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAt = data + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = 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 "address": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("address")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Address = data + case "phone": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phone")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Phone = data + case "postIDs": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("postIDs")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.PostIDs = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputPostOrder(ctx context.Context, obj interface{}) (ent.PostOrder, error) { + var it ent.PostOrder + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + if _, present := asMap["direction"]; !present { + asMap["direction"] = "ASC" + } + + fieldsInOrder := [...]string{"direction", "field"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "direction": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("direction")) + data, err := ec.unmarshalNOrderDirection2entgoᚗioᚋcontribᚋentgqlᚐOrderDirection(ctx, v) + if err != nil { + return it, err + } + it.Direction = data + case "field": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("field")) + data, err := ec.unmarshalNPostOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostOrderField(ctx, v) + if err != nil { + return it, err + } + it.Field = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputPostWhereInput(ctx context.Context, obj interface{}) (ent.PostWhereInput, error) { + var it ent.PostWhereInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "updatedAt", "updatedAtNEQ", "updatedAtIn", "updatedAtNotIn", "updatedAtGT", "updatedAtGTE", "updatedAtLT", "updatedAtLTE", "updatedAtIsNil", "updatedAtNotNil", "expires", "expiresNEQ", "expireTime", "expireTimeNEQ", "expireTimeIn", "expireTimeNotIn", "expireTimeGT", "expireTimeGTE", "expireTimeLT", "expireTimeLTE", "expireTimeIsNil", "expireTimeNotNil", "title", "titleNEQ", "titleIn", "titleNotIn", "titleGT", "titleGTE", "titleLT", "titleLTE", "titleContains", "titleHasPrefix", "titleHasSuffix", "titleEqualFold", "titleContainsFold", "body", "bodyNEQ", "bodyIn", "bodyNotIn", "bodyGT", "bodyGTE", "bodyLT", "bodyLTE", "bodyContains", "bodyHasPrefix", "bodyHasSuffix", "bodyEqualFold", "bodyContainsFold", "hasCategory", "hasCategoryWith", "hasProfile", "hasProfileWith"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "not": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("not")) + data, err := ec.unmarshalOPostWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInput(ctx, v) + if err != nil { + return it, err + } + it.Not = data + case "and": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("and")) + data, err := ec.unmarshalOPostWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.And = data + case "or": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("or")) + data, err := ec.unmarshalOPostWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.Or = data + case "id": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.ID = data + case "idNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idNEQ")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDNEQ = data + case "idIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idIn")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.IDIn = data + case "idNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idNotIn")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.IDNotIn = data + case "idGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idGT")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDGT = data + case "idGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idGTE")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDGTE = data + case "idLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idLT")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDLT = data + case "idLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idLTE")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDLTE = data + case "createdAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAt = data + case "createdAtNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNEQ")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtNEQ = data + case "createdAtIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtIn = data + case "createdAtNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNotIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtNotIn = data + case "createdAtGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtGT = data + case "createdAtGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtGTE = data + case "createdAtLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtLT = data + case "createdAtLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtLTE = data + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = data + case "updatedAtNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNEQ")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNEQ = data + case "updatedAtIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtIn = data + case "updatedAtNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNotIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNotIn = data + case "updatedAtGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtGT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtGT = data + case "updatedAtGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtGTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtGTE = data + case "updatedAtLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtLT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtLT = data + case "updatedAtLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtLTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtLTE = data + case "updatedAtIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtIsNil = data + case "updatedAtNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNotNil = data + case "expires": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expires")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.Expires = data + case "expiresNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expiresNEQ")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.ExpiresNEQ = data + case "expireTime": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTime")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.ExpireTime = data + case "expireTimeNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeNEQ")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeNEQ = data + case "expireTimeIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeIn = data + case "expireTimeNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeNotIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeNotIn = data + case "expireTimeGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeGT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeGT = data + case "expireTimeGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeGTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeGTE = data + case "expireTimeLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeLT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeLT = data + case "expireTimeLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeLTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeLTE = data + case "expireTimeIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeIsNil = data + case "expireTimeNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTimeNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ExpireTimeNotNil = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "titleNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleNEQ = data + case "titleIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.TitleIn = data + case "titleNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.TitleNotIn = data + case "titleGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleGT = data + case "titleGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleGTE = data + case "titleLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleLT = data + case "titleLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleLTE = data + case "titleContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleContains = data + case "titleHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleHasPrefix = data + case "titleHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleHasSuffix = data + case "titleEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleEqualFold = data + case "titleContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("titleContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.TitleContainsFold = data + case "body": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("body")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Body = data + case "bodyNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyNEQ = data + case "bodyIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.BodyIn = data + case "bodyNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.BodyNotIn = data + case "bodyGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyGT = data + case "bodyGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyGTE = data + case "bodyLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyLT = data + case "bodyLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyLTE = data + case "bodyContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyContains = data + case "bodyHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyHasPrefix = data + case "bodyHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyHasSuffix = data + case "bodyEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyEqualFold = data + case "bodyContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bodyContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.BodyContainsFold = data + case "hasCategory": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasCategory")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.HasCategory = data + case "hasCategoryWith": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasCategoryWith")) + data, err := ec.unmarshalOCategoryWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.HasCategoryWith = data + case "hasProfile": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasProfile")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.HasProfile = data + case "hasProfileWith": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasProfileWith")) + data, err := ec.unmarshalOProfileWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.HasProfileWith = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputProfileOrder(ctx context.Context, obj interface{}) (ent.ProfileOrder, error) { + var it ent.ProfileOrder + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + if _, present := asMap["direction"]; !present { + asMap["direction"] = "ASC" + } + + fieldsInOrder := [...]string{"direction", "field"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "direction": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("direction")) + data, err := ec.unmarshalNOrderDirection2entgoᚗioᚋcontribᚋentgqlᚐOrderDirection(ctx, v) + if err != nil { + return it, err + } + it.Direction = data + case "field": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("field")) + data, err := ec.unmarshalNProfileOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileOrderField(ctx, v) + if err != nil { + return it, err + } + it.Field = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputProfileWhereInput(ctx context.Context, obj interface{}) (ent.ProfileWhereInput, error) { + var it ent.ProfileWhereInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "updatedAt", "updatedAtNEQ", "updatedAtIn", "updatedAtNotIn", "updatedAtGT", "updatedAtGTE", "updatedAtLT", "updatedAtLTE", "updatedAtIsNil", "updatedAtNotNil", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameIsNil", "nameNotNil", "nameEqualFold", "nameContainsFold", "address", "addressNEQ", "addressIn", "addressNotIn", "addressGT", "addressGTE", "addressLT", "addressLTE", "addressContains", "addressHasPrefix", "addressHasSuffix", "addressIsNil", "addressNotNil", "addressEqualFold", "addressContainsFold", "phone", "phoneNEQ", "phoneIn", "phoneNotIn", "phoneGT", "phoneGTE", "phoneLT", "phoneLTE", "phoneContains", "phoneHasPrefix", "phoneHasSuffix", "phoneIsNil", "phoneNotNil", "phoneEqualFold", "phoneContainsFold", "hasPosts", "hasPostsWith"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "not": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("not")) + data, err := ec.unmarshalOProfileWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInput(ctx, v) + if err != nil { + return it, err + } + it.Not = data + case "and": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("and")) + data, err := ec.unmarshalOProfileWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.And = data + case "or": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("or")) + data, err := ec.unmarshalOProfileWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.Or = data + case "id": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.ID = data + case "idNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idNEQ")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDNEQ = data + case "idIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idIn")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.IDIn = data + case "idNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idNotIn")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.IDNotIn = data + case "idGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idGT")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDGT = data + case "idGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idGTE")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDGTE = data + case "idLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idLT")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDLT = data + case "idLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idLTE")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.IDLTE = data + case "createdAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAt = data + case "createdAtNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNEQ")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtNEQ = data + case "createdAtIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtIn = data + case "createdAtNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNotIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtNotIn = data + case "createdAtGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtGT = data + case "createdAtGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtGTE = data + case "createdAtLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtLT = data + case "createdAtLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.CreatedAtLTE = data + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = data + case "updatedAtNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNEQ")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNEQ = data + case "updatedAtIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtIn = data + case "updatedAtNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNotIn")) + data, err := ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNotIn = data + case "updatedAtGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtGT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtGT = data + case "updatedAtGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtGTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtGTE = data + case "updatedAtLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtLT")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtLT = data + case "updatedAtLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtLTE")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtLTE = data + case "updatedAtIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtIsNil = data + case "updatedAtNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAtNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAtNotNil = 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 "address": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("address")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Address = data + case "addressNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressNEQ = data + case "addressIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.AddressIn = data + case "addressNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.AddressNotIn = data + case "addressGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressGT = data + case "addressGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressGTE = data + case "addressLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressLT = data + case "addressLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressLTE = data + case "addressContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressContains = data + case "addressHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressHasPrefix = data + case "addressHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressHasSuffix = data + case "addressIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.AddressIsNil = data + case "addressNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.AddressNotNil = data + case "addressEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressEqualFold = data + case "addressContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addressContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.AddressContainsFold = data + case "phone": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phone")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Phone = data + case "phoneNEQ": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneNEQ")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneNEQ = data + case "phoneIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.PhoneIn = data + case "phoneNotIn": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneNotIn")) + data, err := ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.PhoneNotIn = data + case "phoneGT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneGT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneGT = data + case "phoneGTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneGTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneGTE = data + case "phoneLT": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneLT")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneLT = data + case "phoneLTE": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneLTE")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneLTE = data + case "phoneContains": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneContains")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneContains = data + case "phoneHasPrefix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneHasPrefix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneHasPrefix = data + case "phoneHasSuffix": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneHasSuffix")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneHasSuffix = data + case "phoneIsNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.PhoneIsNil = data + case "phoneNotNil": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.PhoneNotNil = data + case "phoneEqualFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneEqualFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneEqualFold = data + case "phoneContainsFold": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phoneContainsFold")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.PhoneContainsFold = data + case "hasPosts": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasPosts")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.HasPosts = data + case "hasPostsWith": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasPostsWith")) + data, err := ec.unmarshalOPostWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } + it.HasPostsWith = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputUpdateCategoryInput(ctx context.Context, obj interface{}) (ent.UpdateCategoryInput, error) { + var it ent.UpdateCategoryInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"updatedAt", "clearUpdatedAt", "title", "description", "clearDescription", "addPostIDs", "removePostIDs", "clearPosts"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = data + case "clearUpdatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearUpdatedAt")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearUpdatedAt = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "description": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("description")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Description = data + case "clearDescription": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearDescription")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearDescription = data + case "addPostIDs": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addPostIDs")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.AddPostIDs = data + case "removePostIDs": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("removePostIDs")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.RemovePostIDs = data + case "clearPosts": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearPosts")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearPosts = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputUpdatePostInput(ctx context.Context, obj interface{}) (ent.UpdatePostInput, error) { + var it ent.UpdatePostInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"updatedAt", "clearUpdatedAt", "expires", "expireTime", "clearExpireTime", "title", "body", "categoryID", "clearCategory", "profileID", "clearProfile"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = data + case "clearUpdatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearUpdatedAt")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearUpdatedAt = data + case "expires": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expires")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.Expires = data + case "expireTime": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expireTime")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.ExpireTime = data + case "clearExpireTime": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearExpireTime")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearExpireTime = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "body": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("body")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Body = data + case "categoryID": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("categoryID")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.CategoryID = data + case "clearCategory": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearCategory")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearCategory = data + case "profileID": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("profileID")) + data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, v) + if err != nil { + return it, err + } + it.ProfileID = data + case "clearProfile": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearProfile")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearProfile = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputUpdateProfileInput(ctx context.Context, obj interface{}) (ent.UpdateProfileInput, error) { + var it ent.UpdateProfileInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"updatedAt", "clearUpdatedAt", "name", "clearName", "address", "clearAddress", "phone", "clearPhone", "addPostIDs", "removePostIDs", "clearPosts"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "updatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updatedAt")) + data, err := ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.UpdatedAt = data + case "clearUpdatedAt": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearUpdatedAt")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearUpdatedAt = 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 "address": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("address")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Address = data + case "clearAddress": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearAddress")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearAddress = data + case "phone": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("phone")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Phone = data + case "clearPhone": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearPhone")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearPhone = data + case "addPostIDs": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("addPostIDs")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.AddPostIDs = data + case "removePostIDs": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("removePostIDs")) + data, err := ec.unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, v) + if err != nil { + return it, err + } + it.RemovePostIDs = data + case "clearPosts": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearPosts")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearPosts = data + } + } + + return it, nil +} + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +func (ec *executionContext) _Node(ctx context.Context, sel ast.SelectionSet, obj ent.Noder) graphql.Marshaler { + switch obj := (obj).(type) { + case nil: + return graphql.Null + case *ent.Category: + if obj == nil { + return graphql.Null + } + return ec._Category(ctx, sel, obj) + case *ent.Post: + if obj == nil { + return graphql.Null + } + return ec._Post(ctx, sel, obj) + case *ent.Profile: + if obj == nil { + return graphql.Null + } + return ec._Profile(ctx, sel, obj) + default: + panic(fmt.Errorf("unexpected type %T", obj)) + } +} + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var categoryImplementors = []string{"Category", "Node"} + +func (ec *executionContext) _Category(ctx context.Context, sel ast.SelectionSet, obj *ent.Category) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, categoryImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Category") + case "id": + out.Values[i] = ec._Category_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "createdAt": + out.Values[i] = ec._Category_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "updatedAt": + out.Values[i] = ec._Category_updatedAt(ctx, field, obj) + case "title": + out.Values[i] = ec._Category_title(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "description": + out.Values[i] = ec._Category_description(ctx, field, obj) + case "posts": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Category_posts(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + 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)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var categoryConnectionImplementors = []string{"CategoryConnection"} + +func (ec *executionContext) _CategoryConnection(ctx context.Context, sel ast.SelectionSet, obj *ent.CategoryConnection) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, categoryConnectionImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CategoryConnection") + case "edges": + out.Values[i] = ec._CategoryConnection_edges(ctx, field, obj) + case "pageInfo": + out.Values[i] = ec._CategoryConnection_pageInfo(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "totalCount": + out.Values[i] = ec._CategoryConnection_totalCount(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var categoryEdgeImplementors = []string{"CategoryEdge"} + +func (ec *executionContext) _CategoryEdge(ctx context.Context, sel ast.SelectionSet, obj *ent.CategoryEdge) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, categoryEdgeImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CategoryEdge") + case "node": + out.Values[i] = ec._CategoryEdge_node(ctx, field, obj) + case "cursor": + out.Values[i] = ec._CategoryEdge_cursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var pageInfoImplementors = []string{"PageInfo"} + +func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, obj *entgql.PageInfo[uuid.UUID]) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, pageInfoImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("PageInfo") + case "hasNextPage": + out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "hasPreviousPage": + out.Values[i] = ec._PageInfo_hasPreviousPage(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "startCursor": + out.Values[i] = ec._PageInfo_startCursor(ctx, field, obj) + case "endCursor": + out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var postImplementors = []string{"Post", "Node"} + +func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj *ent.Post) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, postImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Post") + case "id": + out.Values[i] = ec._Post_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "createdAt": + out.Values[i] = ec._Post_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "updatedAt": + out.Values[i] = ec._Post_updatedAt(ctx, field, obj) + case "expires": + out.Values[i] = ec._Post_expires(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "expireTime": + out.Values[i] = ec._Post_expireTime(ctx, field, obj) + case "title": + out.Values[i] = ec._Post_title(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "body": + out.Values[i] = ec._Post_body(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "category": + 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._Post_category(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) }) + case "profile": + 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._Post_profile(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)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var postConnectionImplementors = []string{"PostConnection"} + +func (ec *executionContext) _PostConnection(ctx context.Context, sel ast.SelectionSet, obj *ent.PostConnection) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, postConnectionImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("PostConnection") + case "edges": + out.Values[i] = ec._PostConnection_edges(ctx, field, obj) + case "pageInfo": + out.Values[i] = ec._PostConnection_pageInfo(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "totalCount": + out.Values[i] = ec._PostConnection_totalCount(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var postEdgeImplementors = []string{"PostEdge"} + +func (ec *executionContext) _PostEdge(ctx context.Context, sel ast.SelectionSet, obj *ent.PostEdge) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, postEdgeImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("PostEdge") + case "node": + out.Values[i] = ec._PostEdge_node(ctx, field, obj) + case "cursor": + out.Values[i] = ec._PostEdge_cursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var profileImplementors = []string{"Profile", "Node"} + +func (ec *executionContext) _Profile(ctx context.Context, sel ast.SelectionSet, obj *ent.Profile) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, profileImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Profile") + case "id": + out.Values[i] = ec._Profile_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "createdAt": + out.Values[i] = ec._Profile_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "updatedAt": + out.Values[i] = ec._Profile_updatedAt(ctx, field, obj) + case "name": + out.Values[i] = ec._Profile_name(ctx, field, obj) + case "address": + out.Values[i] = ec._Profile_address(ctx, field, obj) + case "phone": + out.Values[i] = ec._Profile_phone(ctx, field, obj) + case "posts": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Profile_posts(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + 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)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var profileConnectionImplementors = []string{"ProfileConnection"} + +func (ec *executionContext) _ProfileConnection(ctx context.Context, sel ast.SelectionSet, obj *ent.ProfileConnection) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, profileConnectionImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ProfileConnection") + case "edges": + out.Values[i] = ec._ProfileConnection_edges(ctx, field, obj) + case "pageInfo": + out.Values[i] = ec._ProfileConnection_pageInfo(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "totalCount": + out.Values[i] = ec._ProfileConnection_totalCount(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var profileEdgeImplementors = []string{"ProfileEdge"} + +func (ec *executionContext) _ProfileEdge(ctx context.Context, sel ast.SelectionSet, obj *ent.ProfileEdge) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, profileEdgeImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ProfileEdge") + case "node": + out.Values[i] = ec._ProfileEdge_node(ctx, field, obj) + case "cursor": + out.Values[i] = ec._ProfileEdge_cursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var queryImplementors = []string{"Query"} + +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, queryImplementors) + ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ + Object: field.Name, + Field: field, + }) + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "node": + 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._Query_node(ctx, field) + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "nodes": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_nodes(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "categories": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_categories(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "posts": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_posts(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "profiles": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_profiles(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "__type": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___type(ctx, field) + }) + case "__schema": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___schema(ctx, field) + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) marshalNCategoryConnection2codeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryConnection(ctx context.Context, sel ast.SelectionSet, v ent.CategoryConnection) graphql.Marshaler { + return ec._CategoryConnection(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCategoryConnection2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryConnection(ctx context.Context, sel ast.SelectionSet, v *ent.CategoryConnection) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._CategoryConnection(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNCategoryOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryOrderField(ctx context.Context, v interface{}) (*ent.CategoryOrderField, error) { + var res = new(ent.CategoryOrderField) + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNCategoryOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryOrderField(ctx context.Context, sel ast.SelectionSet, v *ent.CategoryOrderField) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return v +} + +func (ec *executionContext) unmarshalNCategoryWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInput(ctx context.Context, v interface{}) (*ent.CategoryWhereInput, error) { + res, err := ec.unmarshalInputCategoryWhereInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalNCursor2entgoᚗioᚋcontribᚋentgqlᚐCursor(ctx context.Context, v interface{}) (entgql.Cursor[uuid.UUID], error) { + var res entgql.Cursor[uuid.UUID] + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNCursor2entgoᚗioᚋcontribᚋentgqlᚐCursor(ctx context.Context, sel ast.SelectionSet, v entgql.Cursor[uuid.UUID]) graphql.Marshaler { + return v +} + +func (ec *executionContext) marshalNNode2ᚕcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐNoder(ctx context.Context, sel ast.SelectionSet, v []ent.Noder) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalONode2codeᚗicodᚗdeᚋdaluᚋkaᚋentᚐNoder(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret +} + +func (ec *executionContext) unmarshalNOrderDirection2entgoᚗioᚋcontribᚋentgqlᚐOrderDirection(ctx context.Context, v interface{}) (entgql.OrderDirection, error) { + var res entgql.OrderDirection + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNOrderDirection2entgoᚗioᚋcontribᚋentgqlᚐOrderDirection(ctx context.Context, sel ast.SelectionSet, v entgql.OrderDirection) graphql.Marshaler { + return v +} + +func (ec *executionContext) marshalNPageInfo2entgoᚗioᚋcontribᚋentgqlᚐPageInfo(ctx context.Context, sel ast.SelectionSet, v entgql.PageInfo[uuid.UUID]) graphql.Marshaler { + return ec._PageInfo(ctx, sel, &v) +} + +func (ec *executionContext) marshalNPostConnection2codeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostConnection(ctx context.Context, sel ast.SelectionSet, v ent.PostConnection) graphql.Marshaler { + return ec._PostConnection(ctx, sel, &v) +} + +func (ec *executionContext) marshalNPostConnection2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostConnection(ctx context.Context, sel ast.SelectionSet, v *ent.PostConnection) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._PostConnection(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNPostOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostOrderField(ctx context.Context, v interface{}) (*ent.PostOrderField, error) { + var res = new(ent.PostOrderField) + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNPostOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostOrderField(ctx context.Context, sel ast.SelectionSet, v *ent.PostOrderField) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return v +} + +func (ec *executionContext) unmarshalNPostWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInput(ctx context.Context, v interface{}) (*ent.PostWhereInput, error) { + res, err := ec.unmarshalInputPostWhereInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNProfileConnection2codeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileConnection(ctx context.Context, sel ast.SelectionSet, v ent.ProfileConnection) graphql.Marshaler { + return ec._ProfileConnection(ctx, sel, &v) +} + +func (ec *executionContext) marshalNProfileConnection2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileConnection(ctx context.Context, sel ast.SelectionSet, v *ent.ProfileConnection) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._ProfileConnection(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNProfileOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileOrderField(ctx context.Context, v interface{}) (*ent.ProfileOrderField, error) { + var res = new(ent.ProfileOrderField) + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNProfileOrderField2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileOrderField(ctx context.Context, sel ast.SelectionSet, v *ent.ProfileOrderField) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return v +} + +func (ec *executionContext) unmarshalNProfileWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInput(ctx context.Context, v interface{}) (*ent.ProfileWhereInput, error) { + res, err := ec.unmarshalInputProfileWhereInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalNTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + res, err := graphql.UnmarshalTime(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNTime2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + res := graphql.MarshalTime(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) marshalOCategory2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v *ent.Category) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Category(ctx, sel, v) +} + +func (ec *executionContext) marshalOCategoryEdge2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryEdge(ctx context.Context, sel ast.SelectionSet, v []*ent.CategoryEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalOCategoryEdge2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryEdge(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret +} + +func (ec *executionContext) marshalOCategoryEdge2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryEdge(ctx context.Context, sel ast.SelectionSet, v *ent.CategoryEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._CategoryEdge(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOCategoryOrder2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryOrder(ctx context.Context, v interface{}) (*ent.CategoryOrder, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputCategoryOrder(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalOCategoryWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInputᚄ(ctx context.Context, v interface{}) ([]*ent.CategoryWhereInput, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]*ent.CategoryWhereInput, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNCategoryWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) unmarshalOCategoryWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐCategoryWhereInput(ctx context.Context, v interface{}) (*ent.CategoryWhereInput, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputCategoryWhereInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx context.Context, v interface{}) (*entgql.Cursor[uuid.UUID], error) { + if v == nil { + return nil, nil + } + var res = new(entgql.Cursor[uuid.UUID]) + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚐCursor(ctx context.Context, sel ast.SelectionSet, v *entgql.Cursor[uuid.UUID]) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return v +} + +func (ec *executionContext) marshalONode2codeᚗicodᚗdeᚋdaluᚋkaᚋentᚐNoder(ctx context.Context, sel ast.SelectionSet, v ent.Noder) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Node(ctx, sel, v) +} + +func (ec *executionContext) marshalOPost2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPost(ctx context.Context, sel ast.SelectionSet, v *ent.Post) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Post(ctx, sel, v) +} + +func (ec *executionContext) marshalOPostEdge2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostEdge(ctx context.Context, sel ast.SelectionSet, v []*ent.PostEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalOPostEdge2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostEdge(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret +} + +func (ec *executionContext) marshalOPostEdge2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostEdge(ctx context.Context, sel ast.SelectionSet, v *ent.PostEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._PostEdge(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOPostOrder2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostOrder(ctx context.Context, v interface{}) (*ent.PostOrder, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputPostOrder(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalOPostWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInputᚄ(ctx context.Context, v interface{}) ([]*ent.PostWhereInput, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]*ent.PostWhereInput, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNPostWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) unmarshalOPostWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐPostWhereInput(ctx context.Context, v interface{}) (*ent.PostWhereInput, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputPostWhereInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOProfile2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfile(ctx context.Context, sel ast.SelectionSet, v *ent.Profile) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Profile(ctx, sel, v) +} + +func (ec *executionContext) marshalOProfileEdge2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileEdge(ctx context.Context, sel ast.SelectionSet, v []*ent.ProfileEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalOProfileEdge2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileEdge(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret +} + +func (ec *executionContext) marshalOProfileEdge2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileEdge(ctx context.Context, sel ast.SelectionSet, v *ent.ProfileEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._ProfileEdge(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOProfileOrder2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileOrder(ctx context.Context, v interface{}) (*ent.ProfileOrder, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputProfileOrder(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalOProfileWhereInput2ᚕᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInputᚄ(ctx context.Context, v interface{}) ([]*ent.ProfileWhereInput, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]*ent.ProfileWhereInput, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNProfileWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) unmarshalOProfileWhereInput2ᚖcodeᚗicodᚗdeᚋdaluᚋkaᚋentᚐProfileWhereInput(ctx context.Context, v interface{}) (*ent.ProfileWhereInput, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputProfileWhereInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalOTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + res, err := graphql.UnmarshalTime(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOTime2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + res := graphql.MarshalTime(v) + return res +} + +func (ec *executionContext) unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx context.Context, v interface{}) ([]time.Time, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]time.Time, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNTime2timeᚐTime(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOTime2ᚕtimeᚐTimeᚄ(ctx context.Context, sel ast.SelectionSet, v []time.Time) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNTime2timeᚐTime(ctx, sel, v[i]) + } + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalOTime2ᚖtimeᚐTime(ctx context.Context, v interface{}) (*time.Time, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalTime(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOTime2ᚖtimeᚐTime(ctx context.Context, sel ast.SelectionSet, v *time.Time) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalTime(*v) + return res +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/graph/generated/prelude.generated.go b/graph/generated/prelude.generated.go new file mode 100644 index 0000000..78b9fc1 --- /dev/null +++ b/graph/generated/prelude.generated.go @@ -0,0 +1,2971 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package generated + +import ( + "context" + "errors" + "fmt" + "strconv" + "sync" + "sync/atomic" + + "code.icod.de/dalu/ka/ent/schema/uuidgql" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + "github.com/google/uuid" + "github.com/vektah/gqlparser/v2/ast" +) + +// region ************************** generated!.gotpl ************************** + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) dir_defer_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.dir_defer_argsIf(ctx, rawArgs) + if err != nil { + return nil, err + } + args["if"] = arg0 + arg1, err := ec.dir_defer_argsLabel(ctx, rawArgs) + if err != nil { + return nil, err + } + args["label"] = arg1 + return args, nil +} +func (ec *executionContext) dir_defer_argsIf( + ctx context.Context, + rawArgs map[string]interface{}, +) (*bool, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["if"] + if !ok { + var zeroVal *bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("if")) + if tmp, ok := rawArgs["if"]; ok { + return ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + } + + var zeroVal *bool + return zeroVal, nil +} + +func (ec *executionContext) dir_defer_argsLabel( + ctx context.Context, + rawArgs map[string]interface{}, +) (*string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["label"] + if !ok { + var zeroVal *string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("label")) + if tmp, ok := rawArgs["label"]; ok { + return ec.unmarshalOString2ᚖstring(ctx, tmp) + } + + var zeroVal *string + return zeroVal, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field___Type_enumValues_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err + } + args["includeDeprecated"] = arg0 + return args, nil +} +func (ec *executionContext) field___Type_enumValues_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]interface{}, +) (bool, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["includeDeprecated"] + if !ok { + var zeroVal bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2bool(ctx, tmp) + } + + var zeroVal bool + return zeroVal, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + arg0, err := ec.field___Type_fields_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err + } + args["includeDeprecated"] = arg0 + return args, nil +} +func (ec *executionContext) field___Type_fields_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]interface{}, +) (bool, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["includeDeprecated"] + if !ok { + var zeroVal bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2bool(ctx, tmp) + } + + var zeroVal bool + return zeroVal, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region ************************** directives.gotpl ************************** + +// endregion ************************** directives.gotpl ************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_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) (interface{}, 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 { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + 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) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_description(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: true, + 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) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_locations(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Locations, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]string) + fc.Result = res + return ec.marshalN__DirectiveLocation2ᚕstringᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_locations(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type __DirectiveLocation does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_args(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_args(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_isRepeatable(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsRepeatable, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_isRepeatable(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_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) (interface{}, 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 { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + 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) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_description(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + 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) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_isDeprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_isDeprecated(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_deprecationReason(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_deprecationReason(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + 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) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_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) (interface{}, 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 { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + 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) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_description(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + 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) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_args(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_args(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_type(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_isDeprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_isDeprecated(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_deprecationReason(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_deprecationReason(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + 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) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_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) (interface{}, 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 { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + 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) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_description(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: true, + 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) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_type(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_defaultValue(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DefaultValue, 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_defaultValue(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + 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) ___Schema_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_description(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + 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) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_types(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_types(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_queryType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.QueryType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_queryType(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_mutationType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.MutationType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_mutationType(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_subscriptionType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SubscriptionType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_subscriptionType(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_directives(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Directives(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Directive) + fc.Result = res + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_directives(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___Directive_name(ctx, field) + case "description": + return ec.fieldContext___Directive_description(ctx, field) + case "locations": + return ec.fieldContext___Directive_locations(ctx, field) + case "args": + return ec.fieldContext___Directive_args(ctx, field) + case "isRepeatable": + return ec.fieldContext___Directive_isRepeatable(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Directive", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_kind(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Kind(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_kind(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type __TypeKind does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_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) (interface{}, 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + 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) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_description(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + 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) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_fields(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Fields(fc.Args["includeDeprecated"].(bool)), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Field) + fc.Result = res + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_fields(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___Field_name(ctx, field) + case "description": + return ec.fieldContext___Field_description(ctx, field) + case "args": + return ec.fieldContext___Field_args(ctx, field) + case "type": + return ec.fieldContext___Field_type(ctx, field) + case "isDeprecated": + return ec.fieldContext___Field_isDeprecated(ctx, field) + case "deprecationReason": + return ec.fieldContext___Field_deprecationReason(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Field", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field___Type_fields_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_interfaces(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Interfaces(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_interfaces(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_possibleTypes(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PossibleTypes(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_possibleTypes(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_enumValues(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EnumValues(fc.Args["includeDeprecated"].(bool)), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.EnumValue) + fc.Result = res + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_enumValues(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___EnumValue_name(ctx, field) + case "description": + return ec.fieldContext___EnumValue_description(ctx, field) + case "isDeprecated": + return ec.fieldContext___EnumValue_isDeprecated(ctx, field) + case "deprecationReason": + return ec.fieldContext___EnumValue_deprecationReason(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __EnumValue", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field___Type_enumValues_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_inputFields(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.InputFields(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_inputFields(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_ofType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.OfType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_ofType(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_specifiedByURL(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_specifiedByURL(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SpecifiedByURL(), 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.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_specifiedByURL(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + 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 +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var __DirectiveImplementors = []string{"__Directive"} + +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __DirectiveImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "isRepeatable": + out.Values[i] = ec.___Directive_isRepeatable(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __EnumValueImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "description": + out.Values[i] = ec.___Schema_description(ctx, field, obj) + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + case "specifiedByURL": + out.Values[i] = ec.___Type_specifiedByURL(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + res, err := graphql.UnmarshalBoolean(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + res := graphql.MarshalBoolean(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx context.Context, v interface{}) (uuid.UUID, error) { + res, err := uuidgql.UnmarshalUUID(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx context.Context, sel ast.SelectionSet, v uuid.UUID) graphql.Marshaler { + res := uuidgql.MarshalUUID(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalNID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx context.Context, v interface{}) ([]uuid.UUID, error) { + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]uuid.UUID, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalNID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx context.Context, sel ast.SelectionSet, v []uuid.UUID) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, sel, v[i]) + } + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) { + res, err := graphql.UnmarshalInt(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + res := graphql.MarshalInt(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + res, err := graphql.UnmarshalBoolean(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + res := graphql.MarshalBoolean(v) + return res +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalBoolean(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalBoolean(*v) + return res +} + +func (ec *executionContext) unmarshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx context.Context, v interface{}) ([]uuid.UUID, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]uuid.UUID, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx context.Context, sel ast.SelectionSet, v []uuid.UUID) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, sel, v[i]) + } + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx context.Context, v interface{}) (*uuid.UUID, error) { + if v == nil { + return nil, nil + } + res, err := uuidgql.UnmarshalUUID(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx context.Context, sel ast.SelectionSet, v *uuid.UUID) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := uuidgql.MarshalUUID(*v) + return res +} + +func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v interface{}) (*int, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalInt(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.SelectionSet, v *int) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalInt(*v) + return res +} + +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (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 interface{}) ([]string, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNString2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOString2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNString2string(ctx, sel, v[i]) + } + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalString(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalString(*v) + return res +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/graph/generated/root_.generated.go b/graph/generated/root_.generated.go new file mode 100644 index 0000000..f7d22bc --- /dev/null +++ b/graph/generated/root_.generated.go @@ -0,0 +1,1390 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package generated + +import ( + "bytes" + "context" + "errors" + "sync/atomic" + + "code.icod.de/dalu/ka/ent" + "entgo.io/contrib/entgql" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + "github.com/google/uuid" + gqlparser "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" +) + +// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. +func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { + return &executableSchema{ + schema: cfg.Schema, + resolvers: cfg.Resolvers, + directives: cfg.Directives, + complexity: cfg.Complexity, + } +} + +type Config struct { + Schema *ast.Schema + Resolvers ResolverRoot + Directives DirectiveRoot + Complexity ComplexityRoot +} + +type ResolverRoot interface { + Query() QueryResolver +} + +type DirectiveRoot struct { +} + +type ComplexityRoot struct { + Category struct { + CreatedAt func(childComplexity int) int + Description func(childComplexity int) int + ID func(childComplexity int) int + Posts func(childComplexity int, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.PostOrder, where *ent.PostWhereInput) int + Title func(childComplexity int) int + UpdatedAt func(childComplexity int) int + } + + CategoryConnection struct { + Edges func(childComplexity int) int + PageInfo func(childComplexity int) int + TotalCount func(childComplexity int) int + } + + CategoryEdge struct { + Cursor func(childComplexity int) int + Node func(childComplexity int) int + } + + PageInfo struct { + EndCursor func(childComplexity int) int + HasNextPage func(childComplexity int) int + HasPreviousPage func(childComplexity int) int + StartCursor func(childComplexity int) int + } + + Post struct { + Body func(childComplexity int) int + Category func(childComplexity int) int + CreatedAt func(childComplexity int) int + ExpireTime func(childComplexity int) int + Expires func(childComplexity int) int + ID func(childComplexity int) int + Profile func(childComplexity int) int + Title func(childComplexity int) int + UpdatedAt func(childComplexity int) int + } + + PostConnection struct { + Edges func(childComplexity int) int + PageInfo func(childComplexity int) int + TotalCount func(childComplexity int) int + } + + PostEdge struct { + Cursor func(childComplexity int) int + Node func(childComplexity int) int + } + + Profile struct { + Address func(childComplexity int) int + CreatedAt func(childComplexity int) int + ID func(childComplexity int) int + Name func(childComplexity int) int + Phone func(childComplexity int) int + Posts func(childComplexity int, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.PostOrder, where *ent.PostWhereInput) int + UpdatedAt func(childComplexity int) int + } + + ProfileConnection struct { + Edges func(childComplexity int) int + PageInfo func(childComplexity int) int + TotalCount func(childComplexity int) int + } + + ProfileEdge struct { + Cursor func(childComplexity int) int + Node func(childComplexity int) int + } + + Query struct { + Categories func(childComplexity int, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.CategoryOrder, where *ent.CategoryWhereInput) int + Node func(childComplexity int, id uuid.UUID) int + Nodes func(childComplexity int, ids []uuid.UUID) int + Posts func(childComplexity int, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.PostOrder, where *ent.PostWhereInput) int + Profiles func(childComplexity int, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.ProfileOrder, where *ent.ProfileWhereInput) int + } +} + +type executableSchema struct { + schema *ast.Schema + resolvers ResolverRoot + directives DirectiveRoot + complexity ComplexityRoot +} + +func (e *executableSchema) Schema() *ast.Schema { + if e.schema != nil { + return e.schema + } + return parsedSchema +} + +func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e, 0, 0, nil} + _ = ec + switch typeName + "." + field { + + case "Category.createdAt": + if e.complexity.Category.CreatedAt == nil { + break + } + + return e.complexity.Category.CreatedAt(childComplexity), true + + case "Category.description": + if e.complexity.Category.Description == nil { + break + } + + return e.complexity.Category.Description(childComplexity), true + + case "Category.id": + if e.complexity.Category.ID == nil { + break + } + + return e.complexity.Category.ID(childComplexity), true + + case "Category.posts": + if e.complexity.Category.Posts == nil { + break + } + + args, err := ec.field_Category_posts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Category.Posts(childComplexity, args["after"].(*entgql.Cursor[uuid.UUID]), args["first"].(*int), args["before"].(*entgql.Cursor[uuid.UUID]), args["last"].(*int), args["orderBy"].(*ent.PostOrder), args["where"].(*ent.PostWhereInput)), true + + case "Category.title": + if e.complexity.Category.Title == nil { + break + } + + return e.complexity.Category.Title(childComplexity), true + + case "Category.updatedAt": + if e.complexity.Category.UpdatedAt == nil { + break + } + + return e.complexity.Category.UpdatedAt(childComplexity), true + + case "CategoryConnection.edges": + if e.complexity.CategoryConnection.Edges == nil { + break + } + + return e.complexity.CategoryConnection.Edges(childComplexity), true + + case "CategoryConnection.pageInfo": + if e.complexity.CategoryConnection.PageInfo == nil { + break + } + + return e.complexity.CategoryConnection.PageInfo(childComplexity), true + + case "CategoryConnection.totalCount": + if e.complexity.CategoryConnection.TotalCount == nil { + break + } + + return e.complexity.CategoryConnection.TotalCount(childComplexity), true + + case "CategoryEdge.cursor": + if e.complexity.CategoryEdge.Cursor == nil { + break + } + + return e.complexity.CategoryEdge.Cursor(childComplexity), true + + case "CategoryEdge.node": + if e.complexity.CategoryEdge.Node == nil { + break + } + + return e.complexity.CategoryEdge.Node(childComplexity), true + + case "PageInfo.endCursor": + if e.complexity.PageInfo.EndCursor == nil { + break + } + + return e.complexity.PageInfo.EndCursor(childComplexity), true + + case "PageInfo.hasNextPage": + if e.complexity.PageInfo.HasNextPage == nil { + break + } + + return e.complexity.PageInfo.HasNextPage(childComplexity), true + + case "PageInfo.hasPreviousPage": + if e.complexity.PageInfo.HasPreviousPage == nil { + break + } + + return e.complexity.PageInfo.HasPreviousPage(childComplexity), true + + case "PageInfo.startCursor": + if e.complexity.PageInfo.StartCursor == nil { + break + } + + return e.complexity.PageInfo.StartCursor(childComplexity), true + + case "Post.body": + if e.complexity.Post.Body == nil { + break + } + + return e.complexity.Post.Body(childComplexity), true + + case "Post.category": + if e.complexity.Post.Category == nil { + break + } + + return e.complexity.Post.Category(childComplexity), true + + case "Post.createdAt": + if e.complexity.Post.CreatedAt == nil { + break + } + + return e.complexity.Post.CreatedAt(childComplexity), true + + case "Post.expireTime": + if e.complexity.Post.ExpireTime == nil { + break + } + + return e.complexity.Post.ExpireTime(childComplexity), true + + case "Post.expires": + if e.complexity.Post.Expires == nil { + break + } + + return e.complexity.Post.Expires(childComplexity), true + + case "Post.id": + if e.complexity.Post.ID == nil { + break + } + + return e.complexity.Post.ID(childComplexity), true + + case "Post.profile": + if e.complexity.Post.Profile == nil { + break + } + + return e.complexity.Post.Profile(childComplexity), true + + case "Post.title": + if e.complexity.Post.Title == nil { + break + } + + return e.complexity.Post.Title(childComplexity), true + + case "Post.updatedAt": + if e.complexity.Post.UpdatedAt == nil { + break + } + + return e.complexity.Post.UpdatedAt(childComplexity), true + + case "PostConnection.edges": + if e.complexity.PostConnection.Edges == nil { + break + } + + return e.complexity.PostConnection.Edges(childComplexity), true + + case "PostConnection.pageInfo": + if e.complexity.PostConnection.PageInfo == nil { + break + } + + return e.complexity.PostConnection.PageInfo(childComplexity), true + + case "PostConnection.totalCount": + if e.complexity.PostConnection.TotalCount == nil { + break + } + + return e.complexity.PostConnection.TotalCount(childComplexity), true + + case "PostEdge.cursor": + if e.complexity.PostEdge.Cursor == nil { + break + } + + return e.complexity.PostEdge.Cursor(childComplexity), true + + case "PostEdge.node": + if e.complexity.PostEdge.Node == nil { + break + } + + return e.complexity.PostEdge.Node(childComplexity), true + + case "Profile.address": + if e.complexity.Profile.Address == nil { + break + } + + return e.complexity.Profile.Address(childComplexity), true + + case "Profile.createdAt": + if e.complexity.Profile.CreatedAt == nil { + break + } + + return e.complexity.Profile.CreatedAt(childComplexity), true + + case "Profile.id": + if e.complexity.Profile.ID == nil { + break + } + + return e.complexity.Profile.ID(childComplexity), true + + case "Profile.name": + if e.complexity.Profile.Name == nil { + break + } + + return e.complexity.Profile.Name(childComplexity), true + + case "Profile.phone": + if e.complexity.Profile.Phone == nil { + break + } + + return e.complexity.Profile.Phone(childComplexity), true + + case "Profile.posts": + if e.complexity.Profile.Posts == nil { + break + } + + args, err := ec.field_Profile_posts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Profile.Posts(childComplexity, args["after"].(*entgql.Cursor[uuid.UUID]), args["first"].(*int), args["before"].(*entgql.Cursor[uuid.UUID]), args["last"].(*int), args["orderBy"].(*ent.PostOrder), args["where"].(*ent.PostWhereInput)), true + + case "Profile.updatedAt": + if e.complexity.Profile.UpdatedAt == nil { + break + } + + return e.complexity.Profile.UpdatedAt(childComplexity), true + + case "ProfileConnection.edges": + if e.complexity.ProfileConnection.Edges == nil { + break + } + + return e.complexity.ProfileConnection.Edges(childComplexity), true + + case "ProfileConnection.pageInfo": + if e.complexity.ProfileConnection.PageInfo == nil { + break + } + + return e.complexity.ProfileConnection.PageInfo(childComplexity), true + + case "ProfileConnection.totalCount": + if e.complexity.ProfileConnection.TotalCount == nil { + break + } + + return e.complexity.ProfileConnection.TotalCount(childComplexity), true + + case "ProfileEdge.cursor": + if e.complexity.ProfileEdge.Cursor == nil { + break + } + + return e.complexity.ProfileEdge.Cursor(childComplexity), true + + case "ProfileEdge.node": + if e.complexity.ProfileEdge.Node == nil { + break + } + + return e.complexity.ProfileEdge.Node(childComplexity), true + + case "Query.categories": + if e.complexity.Query.Categories == nil { + break + } + + args, err := ec.field_Query_categories_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Categories(childComplexity, args["after"].(*entgql.Cursor[uuid.UUID]), args["first"].(*int), args["before"].(*entgql.Cursor[uuid.UUID]), args["last"].(*int), args["orderBy"].(*ent.CategoryOrder), args["where"].(*ent.CategoryWhereInput)), true + + case "Query.node": + if e.complexity.Query.Node == nil { + break + } + + args, err := ec.field_Query_node_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Node(childComplexity, args["id"].(uuid.UUID)), true + + case "Query.nodes": + if e.complexity.Query.Nodes == nil { + break + } + + args, err := ec.field_Query_nodes_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Nodes(childComplexity, args["ids"].([]uuid.UUID)), true + + case "Query.posts": + if e.complexity.Query.Posts == nil { + break + } + + args, err := ec.field_Query_posts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Posts(childComplexity, args["after"].(*entgql.Cursor[uuid.UUID]), args["first"].(*int), args["before"].(*entgql.Cursor[uuid.UUID]), args["last"].(*int), args["orderBy"].(*ent.PostOrder), args["where"].(*ent.PostWhereInput)), true + + case "Query.profiles": + if e.complexity.Query.Profiles == nil { + break + } + + args, err := ec.field_Query_profiles_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Profiles(childComplexity, args["after"].(*entgql.Cursor[uuid.UUID]), args["first"].(*int), args["before"].(*entgql.Cursor[uuid.UUID]), args["last"].(*int), args["orderBy"].(*ent.ProfileOrder), args["where"].(*ent.ProfileWhereInput)), true + + } + return 0, false +} + +func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { + rc := graphql.GetOperationContext(ctx) + ec := executionContext{rc, e, 0, 0, make(chan graphql.DeferredResult)} + inputUnmarshalMap := graphql.BuildUnmarshalerMap( + ec.unmarshalInputCategoryOrder, + ec.unmarshalInputCategoryWhereInput, + ec.unmarshalInputCreateCategoryInput, + ec.unmarshalInputCreatePostInput, + ec.unmarshalInputCreateProfileInput, + ec.unmarshalInputPostOrder, + ec.unmarshalInputPostWhereInput, + ec.unmarshalInputProfileOrder, + ec.unmarshalInputProfileWhereInput, + ec.unmarshalInputUpdateCategoryInput, + ec.unmarshalInputUpdatePostInput, + ec.unmarshalInputUpdateProfileInput, + ) + first := true + + switch rc.Operation.Operation { + case ast.Query: + return func(ctx context.Context) *graphql.Response { + var response graphql.Response + var data graphql.Marshaler + if first { + first = false + ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap) + data = ec._Query(ctx, rc.Operation.SelectionSet) + } else { + if atomic.LoadInt32(&ec.pendingDeferred) > 0 { + result := <-ec.deferredResults + atomic.AddInt32(&ec.pendingDeferred, -1) + data = result.Result + response.Path = result.Path + response.Label = result.Label + response.Errors = result.Errors + } else { + return nil + } + } + var buf bytes.Buffer + data.MarshalGQL(&buf) + response.Data = buf.Bytes() + if atomic.LoadInt32(&ec.deferred) > 0 { + hasNext := atomic.LoadInt32(&ec.pendingDeferred) > 0 + response.HasNext = &hasNext + } + + return &response + } + + default: + return graphql.OneShot(graphql.ErrorResponse(ctx, "unsupported GraphQL operation")) + } +} + +type executionContext struct { + *graphql.OperationContext + *executableSchema + deferred int32 + pendingDeferred int32 + deferredResults chan graphql.DeferredResult +} + +func (ec *executionContext) processDeferredGroup(dg graphql.DeferredGroup) { + atomic.AddInt32(&ec.pendingDeferred, 1) + go func() { + ctx := graphql.WithFreshResponseContext(dg.Context) + dg.FieldSet.Dispatch(ctx) + ds := graphql.DeferredResult{ + Path: dg.Path, + Label: dg.Label, + Result: dg.FieldSet, + Errors: graphql.GetErrors(ctx), + } + // null fields should bubble up + if dg.FieldSet.Invalids > 0 { + ds.Result = graphql.Null + } + ec.deferredResults <- ds + }() +} + +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapSchema(ec.Schema()), nil +} + +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(ec.Schema(), ec.Schema().Types[name]), nil +} + +var sources = []*ast.Source{ + {Name: "../../ent.graphql", Input: `directive @goField(forceResolver: Boolean, name: String, omittable: Boolean) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION +directive @goModel(model: String, models: [String!], forceGenerate: Boolean) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION +type Category implements Node { + id: ID! + createdAt: Time! + updatedAt: Time + title: String! + description: String + posts( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Posts returned from the connection. + """ + orderBy: PostOrder + + """ + Filtering options for Posts returned from the connection. + """ + where: PostWhereInput + ): PostConnection! +} +""" +A connection to a list of items. +""" +type CategoryConnection { + """ + A list of edges. + """ + edges: [CategoryEdge] + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! + """ + Identifies the total count of items in the connection. + """ + totalCount: Int! +} +""" +An edge in a connection. +""" +type CategoryEdge { + """ + The item at the end of the edge. + """ + node: Category + """ + A cursor for use in pagination. + """ + cursor: Cursor! +} +""" +Ordering options for Category connections +""" +input CategoryOrder { + """ + The ordering direction. + """ + direction: OrderDirection! = ASC + """ + The field by which to order Categories. + """ + field: CategoryOrderField! +} +""" +Properties by which Category connections can be ordered. +""" +enum CategoryOrderField { + CREATED_AT + UPDATED_AT + POSTS_COUNT +} +""" +CategoryWhereInput is used for filtering Category objects. +Input was generated by ent. +""" +input CategoryWhereInput { + not: CategoryWhereInput + and: [CategoryWhereInput!] + or: [CategoryWhereInput!] + """ + id field predicates + """ + id: ID + idNEQ: ID + idIn: [ID!] + idNotIn: [ID!] + idGT: ID + idGTE: ID + idLT: ID + idLTE: ID + """ + created_at field predicates + """ + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """ + updated_at field predicates + """ + updatedAt: Time + updatedAtNEQ: Time + updatedAtIn: [Time!] + updatedAtNotIn: [Time!] + updatedAtGT: Time + updatedAtGTE: Time + updatedAtLT: Time + updatedAtLTE: Time + updatedAtIsNil: Boolean + updatedAtNotNil: Boolean + """ + title field predicates + """ + title: String + titleNEQ: String + titleIn: [String!] + titleNotIn: [String!] + titleGT: String + titleGTE: String + titleLT: String + titleLTE: String + titleContains: String + titleHasPrefix: String + titleHasSuffix: String + titleEqualFold: String + titleContainsFold: String + """ + description field predicates + """ + description: String + descriptionNEQ: String + descriptionIn: [String!] + descriptionNotIn: [String!] + descriptionGT: String + descriptionGTE: String + descriptionLT: String + descriptionLTE: String + descriptionContains: String + descriptionHasPrefix: String + descriptionHasSuffix: String + descriptionIsNil: Boolean + descriptionNotNil: Boolean + descriptionEqualFold: String + descriptionContainsFold: String + """ + posts edge predicates + """ + hasPosts: Boolean + hasPostsWith: [PostWhereInput!] +} +""" +CreateCategoryInput is used for create Category object. +Input was generated by ent. +""" +input CreateCategoryInput { + createdAt: Time + updatedAt: Time + title: String! + description: String + postIDs: [ID!] +} +""" +CreatePostInput is used for create Post object. +Input was generated by ent. +""" +input CreatePostInput { + createdAt: Time + updatedAt: Time + expires: Boolean + expireTime: Time + title: String! + body: String! + categoryID: ID + profileID: ID +} +""" +CreateProfileInput is used for create Profile object. +Input was generated by ent. +""" +input CreateProfileInput { + createdAt: Time + updatedAt: Time + name: String + address: String + phone: String + postIDs: [ID!] +} +""" +Define a Relay Cursor type: +https://relay.dev/graphql/connections.htm#sec-Cursor +""" +scalar Cursor +""" +An object with an ID. +Follows the [Relay Global Object Identification Specification](https://relay.dev/graphql/objectidentification.htm) +""" +interface Node @goModel(model: "code.icod.de/dalu/ka/ent.Noder") { + """ + The id of the object. + """ + id: ID! +} +""" +Possible directions in which to order a list of items when provided an ` + "`" + `orderBy` + "`" + ` argument. +""" +enum OrderDirection { + """ + Specifies an ascending order for a given ` + "`" + `orderBy` + "`" + ` argument. + """ + ASC + """ + Specifies a descending order for a given ` + "`" + `orderBy` + "`" + ` argument. + """ + DESC +} +""" +Information about pagination in a connection. +https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo +""" +type PageInfo { + """ + When paginating forwards, are there more items? + """ + hasNextPage: Boolean! + """ + When paginating backwards, are there more items? + """ + hasPreviousPage: Boolean! + """ + When paginating backwards, the cursor to continue. + """ + startCursor: Cursor + """ + When paginating forwards, the cursor to continue. + """ + endCursor: Cursor +} +type Post implements Node { + id: ID! + createdAt: Time! + updatedAt: Time + expires: Boolean! + expireTime: Time + title: String! + body: String! + category: Category + profile: Profile +} +""" +A connection to a list of items. +""" +type PostConnection { + """ + A list of edges. + """ + edges: [PostEdge] + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! + """ + Identifies the total count of items in the connection. + """ + totalCount: Int! +} +""" +An edge in a connection. +""" +type PostEdge { + """ + The item at the end of the edge. + """ + node: Post + """ + A cursor for use in pagination. + """ + cursor: Cursor! +} +""" +Ordering options for Post connections +""" +input PostOrder { + """ + The ordering direction. + """ + direction: OrderDirection! = ASC + """ + The field by which to order Posts. + """ + field: PostOrderField! +} +""" +Properties by which Post connections can be ordered. +""" +enum PostOrderField { + CREATED_AT + UPDATED_AT + EXPIRE_TIME +} +""" +PostWhereInput is used for filtering Post objects. +Input was generated by ent. +""" +input PostWhereInput { + not: PostWhereInput + and: [PostWhereInput!] + or: [PostWhereInput!] + """ + id field predicates + """ + id: ID + idNEQ: ID + idIn: [ID!] + idNotIn: [ID!] + idGT: ID + idGTE: ID + idLT: ID + idLTE: ID + """ + created_at field predicates + """ + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """ + updated_at field predicates + """ + updatedAt: Time + updatedAtNEQ: Time + updatedAtIn: [Time!] + updatedAtNotIn: [Time!] + updatedAtGT: Time + updatedAtGTE: Time + updatedAtLT: Time + updatedAtLTE: Time + updatedAtIsNil: Boolean + updatedAtNotNil: Boolean + """ + expires field predicates + """ + expires: Boolean + expiresNEQ: Boolean + """ + expire_time field predicates + """ + expireTime: Time + expireTimeNEQ: Time + expireTimeIn: [Time!] + expireTimeNotIn: [Time!] + expireTimeGT: Time + expireTimeGTE: Time + expireTimeLT: Time + expireTimeLTE: Time + expireTimeIsNil: Boolean + expireTimeNotNil: Boolean + """ + title field predicates + """ + title: String + titleNEQ: String + titleIn: [String!] + titleNotIn: [String!] + titleGT: String + titleGTE: String + titleLT: String + titleLTE: String + titleContains: String + titleHasPrefix: String + titleHasSuffix: String + titleEqualFold: String + titleContainsFold: String + """ + body field predicates + """ + body: String + bodyNEQ: String + bodyIn: [String!] + bodyNotIn: [String!] + bodyGT: String + bodyGTE: String + bodyLT: String + bodyLTE: String + bodyContains: String + bodyHasPrefix: String + bodyHasSuffix: String + bodyEqualFold: String + bodyContainsFold: String + """ + category edge predicates + """ + hasCategory: Boolean + hasCategoryWith: [CategoryWhereInput!] + """ + profile edge predicates + """ + hasProfile: Boolean + hasProfileWith: [ProfileWhereInput!] +} +type Profile implements Node { + id: ID! + createdAt: Time! + updatedAt: Time + name: String + address: String + phone: String + posts( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Posts returned from the connection. + """ + orderBy: PostOrder + + """ + Filtering options for Posts returned from the connection. + """ + where: PostWhereInput + ): PostConnection! +} +""" +A connection to a list of items. +""" +type ProfileConnection { + """ + A list of edges. + """ + edges: [ProfileEdge] + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! + """ + Identifies the total count of items in the connection. + """ + totalCount: Int! +} +""" +An edge in a connection. +""" +type ProfileEdge { + """ + The item at the end of the edge. + """ + node: Profile + """ + A cursor for use in pagination. + """ + cursor: Cursor! +} +""" +Ordering options for Profile connections +""" +input ProfileOrder { + """ + The ordering direction. + """ + direction: OrderDirection! = ASC + """ + The field by which to order Profiles. + """ + field: ProfileOrderField! +} +""" +Properties by which Profile connections can be ordered. +""" +enum ProfileOrderField { + CREATED_AT + UPDATED_AT + POSTS_COUNT +} +""" +ProfileWhereInput is used for filtering Profile objects. +Input was generated by ent. +""" +input ProfileWhereInput { + not: ProfileWhereInput + and: [ProfileWhereInput!] + or: [ProfileWhereInput!] + """ + id field predicates + """ + id: ID + idNEQ: ID + idIn: [ID!] + idNotIn: [ID!] + idGT: ID + idGTE: ID + idLT: ID + idLTE: ID + """ + created_at field predicates + """ + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """ + updated_at field predicates + """ + updatedAt: Time + updatedAtNEQ: Time + updatedAtIn: [Time!] + updatedAtNotIn: [Time!] + updatedAtGT: Time + updatedAtGTE: Time + updatedAtLT: Time + updatedAtLTE: Time + updatedAtIsNil: Boolean + updatedAtNotNil: Boolean + """ + 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 + """ + address field predicates + """ + address: String + addressNEQ: String + addressIn: [String!] + addressNotIn: [String!] + addressGT: String + addressGTE: String + addressLT: String + addressLTE: String + addressContains: String + addressHasPrefix: String + addressHasSuffix: String + addressIsNil: Boolean + addressNotNil: Boolean + addressEqualFold: String + addressContainsFold: String + """ + phone field predicates + """ + phone: String + phoneNEQ: String + phoneIn: [String!] + phoneNotIn: [String!] + phoneGT: String + phoneGTE: String + phoneLT: String + phoneLTE: String + phoneContains: String + phoneHasPrefix: String + phoneHasSuffix: String + phoneIsNil: Boolean + phoneNotNil: Boolean + phoneEqualFold: String + phoneContainsFold: String + """ + posts edge predicates + """ + hasPosts: Boolean + hasPostsWith: [PostWhereInput!] +} +type Query { + """ + Fetches an object given its ID. + """ + node( + """ + ID of the object. + """ + id: ID! + ): Node + """ + Lookup nodes by a list of IDs. + """ + nodes( + """ + The list of node IDs. + """ + ids: [ID!]! + ): [Node]! + categories( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Categories returned from the connection. + """ + orderBy: CategoryOrder + + """ + Filtering options for Categories returned from the connection. + """ + where: CategoryWhereInput + ): CategoryConnection! + posts( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Posts returned from the connection. + """ + orderBy: PostOrder + + """ + Filtering options for Posts returned from the connection. + """ + where: PostWhereInput + ): PostConnection! + profiles( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: Cursor + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: Cursor + + """ + Returns the last _n_ elements from the list. + """ + last: Int + + """ + Ordering options for Profiles returned from the connection. + """ + orderBy: ProfileOrder + + """ + Filtering options for Profiles returned from the connection. + """ + where: ProfileWhereInput + ): ProfileConnection! +} +""" +The builtin Time type +""" +scalar Time +""" +UpdateCategoryInput is used for update Category object. +Input was generated by ent. +""" +input UpdateCategoryInput { + updatedAt: Time + clearUpdatedAt: Boolean + title: String + description: String + clearDescription: Boolean + addPostIDs: [ID!] + removePostIDs: [ID!] + clearPosts: Boolean +} +""" +UpdatePostInput is used for update Post object. +Input was generated by ent. +""" +input UpdatePostInput { + updatedAt: Time + clearUpdatedAt: Boolean + expires: Boolean + expireTime: Time + clearExpireTime: Boolean + title: String + body: String + categoryID: ID + clearCategory: Boolean + profileID: ID + clearProfile: Boolean +} +""" +UpdateProfileInput is used for update Profile object. +Input was generated by ent. +""" +input UpdateProfileInput { + updatedAt: Time + clearUpdatedAt: Boolean + name: String + clearName: Boolean + address: String + clearAddress: Boolean + phone: String + clearPhone: Boolean + addPostIDs: [ID!] + removePostIDs: [ID!] + clearPosts: Boolean +} +`, BuiltIn: false}, +} +var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/graph/resolver.go b/graph/resolver.go new file mode 100644 index 0000000..a320472 --- /dev/null +++ b/graph/resolver.go @@ -0,0 +1,21 @@ +package graph + +import ( + "code.icod.de/dalu/ka/ent" + "code.icod.de/dalu/ka/graph/generated" + "github.com/99designs/gqlgen/graphql" +) + +// This file will not be regenerated automatically. +// +// It serves as dependency injection for your app, add any dependencies you require here. + +type Resolver struct { + client *ent.Client +} + +func NewSchema(client *ent.Client) graphql.ExecutableSchema { + return generated.NewExecutableSchema(generated.Config{ + Resolvers: &Resolver{client}, + }) +}