-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
entgql: refactor Skip annotation #268
Conversation
437a0b9
to
e46c4ca
Compare
entgql/annotation.go
Outdated
SkipFlagType SkipFlag = 1 << iota | ||
// SkipFlagFieldEnum will skip generate Enum from the enum field | ||
SkipFlagFieldEnum | ||
// SkipFlagInput will skip mutation input for the entity/field | ||
SkipFlagInput | ||
// SkipFlagWhere will skip input filter for the entity/field | ||
SkipFlagWhere | ||
// SkipFlagOrder will skip generate sort order for the entity | ||
SkipFlagOrder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SkipFlagType SkipFlag = 1 << iota | |
// SkipFlagFieldEnum will skip generate Enum from the enum field | |
SkipFlagFieldEnum | |
// SkipFlagInput will skip mutation input for the entity/field | |
SkipFlagInput | |
// SkipFlagWhere will skip input filter for the entity/field | |
SkipFlagWhere | |
// SkipFlagOrder will skip generate sort order for the entity | |
SkipFlagOrder | |
SkipNode SkipFlag = 1 << iota | |
// SkipEnum will skip generate Enum from the enum field | |
SkipEnumField | |
// SkipMutationInput will skip mutation input for the entity/field | |
SkipMutationInput | |
// SkipWhereInput will skip input filter for the entity/field | |
SkipWhereInput | |
// SkipOrderField will skip generate sort order for the entity | |
SkipOrderField |
I'm thinking about how the API will look and I shorter feels cleaner to me. Another point, what does it mean to SkipOrderField
or SkipEnumField
? Skip generating only GraphQL or also in Ent? Do we need a flag for both options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SkipNode
: I thought about this name before, because we need to use it for all fields. So SkipNode
does not seem appropriate. Do we need to add SkipField
as well? SkipType
seems more suitable to me, as it comes with SkipInput
Another point, what does it mean to SkipOrderField or SkipEnumField? Skip generating only GraphQL or also in Ent
It should skip generating both Go code and GQL schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SkipType
seems more suitable to me, as it comes withSkipInput
Right, let's use SkipType
. I wonder how's the usage will look like:
func (T) Annotations() []schema.Annotation {
return []schema.Annotation{
// Default to skip All.
entgql.Skip(),
// Or, skip only type and input generation.
entgql.Skip(entgql.SkipType|entgql.SkipInput),
}
}
func (T) Fields() []ent.Field {
return []ent.Field{
field.Int("age").
Annotations(
// Skip all.
entgql.Skip(),
// Or, skip only from input?
entgql.Skip(entgql.SkipInput),
),
}
}
This is the API you thought about or you have something else in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's almost the same.
func (T) Annotations() []schema.Annotation {
return []schema.Annotation{
// Default to skip All.
entgql.Skip(),
// Or, skip only type and input generation.
entgql.Skip(entgql.SkipType, entgql.SkipMutationInput),
}
}
func (T) Fields() []ent.Field {
return []ent.Field{
field.Int("age").
Annotations(
// Skip all.
entgql.Skip(),
// Or, skip only from input?
entgql.Skip(entgql.SkipMutationInput),
),
}
}
e46c4ca
to
b76066e
Compare
entgql/annotation.go
Outdated
const ( | ||
// SkipType will skip generating the entity or field in the schema | ||
SkipType SkipMode = 1 << iota | ||
// SkipEnumField will skip generating the enum type from the enum field | ||
SkipEnumField | ||
// SkipOrderField will skip generating the entity or the field for the enum order | ||
SkipOrderField | ||
// SkipWhereInput will skip generating the entity or the field in the WhereInput | ||
SkipWhereInput | ||
|
||
// SkipAll is default mode to skip all | ||
SkipAll = SkipType | | ||
SkipEnumField | | ||
SkipOrderField | | ||
SkipWhereInput |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @a8m, let's review the naming and the description again.
ccaaf29
to
f9f1ad5
Compare
entgql/annotation.go
Outdated
// Any returns true if the skip annotation is setted | ||
func (f SkipMode) Any() bool { | ||
return f != 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it's preferred over != 0
?
entgql/template.go
Outdated
@@ -71,6 +71,8 @@ var ( | |||
"filterNodes": filterNodes, | |||
"findIDType": findIDType, | |||
"nodePaginationNames": nodePaginationNames, | |||
"skipMode": skipModeFromString, | |||
"hasSkipMode": hasSkipMode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not needed IMO, you can use the skipMode
function in the template (0 is falsy).
@@ -152,15 +154,15 @@ func filterNodes(nodes []*gen.Type) ([]*gen.Type, error) { | |||
} | |||
|
|||
// filterEdges filters out edges that should not be included in the GraphQL schema. | |||
func filterEdges(edges []*gen.Edge) ([]*gen.Edge, error) { | |||
func filterEdges(edges []*gen.Edge, skip SkipMode) ([]*gen.Edge, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it an optional param to not break existing templates used by users.
Because we don't use it yet
Co-authored-by: Ariel Mashraki <[email protected]>
Co-authored-by: Ariel Mashraki <[email protected]>
9e0ba20
to
c8eb2be
Compare
Related to ent/ent#2351 (comment)