graphql-engine/cli/commands/metadata_reload.go
Kali Vara Purushotham Santhati 489835eb36 cli: metadata apply,export enhancements
- modified the `dry-run` flag of metadata apply command.
- added new flag `o` which takes "json" or "yaml" as parameters for metadata apply command.
- added new flag `o` which takes "json" or "yaml" as parameters for metadata export command. It outputs the metadata from server to stdout in form of  json or yaml and won't change the project's metadata.
- added deprecation warnings for `--from-file` flag
- added info message for describing change of behavior of `--dry-run` flag
- v3 metadata objects like `rest_endpoints` was also added to list of metadata objects in config v2 (fix)
- the order in which metadata objects are appended to metadata objects list matter when using `--dry-run` flag, refactored this order to match server metadata.
- `metadata apply` command can now accept json/yaml metadata from io pipe
- config v3 `metadata apply` didn't show any information to user when applied metadata is inconsistent, this is addressed.
- removed `github.com/ghodss/yaml` dependency from repo
- version metadata object was added twice during intialization (fix)

Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com>
GitOrigin-RevId: 2316f519eb40645efd86ffee2a85d3c90543ec17
2021-05-14 19:09:59 +00:00

56 lines
1.3 KiB
Go

package commands
import (
"github.com/hasura/graphql-engine/cli"
"github.com/hasura/graphql-engine/cli/internal/metadataobject"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func newMetadataReloadCmd(ec *cli.ExecutionContext) *cobra.Command {
opts := &metadataReloadOptions{
EC: ec,
}
metadataReloadCmd := &cobra.Command{
Use: "reload",
Short: "Reload Hasura GraphQL engine metadata on the database",
Example: ` # Reload all the metadata information from database:
hasura metadata reload
# Use with admin secret:
hasura metadata reload --admin-secret "<admin-secret>"
# Reload metadata on a different instance:
hasura metadata export --endpoint "<endpoint>"`,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
opts.EC.Spin("Reloading metadata...")
err := opts.run()
opts.EC.Spinner.Stop()
if err != nil {
return errors.Wrap(err, "failed to reload metadata")
}
opts.EC.Logger.Info("Metadata reloaded")
return nil
},
}
return metadataReloadCmd
}
type metadataReloadOptions struct {
EC *cli.ExecutionContext
}
func (o *metadataReloadOptions) run() error {
var err error
metadataHandler := metadataobject.NewHandlerFromEC(ec)
err = metadataHandler.ReloadMetadata()
if err != nil {
return errors.Wrap(err, "Cannot reload metadata")
}
return nil
}