From 4640d8e0ece3db2186e29d79ab51228e2d64698e Mon Sep 17 00:00:00 2001 From: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:39:27 +0200 Subject: [PATCH] entc/gen: keep internal feature-flags private (#3832) --- entc/gen/feature.go | 3 ++- entc/gen/graph.go | 4 ++-- entc/gen/graph_test.go | 26 ++------------------------ 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/entc/gen/feature.go b/entc/gen/feature.go index c2f7eaafe..bb536ded3 100644 --- a/entc/gen/feature.go +++ b/entc/gen/feature.go @@ -142,13 +142,14 @@ var ( FeatureNamedEdges, FeatureSnapshot, FeatureSchemaConfig, - featureMultiSchema, FeatureLock, FeatureModifier, FeatureExecQuery, FeatureUpsert, FeatureVersionedMigration, } + // allFeatures includes all public and private features. + allFeatures = append(AllFeatures, featureMultiSchema) ) // FeatureStage describes the stage of the codegen feature. diff --git a/entc/gen/graph.go b/entc/gen/graph.go index 639142106..d21cbcad3 100644 --- a/entc/gen/graph.go +++ b/entc/gen/graph.go @@ -249,7 +249,7 @@ func generate(g *Graph) error { } assets.add(filepath.Join(g.Config.Target, tmpl.Format), b.Bytes()) } - for _, f := range AllFeatures { + for _, f := range allFeatures { if f.cleanup == nil || g.featureEnabled(f) { continue } @@ -979,7 +979,7 @@ func (Config) ModuleInfo() (m debug.Module) { // ... // {{ end }} func (c Config) FeatureEnabled(name string) (bool, error) { - for _, f := range AllFeatures { + for _, f := range allFeatures { if name == f.Name { return c.featureEnabled(f), nil } diff --git a/entc/gen/graph_test.go b/entc/gen/graph_test.go index 6dd30b724..171a1c852 100644 --- a/entc/gen/graph_test.go +++ b/entc/gen/graph_test.go @@ -434,18 +434,7 @@ func TestGraph_Gen(t *testing.T) { Storage: drivers[0], Templates: []*Template{external, skipped}, IDType: &field.TypeInfo{Type: field.TypeInt}, - Features: []Feature{ - FeaturePrivacy, - FeatureIntercept, - FeatureEntQL, - FeatureNamedEdges, - FeatureSnapshot, - FeatureSchemaConfig, - FeatureLock, - FeatureModifier, - FeatureExecQuery, - FeatureUpsert, - }, + Features: AllFeatures, }, schemas...) require.NoError(err) require.NotNil(graph) @@ -493,18 +482,7 @@ func TestGraph_Gen(t *testing.T) { Storage: drivers[0], Templates: []*Template{external, skipped}, IDType: &field.TypeInfo{Type: field.TypeInt}, - Features: []Feature{ - FeaturePrivacy, - FeatureIntercept, - FeatureEntQL, - FeatureNamedEdges, - FeatureSnapshot, - FeatureSchemaConfig, - FeatureLock, - FeatureModifier, - FeatureExecQuery, - FeatureUpsert, - }, + Features: AllFeatures, }, schemas...) require.NoError(err) require.NotNil(graph)