Skip to content

Commit

Permalink
fix(cli): wrong subgraph directory discovery and remove confirmation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac authored Dec 2, 2024
1 parent f3595d0 commit 2280487
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 41 deletions.
1 change: 0 additions & 1 deletion connector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,6 @@ func TestConnectorTLS(t *testing.T) {
})
}()

time.Sleep(2 * time.Second)
assert.Equal(t, 1, mockServer.Count())
assert.Equal(t, 1, mockServer1.Count())
}
11 changes: 2 additions & 9 deletions ndc-http-schema/command/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

// UpdateCommandArguments represent input arguments of the `update` command
type UpdateCommandArguments struct {
Dir string `default:"." env:"HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH" help:"The directory where the config.yaml file is present" short:"d"`
Yes bool `default:"false" help:"Skip the continue confirmation prompt" short:"y"`
Dir string `default:"." env:"HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH" help:"The directory where the config.yaml file is present" short:"d"`
}

// UpdateConfiguration updates the configuration for the HTTP connector
Expand All @@ -37,13 +36,7 @@ func UpdateConfiguration(args *UpdateCommandArguments, logger *slog.Logger, noCo
return errors.New("Detected configuration errors. Update your configuration and try again.")
}

if !args.Yes {
if err := validStatus.PrintWarningConfirmation(); err != nil {
return err
}
}

logger.Info("updated successfully", slog.Duration("exec_time", time.Since(start)))
logger.Info("Updated successfully", slog.Duration("exec_time", time.Since(start)))

return nil
}
2 changes: 0 additions & 2 deletions ndc-http-schema/command/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ func TestUpdateCommand(t *testing.T) {
{
Argument: UpdateCommandArguments{
Dir: "testdata/patch",
Yes: true,
},
Expected: "testdata/patch/expected.json",
},
// go run ./ndc-http-schema update -d ./ndc-http-schema/command/testdata/auth
{
Argument: UpdateCommandArguments{
Dir: "testdata/auth",
Yes: true,
},
Expected: "testdata/auth/expected.json",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# yaml-language-server: $schema=../../../../jsonschema/configuration.schema.json
# yaml-language-server: $schema=../../../../../jsonschema/configuration.schema.json
strict: true
forwardHeaders:
enabled: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# yaml-language-server: $schema=../../../../jsonschema/configuration.schema.json
# yaml-language-server: $schema=../../../../../jsonschema/configuration.schema.json
strict: true
forwardHeaders:
enabled: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# yaml-language-server: $schema=../../../../jsonschema/ndc-http-schema.schema.json
# yaml-language-server: $schema=../../../../../jsonschema/ndc-http-schema.schema.json
settings:
servers:
- url:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# yaml-language-server: $schema=../../../../jsonschema/ndc-http-schema.schema.json
# yaml-language-server: $schema=../../../../../jsonschema/ndc-http-schema.schema.json
settings:
servers:
- url:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WARNING:
Environment Variables:
Make sure that the following environment variables were added to your subgraph configuration:

``` testdata/validation/connector/docker.yaml
``` testdata/validation/connector/http/docker.yaml
services:
app_myapi:
environment:
Expand All @@ -28,7 +28,7 @@ Environment Variables:

```

``` testdata/validation/connector/connector.yaml
``` testdata/validation/connector/http/connector.yaml
envMapping:
CAT_PET_HEADER
fromEnv: APP_MYAPI_CAT_PET_HEADER
Expand Down
23 changes: 1 addition & 22 deletions ndc-http-schema/configuration/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package configuration

import (
"bytes"
"errors"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"slices"
"strings"
"text/template"

Expand Down Expand Up @@ -398,7 +396,7 @@ func (cv *ConfigValidator) findSubgraphName() string {
return ""
}

connectorPath := filepath.Join(cv.contextPath, "..", "subgraph.yaml")
connectorPath := filepath.Join(cv.contextPath, "..", "..", "subgraph.yaml")
rawBytes, err := os.ReadFile(connectorPath)
if err != nil {
cv.logger.Error(fmt.Sprintf("failed to read the subgraph manifest: %s", err))
Expand Down Expand Up @@ -442,22 +440,3 @@ func (cv *ConfigValidator) addError(namespace string, value string) {
cv.errors[namespace] = append(cv.errors[namespace], value)
}
}

// PrintWarningConfirmation prints the warning confirmation prompt.
func (cv *ConfigValidator) PrintWarningConfirmation() error {
fmt.Fprint(os.Stderr, "\nDetected configuration warnings. Check your configuration and continue [Y/n]: ")
var shouldContinue string
_, err := fmt.Scan(&shouldContinue)
if err != nil {
return err
}

if !slices.Contains([]string{"y", "yes"}, strings.ToLower(shouldContinue)) {
err := errors.New("stop the introspection.")
fmt.Fprint(os.Stderr, err.Error()+"\n")

return err
}

return nil
}
2 changes: 1 addition & 1 deletion ndc-http-schema/configuration/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestConfigValidator(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.Dir, func(t *testing.T) {
connectorDir := filepath.Join(tc.Dir, "connector")
connectorDir := filepath.Join(tc.Dir, "connector", "http")
expectedBytes, err := os.ReadFile(filepath.Join(tc.Dir, "expected.tpl"))
config, schemas, err := UpdateHTTPConfiguration(connectorDir, slog.Default())
if tc.ErrorMsg != "" {
Expand Down

0 comments on commit 2280487

Please sign in to comment.