From 74331e35e2ca7402cee7d85d578f1c3e497d5cb0 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Tue, 31 Dec 2024 10:49:15 -0500 Subject: [PATCH 01/11] Partial work --- http/handler_acp.go | 2 +- http/handler_collection.go | 2 +- http/handler_p2p.go | 2 +- internal/db/p2p_replicator.go | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/http/handler_acp.go b/http/handler_acp.go index f9ef17cbee..5b57a0214a 100644 --- a/http/handler_acp.go +++ b/http/handler_acp.go @@ -166,5 +166,5 @@ func (h *acpHandler) bindRoutes(router *Router) { router.AddRoute("/acp/policy", http.MethodPost, acpAddPolicy, h.AddPolicy) router.AddRoute("/acp/relationship", http.MethodPost, acpAddDocActorRelationship, h.AddDocActorRelationship) - router.AddRoute("/acp/relationship", http.MethodDelete, acpDeleteDocActorRelationship, h.DeleteDocActorRelationship) + router.AddRoute("/acp/relationship/delete", http.MethodPost, acpDeleteDocActorRelationship, h.DeleteDocActorRelationship) } diff --git a/http/handler_collection.go b/http/handler_collection.go index 1757fc7d00..1649a6bc03 100644 --- a/http/handler_collection.go +++ b/http/handler_collection.go @@ -491,7 +491,7 @@ func (h *collectionHandler) bindRoutes(router *Router) { router.AddRoute("/collections/{name}", http.MethodGet, collectionKeys, h.GetAllDocIDs) router.AddRoute("/collections/{name}", http.MethodPost, collectionCreate, h.Create) router.AddRoute("/collections/{name}", http.MethodPatch, collectionUpdateWith, h.UpdateWithFilter) - router.AddRoute("/collections/{name}", http.MethodDelete, collectionDeleteWith, h.DeleteWithFilter) + router.AddRoute("/collections/{name}/deleteWithFilter", http.MethodPost, collectionDeleteWith, h.DeleteWithFilter) router.AddRoute("/collections/{name}/indexes", http.MethodPost, createIndex, h.CreateIndex) router.AddRoute("/collections/{name}/indexes", http.MethodGet, getIndexes, h.GetIndexes) router.AddRoute("/collections/{name}/indexes/{index}", http.MethodDelete, dropIndex, h.DropIndex) diff --git a/http/handler_p2p.go b/http/handler_p2p.go index 637b601e5c..33c6a9704b 100644 --- a/http/handler_p2p.go +++ b/http/handler_p2p.go @@ -248,7 +248,7 @@ func (h *p2pHandler) bindRoutes(router *Router) { router.AddRoute("/p2p/info", http.MethodGet, peerInfo, h.PeerInfo) router.AddRoute("/p2p/replicators", http.MethodGet, getReplicators, h.GetAllReplicators) router.AddRoute("/p2p/replicators", http.MethodPost, setReplicator, h.SetReplicator) - router.AddRoute("/p2p/replicators", http.MethodDelete, deleteReplicator, h.DeleteReplicator) + router.AddRoute("/p2p/replicators/delete", http.MethodPost, deleteReplicator, h.DeleteReplicator) router.AddRoute("/p2p/collections", http.MethodGet, getPeerCollections, h.GetAllP2PCollections) router.AddRoute("/p2p/collections", http.MethodPost, addPeerCollections, h.AddP2PCollection) router.AddRoute("/p2p/collections", http.MethodDelete, removePeerCollections, h.RemoveP2PCollection) diff --git a/internal/db/p2p_replicator.go b/internal/db/p2p_replicator.go index a6d28f261a..ae4adc5941 100644 --- a/internal/db/p2p_replicator.go +++ b/internal/db/p2p_replicator.go @@ -13,6 +13,7 @@ package db import ( "context" "encoding/json" + "fmt" "time" "github.com/fxamacker/cbor/v2" @@ -267,6 +268,7 @@ func (db *db) DeleteReplicator(ctx context.Context, rep client.ReplicatorParams) } for _, col := range collections { + fmt.Println("I will delete") delete(storedSchemas, col.SchemaRoot()) } // Update the list of schemas for this replicator prior to persisting. From e4c55ad367c12f1ff71df7b09d4b8940ee0b23ea Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Thu, 2 Jan 2025 10:52:51 -0500 Subject: [PATCH 02/11] First commit --- cli/schema_add.go | 48 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/cli/schema_add.go b/cli/schema_add.go index e81896322d..a1438fd4a5 100644 --- a/cli/schema_add.go +++ b/cli/schema_add.go @@ -19,7 +19,7 @@ import ( ) func MakeSchemaAddCommand() *cobra.Command { - var schemaFile string + var schemaFiles []string var cmd = &cobra.Command{ Use: "add [schema]", Short: "Add new schema", @@ -36,6 +36,9 @@ Example: add from an argument string: Example: add from file: defradb client schema add -f schema.graphql +Example: add from multiple files: + defradb client schema add -f schema1.graphql -f schema2.graphql + Example: add from stdin: cat schema.graphql | defradb client schema add - @@ -43,33 +46,48 @@ Learn more about the DefraDB GraphQL Schema Language on https://docs.source.netw RunE: func(cmd *cobra.Command, args []string) error { store := mustGetContextStore(cmd) - var schema string + var schemas []string switch { - case schemaFile != "": - data, err := os.ReadFile(schemaFile) - if err != nil { - return err + + case len(schemaFiles) > 0: + // Read schemas from files + for _, schemaFile := range schemaFiles { + data, err := os.ReadFile(schemaFile) + if err != nil { + return fmt.Errorf("failed to read file %s: %w", schemaFile, err) + } + schemas = append(schemas, string(data)) } - schema = string(data) + case len(args) > 0 && args[0] == "-": + // Read schema from stdin data, err := io.ReadAll(cmd.InOrStdin()) if err != nil { - return err + return fmt.Errorf("failed to read schema from stdin: %w", err) } - schema = string(data) + schemas = append(schemas, string(data)) + case len(args) > 0: - schema = args[0] + // Read schema from argument string + schemas = append(schemas, args[0]) + default: return fmt.Errorf("schema cannot be empty") } - cols, err := store.AddSchema(cmd.Context(), schema) - if err != nil { - return err + for _, schema := range schemas { + cols, err := store.AddSchema(cmd.Context(), schema) + if err != nil { + return fmt.Errorf("failed to add schema: %w", err) + } + if err := writeJSON(cmd, cols); err != nil { + return err + } } - return writeJSON(cmd, cols) + + return nil }, } - cmd.Flags().StringVarP(&schemaFile, "file", "f", "", "File to load a schema from") + cmd.Flags().StringSliceVarP(&schemaFiles, "file", "f", []string{}, "File(s) to load schema from") return cmd } From 746e13e492614bfa98a664f29d4b07d5438343f4 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Thu, 2 Jan 2025 11:02:45 -0500 Subject: [PATCH 03/11] Rolled back changes to some files made accidentally --- http/handler_acp.go | 2 +- http/handler_collection.go | 2 +- http/handler_p2p.go | 2 +- internal/db/p2p_replicator.go | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/http/handler_acp.go b/http/handler_acp.go index 5b57a0214a..f9ef17cbee 100644 --- a/http/handler_acp.go +++ b/http/handler_acp.go @@ -166,5 +166,5 @@ func (h *acpHandler) bindRoutes(router *Router) { router.AddRoute("/acp/policy", http.MethodPost, acpAddPolicy, h.AddPolicy) router.AddRoute("/acp/relationship", http.MethodPost, acpAddDocActorRelationship, h.AddDocActorRelationship) - router.AddRoute("/acp/relationship/delete", http.MethodPost, acpDeleteDocActorRelationship, h.DeleteDocActorRelationship) + router.AddRoute("/acp/relationship", http.MethodDelete, acpDeleteDocActorRelationship, h.DeleteDocActorRelationship) } diff --git a/http/handler_collection.go b/http/handler_collection.go index 1649a6bc03..1757fc7d00 100644 --- a/http/handler_collection.go +++ b/http/handler_collection.go @@ -491,7 +491,7 @@ func (h *collectionHandler) bindRoutes(router *Router) { router.AddRoute("/collections/{name}", http.MethodGet, collectionKeys, h.GetAllDocIDs) router.AddRoute("/collections/{name}", http.MethodPost, collectionCreate, h.Create) router.AddRoute("/collections/{name}", http.MethodPatch, collectionUpdateWith, h.UpdateWithFilter) - router.AddRoute("/collections/{name}/deleteWithFilter", http.MethodPost, collectionDeleteWith, h.DeleteWithFilter) + router.AddRoute("/collections/{name}", http.MethodDelete, collectionDeleteWith, h.DeleteWithFilter) router.AddRoute("/collections/{name}/indexes", http.MethodPost, createIndex, h.CreateIndex) router.AddRoute("/collections/{name}/indexes", http.MethodGet, getIndexes, h.GetIndexes) router.AddRoute("/collections/{name}/indexes/{index}", http.MethodDelete, dropIndex, h.DropIndex) diff --git a/http/handler_p2p.go b/http/handler_p2p.go index 33c6a9704b..637b601e5c 100644 --- a/http/handler_p2p.go +++ b/http/handler_p2p.go @@ -248,7 +248,7 @@ func (h *p2pHandler) bindRoutes(router *Router) { router.AddRoute("/p2p/info", http.MethodGet, peerInfo, h.PeerInfo) router.AddRoute("/p2p/replicators", http.MethodGet, getReplicators, h.GetAllReplicators) router.AddRoute("/p2p/replicators", http.MethodPost, setReplicator, h.SetReplicator) - router.AddRoute("/p2p/replicators/delete", http.MethodPost, deleteReplicator, h.DeleteReplicator) + router.AddRoute("/p2p/replicators", http.MethodDelete, deleteReplicator, h.DeleteReplicator) router.AddRoute("/p2p/collections", http.MethodGet, getPeerCollections, h.GetAllP2PCollections) router.AddRoute("/p2p/collections", http.MethodPost, addPeerCollections, h.AddP2PCollection) router.AddRoute("/p2p/collections", http.MethodDelete, removePeerCollections, h.RemoveP2PCollection) diff --git a/internal/db/p2p_replicator.go b/internal/db/p2p_replicator.go index ae4adc5941..a6d28f261a 100644 --- a/internal/db/p2p_replicator.go +++ b/internal/db/p2p_replicator.go @@ -13,7 +13,6 @@ package db import ( "context" "encoding/json" - "fmt" "time" "github.com/fxamacker/cbor/v2" @@ -268,7 +267,6 @@ func (db *db) DeleteReplicator(ctx context.Context, rep client.ReplicatorParams) } for _, col := range collections { - fmt.Println("I will delete") delete(storedSchemas, col.SchemaRoot()) } // Update the list of schemas for this replicator prior to persisting. From e006561ec0a346eb70647c49c6915c3c379dfb17 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Thu, 2 Jan 2025 13:23:33 -0500 Subject: [PATCH 04/11] Delint --- cli/schema_add.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/schema_add.go b/cli/schema_add.go index a1438fd4a5..2874301358 100644 --- a/cli/schema_add.go +++ b/cli/schema_add.go @@ -48,7 +48,6 @@ Learn more about the DefraDB GraphQL Schema Language on https://docs.source.netw var schemas []string switch { - case len(schemaFiles) > 0: // Read schemas from files for _, schemaFile := range schemaFiles { From 9cb6ecd9370c15e779c790b09b537dc17044fd28 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Fri, 3 Jan 2025 11:46:24 -0500 Subject: [PATCH 05/11] Redo MakeSchemaAddCommand --- acp/acp_local.go | 2 +- cli/config.go | 2 +- cli/schema_add.go | 25 ++++++++++++------------- crypto/nonce.go | 3 ++- internal/db/collection_index.go | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/acp/acp_local.go b/acp/acp_local.go index 99b2cb15f4..436a35f99d 100644 --- a/acp/acp_local.go +++ b/acp/acp_local.go @@ -12,13 +12,13 @@ package acp import ( "context" - "errors" protoTypes "github.com/cosmos/gogoproto/types" "github.com/sourcenetwork/acp_core/pkg/auth" "github.com/sourcenetwork/acp_core/pkg/engine" "github.com/sourcenetwork/acp_core/pkg/runtime" "github.com/sourcenetwork/acp_core/pkg/types" + "github.com/sourcenetwork/defradb/errors" "github.com/sourcenetwork/immutable" "github.com/sourcenetwork/defradb/acp/identity" diff --git a/cli/config.go b/cli/config.go index f17b3e5ead..a85dd77a27 100644 --- a/cli/config.go +++ b/cli/config.go @@ -11,13 +11,13 @@ package cli import ( - "errors" "os" "path/filepath" "strings" "github.com/joho/godotenv" "github.com/sourcenetwork/corelog" + "github.com/sourcenetwork/defradb/errors" "github.com/spf13/pflag" "github.com/spf13/viper" ) diff --git a/cli/schema_add.go b/cli/schema_add.go index 2874301358..5cdbc6be07 100644 --- a/cli/schema_add.go +++ b/cli/schema_add.go @@ -46,16 +46,16 @@ Learn more about the DefraDB GraphQL Schema Language on https://docs.source.netw RunE: func(cmd *cobra.Command, args []string) error { store := mustGetContextStore(cmd) - var schemas []string + var combinedSchema string switch { case len(schemaFiles) > 0: - // Read schemas from files + // Read schemas from files and concatenate them for _, schemaFile := range schemaFiles { data, err := os.ReadFile(schemaFile) if err != nil { return fmt.Errorf("failed to read file %s: %w", schemaFile, err) } - schemas = append(schemas, string(data)) + combinedSchema += string(data) + "\n" } case len(args) > 0 && args[0] == "-": @@ -64,24 +64,23 @@ Learn more about the DefraDB GraphQL Schema Language on https://docs.source.netw if err != nil { return fmt.Errorf("failed to read schema from stdin: %w", err) } - schemas = append(schemas, string(data)) + combinedSchema += string(data) + "\n" case len(args) > 0: // Read schema from argument string - schemas = append(schemas, args[0]) + combinedSchema += args[0] + "\n" default: return fmt.Errorf("schema cannot be empty") } - for _, schema := range schemas { - cols, err := store.AddSchema(cmd.Context(), schema) - if err != nil { - return fmt.Errorf("failed to add schema: %w", err) - } - if err := writeJSON(cmd, cols); err != nil { - return err - } + // Process the combined schema + cols, err := store.AddSchema(cmd.Context(), combinedSchema) + if err != nil { + return fmt.Errorf("failed to add schema: %w", err) + } + if err := writeJSON(cmd, cols); err != nil { + return err } return nil diff --git a/crypto/nonce.go b/crypto/nonce.go index 9c8f00b31f..bae5dcc58a 100644 --- a/crypto/nonce.go +++ b/crypto/nonce.go @@ -12,10 +12,11 @@ package crypto import ( "crypto/rand" - "errors" "io" "os" "strings" + + "github.com/sourcenetwork/defradb/errors" ) const AESNonceSize = 12 diff --git a/internal/db/collection_index.go b/internal/db/collection_index.go index 3559b02b38..edfe201e41 100644 --- a/internal/db/collection_index.go +++ b/internal/db/collection_index.go @@ -13,7 +13,6 @@ package db import ( "context" "encoding/json" - "errors" "fmt" "strconv" "strings" @@ -24,6 +23,7 @@ import ( "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/datastore" + "github.com/sourcenetwork/defradb/errors" "github.com/sourcenetwork/defradb/internal/db/base" "github.com/sourcenetwork/defradb/internal/db/description" "github.com/sourcenetwork/defradb/internal/db/fetcher" From 58e71f5c1dda0486b7a9eb953c608dd4f09ecfc1 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Mon, 6 Jan 2025 10:39:44 -0500 Subject: [PATCH 06/11] Delint --- acp/acp_local.go | 3 ++- cli/config.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/acp/acp_local.go b/acp/acp_local.go index 436a35f99d..682f57b485 100644 --- a/acp/acp_local.go +++ b/acp/acp_local.go @@ -18,9 +18,10 @@ import ( "github.com/sourcenetwork/acp_core/pkg/engine" "github.com/sourcenetwork/acp_core/pkg/runtime" "github.com/sourcenetwork/acp_core/pkg/types" - "github.com/sourcenetwork/defradb/errors" "github.com/sourcenetwork/immutable" + "github.com/sourcenetwork/defradb/errors" + "github.com/sourcenetwork/defradb/acp/identity" ) diff --git a/cli/config.go b/cli/config.go index a85dd77a27..70975e229f 100644 --- a/cli/config.go +++ b/cli/config.go @@ -17,9 +17,10 @@ import ( "github.com/joho/godotenv" "github.com/sourcenetwork/corelog" - "github.com/sourcenetwork/defradb/errors" "github.com/spf13/pflag" "github.com/spf13/viper" + + "github.com/sourcenetwork/defradb/errors" ) const ( From 15b8d2214934c4a79fde0dff9921e2e816073271 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Mon, 6 Jan 2025 10:41:03 -0500 Subject: [PATCH 07/11] Make docs --- docs/website/references/cli/defradb_client_schema_add.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/website/references/cli/defradb_client_schema_add.md b/docs/website/references/cli/defradb_client_schema_add.md index ecff04212c..42a2474222 100644 --- a/docs/website/references/cli/defradb_client_schema_add.md +++ b/docs/website/references/cli/defradb_client_schema_add.md @@ -17,6 +17,9 @@ Example: add from an argument string: Example: add from file: defradb client schema add -f schema.graphql +Example: add from multiple files: + defradb client schema add -f schema1.graphql -f schema2.graphql + Example: add from stdin: cat schema.graphql | defradb client schema add - @@ -29,8 +32,8 @@ defradb client schema add [schema] [flags] ### Options ``` - -f, --file string File to load a schema from - -h, --help help for add + -f, --file strings File(s) to load schema from + -h, --help help for add ``` ### Options inherited from parent commands From 80a507bfec0509702f309eb931af56298cf26964 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Tue, 14 Jan 2025 10:55:32 -0500 Subject: [PATCH 08/11] Revert error import lines --- acp/acp_local.go | 3 +-- cli/config.go | 3 +-- crypto/nonce.go | 3 +-- internal/db/collection_index.go | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/acp/acp_local.go b/acp/acp_local.go index 682f57b485..99b2cb15f4 100644 --- a/acp/acp_local.go +++ b/acp/acp_local.go @@ -12,6 +12,7 @@ package acp import ( "context" + "errors" protoTypes "github.com/cosmos/gogoproto/types" "github.com/sourcenetwork/acp_core/pkg/auth" @@ -20,8 +21,6 @@ import ( "github.com/sourcenetwork/acp_core/pkg/types" "github.com/sourcenetwork/immutable" - "github.com/sourcenetwork/defradb/errors" - "github.com/sourcenetwork/defradb/acp/identity" ) diff --git a/cli/config.go b/cli/config.go index 70975e229f..f17b3e5ead 100644 --- a/cli/config.go +++ b/cli/config.go @@ -11,6 +11,7 @@ package cli import ( + "errors" "os" "path/filepath" "strings" @@ -19,8 +20,6 @@ import ( "github.com/sourcenetwork/corelog" "github.com/spf13/pflag" "github.com/spf13/viper" - - "github.com/sourcenetwork/defradb/errors" ) const ( diff --git a/crypto/nonce.go b/crypto/nonce.go index bae5dcc58a..9c8f00b31f 100644 --- a/crypto/nonce.go +++ b/crypto/nonce.go @@ -12,11 +12,10 @@ package crypto import ( "crypto/rand" + "errors" "io" "os" "strings" - - "github.com/sourcenetwork/defradb/errors" ) const AESNonceSize = 12 diff --git a/internal/db/collection_index.go b/internal/db/collection_index.go index edfe201e41..3559b02b38 100644 --- a/internal/db/collection_index.go +++ b/internal/db/collection_index.go @@ -13,6 +13,7 @@ package db import ( "context" "encoding/json" + "errors" "fmt" "strconv" "strings" @@ -23,7 +24,6 @@ import ( "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/datastore" - "github.com/sourcenetwork/defradb/errors" "github.com/sourcenetwork/defradb/internal/db/base" "github.com/sourcenetwork/defradb/internal/db/description" "github.com/sourcenetwork/defradb/internal/db/fetcher" From a1740f415d8922567b0ef74b22a9f4913a1120f1 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Thu, 16 Jan 2025 10:17:25 -0500 Subject: [PATCH 09/11] Change hardcoded errors to error types --- cli/errors.go | 14 ++++++++++++++ cli/schema_add.go | 9 ++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cli/errors.go b/cli/errors.go index ff283de5f9..439b89b20d 100644 --- a/cli/errors.go +++ b/cli/errors.go @@ -22,6 +22,7 @@ const ( errRequiredFlag string = "the required flag [--%s|-%s] is %s" errInvalidAscensionOrder string = "invalid order: expected ASC or DESC" errInvalidInxedFieldDescription string = "invalid or malformed field description" + errEmptySchemaString string = "schema cannot be empty" ) var ( @@ -36,6 +37,7 @@ var ( ErrPolicyFileArgCanNotBeEmpty = errors.New("policy file argument can not be empty") ErrPurgeForceFlagRequired = errors.New("run this command again with --force if you really want to purge all data") ErrMissingKeyringSecret = errors.New("missing keyring secret") + ErrEmptySchemaString = errors.New(errEmptySchemaString) ) func NewErrRequiredFlagEmpty(longName string, shortName string) error { @@ -65,3 +67,15 @@ func NewErrInvalidAscensionOrder(fieldName string) error { func NewErrInvalidInxedFieldDescription(fieldName string) error { return errors.New(errInvalidInxedFieldDescription, errors.NewKV("Field", fieldName)) } + +func NewErrFailedToReadSchemaFile(schemaFile string, inner error) error { + return errors.Wrap(fmt.Sprintf("failed to read file %s", schemaFile), inner) +} + +func NewErrFailedToReadSchemaFromStdin(inner error) error { + return errors.Wrap("failed to read schema from stdin", inner) +} + +func NewErrFailedToAddSchema(inner error) error { + return errors.Wrap("failed to add schema", inner) +} diff --git a/cli/schema_add.go b/cli/schema_add.go index 5cdbc6be07..5b6fdfc0b2 100644 --- a/cli/schema_add.go +++ b/cli/schema_add.go @@ -11,7 +11,6 @@ package cli import ( - "fmt" "io" "os" @@ -53,7 +52,7 @@ Learn more about the DefraDB GraphQL Schema Language on https://docs.source.netw for _, schemaFile := range schemaFiles { data, err := os.ReadFile(schemaFile) if err != nil { - return fmt.Errorf("failed to read file %s: %w", schemaFile, err) + return NewErrFailedToReadSchemaFile(schemaFile, err) } combinedSchema += string(data) + "\n" } @@ -62,7 +61,7 @@ Learn more about the DefraDB GraphQL Schema Language on https://docs.source.netw // Read schema from stdin data, err := io.ReadAll(cmd.InOrStdin()) if err != nil { - return fmt.Errorf("failed to read schema from stdin: %w", err) + return NewErrFailedToReadSchemaFromStdin(err) } combinedSchema += string(data) + "\n" @@ -71,13 +70,13 @@ Learn more about the DefraDB GraphQL Schema Language on https://docs.source.netw combinedSchema += args[0] + "\n" default: - return fmt.Errorf("schema cannot be empty") + return ErrEmptySchemaString } // Process the combined schema cols, err := store.AddSchema(cmd.Context(), combinedSchema) if err != nil { - return fmt.Errorf("failed to add schema: %w", err) + return NewErrFailedToAddSchema(err) } if err := writeJSON(cmd, cols); err != nil { return err From 88159c48de29b4615937e03b16fcad41dcd94641 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Thu, 16 Jan 2025 10:48:07 -0500 Subject: [PATCH 10/11] Changed docs --- cli/schema_add.go | 2 +- docs/website/references/cli/defradb_client_schema_add.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/schema_add.go b/cli/schema_add.go index 5b6fdfc0b2..9bdb056c44 100644 --- a/cli/schema_add.go +++ b/cli/schema_add.go @@ -85,6 +85,6 @@ Learn more about the DefraDB GraphQL Schema Language on https://docs.source.netw return nil }, } - cmd.Flags().StringSliceVarP(&schemaFiles, "file", "f", []string{}, "File(s) to load schema from") + cmd.Flags().StringSliceVarP(&schemaFiles, "file", "f", []string{}, "File to load schema from") return cmd } diff --git a/docs/website/references/cli/defradb_client_schema_add.md b/docs/website/references/cli/defradb_client_schema_add.md index 42a2474222..41ef9b3add 100644 --- a/docs/website/references/cli/defradb_client_schema_add.md +++ b/docs/website/references/cli/defradb_client_schema_add.md @@ -32,7 +32,7 @@ defradb client schema add [schema] [flags] ### Options ``` - -f, --file strings File(s) to load schema from + -f, --file strings File to load schema from -h, --help help for add ``` From 943173ac1ca907c9b650e6069ea85b9301eed9f6 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Fri, 17 Jan 2025 11:03:36 -0500 Subject: [PATCH 11/11] Doc update --- cli/schema_add.go | 3 +++ docs/website/references/cli/defradb_client_schema_add.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cli/schema_add.go b/cli/schema_add.go index 9bdb056c44..f6c819c96b 100644 --- a/cli/schema_add.go +++ b/cli/schema_add.go @@ -38,6 +38,9 @@ Example: add from file: Example: add from multiple files: defradb client schema add -f schema1.graphql -f schema2.graphql +Example: add from multiple files: + defradb client schema add -f schema1.graphql,schema2.graphql + Example: add from stdin: cat schema.graphql | defradb client schema add - diff --git a/docs/website/references/cli/defradb_client_schema_add.md b/docs/website/references/cli/defradb_client_schema_add.md index 41ef9b3add..9f7a2579a8 100644 --- a/docs/website/references/cli/defradb_client_schema_add.md +++ b/docs/website/references/cli/defradb_client_schema_add.md @@ -20,6 +20,9 @@ Example: add from file: Example: add from multiple files: defradb client schema add -f schema1.graphql -f schema2.graphql +Example: add from multiple files: + defradb client schema add -f schema1.graphql,schema2.graphql + Example: add from stdin: cat schema.graphql | defradb client schema add -