Skip to content

Commit

Permalink
fix: change cwd to load gqlgen config correctly (#103)
Browse files Browse the repository at this point in the history
Code copied from 99designs/gqlgen#1511
  • Loading branch information
giautm authored Jul 8, 2021
1 parent a52eb13 commit 7b57be4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion entgql/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package entgql
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -85,7 +86,21 @@ func WithSchemaPath(path string) ExtensionOption {
// GraphQL integration,
func WithConfigPath(path string) ExtensionOption {
return func(ex *Extension) error {
cfg, err := config.LoadConfig(path)
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("unable to get working directory: %w", err)
}
err = os.Chdir(filepath.Dir(path))
if err != nil {
return fmt.Errorf("unable to enter config dir: %w", err)
}
defer func() {
if cerr := os.Chdir(cwd); cerr != nil {
err = fmt.Errorf("unable to restore working directory: %w", cerr)
}
}()

cfg, err := config.LoadConfig(filepath.Base(path))
if err != nil {
return err
}
Expand Down

0 comments on commit 7b57be4

Please sign in to comment.