-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ReplacePlugin option to replace a specific plugin (#1657)
* Add Helper Option for replacing plugins * Update recipe to use ReplacePlugin instead of NoPlugin and AddPlugin * fix linting issue on comment
- Loading branch information
Showing
3 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package api | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/99designs/gqlgen/codegen/config" | ||
"github.com/99designs/gqlgen/plugin" | ||
"github.com/99designs/gqlgen/plugin/federation" | ||
"github.com/99designs/gqlgen/plugin/modelgen" | ||
"github.com/99designs/gqlgen/plugin/resolvergen" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type testPlugin struct { | ||
} | ||
|
||
// Name returns the plugin name | ||
func (t *testPlugin) Name() string { | ||
return "modelgen" | ||
} | ||
|
||
// MutateConfig mutates the configuration | ||
func (t *testPlugin) MutateConfig(_ *config.Config) error { | ||
return nil | ||
} | ||
|
||
func TestReplacePlugin(t *testing.T) { | ||
|
||
t.Run("replace plugin if exists", func(t *testing.T) { | ||
pg := []plugin.Plugin{ | ||
federation.New(), | ||
modelgen.New(), | ||
resolvergen.New(), | ||
} | ||
|
||
expectedPlugin := &testPlugin{} | ||
ReplacePlugin(expectedPlugin)(config.DefaultConfig(), &pg) | ||
|
||
require.EqualValues(t, federation.New(), pg[0]) | ||
require.EqualValues(t, expectedPlugin, pg[1]) | ||
require.EqualValues(t, resolvergen.New(), pg[2]) | ||
}) | ||
|
||
t.Run("add plugin if doesn't exist", func(t *testing.T) { | ||
pg := []plugin.Plugin{ | ||
federation.New(), | ||
resolvergen.New(), | ||
} | ||
|
||
expectedPlugin := &testPlugin{} | ||
ReplacePlugin(expectedPlugin)(config.DefaultConfig(), &pg) | ||
|
||
require.EqualValues(t, federation.New(), pg[0]) | ||
require.EqualValues(t, resolvergen.New(), pg[1]) | ||
require.EqualValues(t, expectedPlugin, pg[2]) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters