From b91d7203a9bb0d636256bb5fbab1fd6d4981c760 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 24 Jan 2022 16:02:49 +0900 Subject: [PATCH 1/2] add PrependPlugin related: https://github.com/99designs/gqlgen/pull/1838 --- api/option.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/option.go b/api/option.go index e1a750fd53..739af9aa4a 100644 --- a/api/option.go +++ b/api/option.go @@ -19,6 +19,13 @@ func AddPlugin(p plugin.Plugin) Option { } } +// PrependPlugin prepends plugin any existing plugins +func PrependPlugin(p plugin.Plugin) Option { + return func(cfg *config.Config, plugins *[]plugin.Plugin) { + *plugins = append([]plugin.Plugin{p}, *plugins...) + } +} + // ReplacePlugin replaces any existing plugin with a matching plugin name func ReplacePlugin(p plugin.Plugin) Option { return func(cfg *config.Config, plugins *[]plugin.Plugin) { From 41968449de50c0b8021192dc884336059d79f5c1 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 24 Jan 2022 23:59:07 +0900 Subject: [PATCH 2/2] added test for PrependPlugin --- api/option_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api/option_test.go b/api/option_test.go index 205202685c..11b13f3011 100644 --- a/api/option_test.go +++ b/api/option_test.go @@ -53,3 +53,16 @@ func TestReplacePlugin(t *testing.T) { require.EqualValues(t, expectedPlugin, pg[2]) }) } + +func TestPrependPlugin(t *testing.T) { + modelgenPlugin := modelgen.New() + pg := []plugin.Plugin{ + modelgenPlugin, + } + + expectedPlugin := &testPlugin{} + PrependPlugin(expectedPlugin)(config.DefaultConfig(), &pg) + + require.EqualValues(t, expectedPlugin, pg[0]) + require.EqualValues(t, modelgenPlugin, pg[1]) +}