Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions entgql/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type (
QueryField *FieldConfig `json:"QueryField,omitempty"`
// MutationInputs defines the input types for the mutation.
MutationInputs []MutationConfig `json:"MutationInputs,omitempty"`
// CollectedFor indicates that this field should be collected when any of the specified GraphQL field names are queried.
// This is useful for resolver fields that depend on this field's value.
CollectedFor []string `json:"CollectedFor,omitempty"`
}

// Directive to apply on the field/type.
Expand Down Expand Up @@ -180,6 +183,23 @@ func MapsTo(names ...string) Annotation {
}
}

// CollectedFor returns an annotation indicating that this field should be collected
// when any of the specified GraphQL field names are queried. This is useful for
// resolver fields that depend on this field's value.
//
// For example, if you have a resolver field `uppercaseName` that depends on the `name` field:
//
// field.String("name").
// Annotations(entgql.CollectedFor("uppercaseName"))
//
// When `uppercaseName` is queried, the `name` field will be automatically fetched,
// ensuring `unknownSeen` remains false and the field is available in the resolver.
func CollectedFor(names ...string) Annotation {
return Annotation{
CollectedFor: names,
}
}

// Type returns a type mapping annotation.
// The Type() annotation is used to map the underlying
// GraphQL type to the type.
Expand Down Expand Up @@ -482,6 +502,9 @@ func (a Annotation) Merge(other schema.Annotation) schema.Annotation {
}
a.QueryField.merge(ant.QueryField)
}
if len(ant.CollectedFor) > 0 {
a.CollectedFor = append(a.CollectedFor, ant.CollectedFor...)
}
return a
}

Expand Down
22 changes: 22 additions & 0 deletions entgql/internal/todo/ent.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ input CreateTodoInput {
status: TodoStatus!
priority: Int
text: String!
name: String
init: Map
value: Int
parentID: ID
Expand Down Expand Up @@ -969,6 +970,7 @@ type Todo implements Node {
status: TodoStatus!
priorityOrder: Int! @goField(name: "Priority", forceResolver: false)
text: String!
name: String
categoryID: ID
category_id: ID
categoryX: ID @goField(name: "CategoryID", forceResolver: false)
Expand Down Expand Up @@ -1138,6 +1140,24 @@ input TodoWhereInput {
textEqualFold: String
textContainsFold: String
"""
name field predicates
"""
name: String
nameNEQ: String
nameIn: [String!]
nameNotIn: [String!]
nameGT: String
nameGTE: String
nameLT: String
nameLTE: String
nameContains: String
nameHasPrefix: String
nameHasSuffix: String
nameIsNil: Boolean
nameNotNil: Boolean
nameEqualFold: String
nameContainsFold: String
"""
category_id field predicates
"""
categoryID: ID
Expand Down Expand Up @@ -1219,6 +1239,8 @@ input UpdateTodoInput {
status: TodoStatus
priority: Int
text: String
name: String
clearName: Boolean
init: Map
clearInit: Boolean
value: Int
Expand Down
5 changes: 5 additions & 0 deletions entgql/internal/todo/ent/gql_collection.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions entgql/internal/todo/ent/gql_mutation_input.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions entgql/internal/todo/ent/gql_node_descriptor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions entgql/internal/todo/ent/gql_where_input.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions entgql/internal/todo/ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading