Skip to content

Commit

Permalink
Redo MakeSchemaAddCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBQu committed Jan 3, 2025
1 parent e006561 commit 9cb6ecd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion acp/acp_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
25 changes: 12 additions & 13 deletions cli/schema_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check warning on line 58 in cli/schema_add.go

View check run for this annotation

Codecov / codecov/patch

cli/schema_add.go#L51-L58

Added lines #L51 - L58 were not covered by tests
}

case len(args) > 0 && args[0] == "-":
Expand All @@ -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)

Check warning on line 65 in cli/schema_add.go

View check run for this annotation

Codecov / codecov/patch

cli/schema_add.go#L65

Added line #L65 was not covered by tests
}
schemas = append(schemas, string(data))
combinedSchema += string(data) + "\n"

Check warning on line 67 in cli/schema_add.go

View check run for this annotation

Codecov / codecov/patch

cli/schema_add.go#L67

Added line #L67 was not covered by tests

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
Expand Down
3 changes: 2 additions & 1 deletion crypto/nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ package crypto

import (
"crypto/rand"
"errors"
"io"
"os"
"strings"

"github.com/sourcenetwork/defradb/errors"
)

const AESNonceSize = 12
Expand Down
2 changes: 1 addition & 1 deletion internal/db/collection_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package db
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
Expand All @@ -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"
Expand Down

0 comments on commit 9cb6ecd

Please sign in to comment.