Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Change terminology from query to request #1054

Merged
merged 27 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
03fbddb
PR: Rename the query folder to request.
shahzadlone Jan 24, 2023
2a11c3e
PR: Split the mixed query & request parsing logic.
shahzadlone Jan 24, 2023
99af856
PR: Change `ParseQuery` to `ParseRequest`.
shahzadlone Jan 24, 2023
ba82859
PR: Fix error handling & comment for ParseRequest.
shahzadlone Jan 24, 2023
974db30
PR: Rename `planner/query.go` & `planner.Query`.
shahzadlone Jan 24, 2023
11d45be
PR: Fix terminology in planner, with some errors.
shahzadlone Jan 24, 2023
f7c4ffe
PR: Fix a log I missed in schema package.
shahzadlone Jan 24, 2023
5e6fc2c
PR: Rename `db/query.go` file to `db/request.go`.
shahzadlone Jan 24, 2023
925bbbc
PR: Rename `ExecQuery` & `ExecTransactionalQuery`.
shahzadlone Jan 24, 2023
ff9fd93
PR: Rename local vars in `db/request.go`.
shahzadlone Jan 24, 2023
30f9f86
PR: Rename `client.QueryResult`.
shahzadlone Jan 24, 2023
6f57abe
PR: Update terminology under the `db` package.
shahzadlone Jan 24, 2023
2bcd2ba
PR: Fix terminology within the `api` package.
shahzadlone Jan 24, 2023
a07810c
PR: Fix terminology in `client` package.
shahzadlone Jan 24, 2023
ac2f84c
PR: Rename `cli/query.go` to `cli/request.go`.
shahzadlone Jan 24, 2023
5dc0b85
PR: Fix terminology in the `cli` package.
shahzadlone Jan 24, 2023
bc4dcb2
PR: Test - Fix terminology for subsciption tests.
shahzadlone Jan 24, 2023
a14585e
PR: Test - Fix terminology for transactional tests
shahzadlone Jan 24, 2023
132ed10
PR: Test - Rename `QueryTestCase`.
shahzadlone Jan 24, 2023
9b530f2
PR: Test - Fix 2 members of `RequestTestCase`.
shahzadlone Jan 24, 2023
f150b7a
PR: Test - Rename `Query` to `Request`.
shahzadlone Jan 24, 2023
b59bdaf
PR: Rename `ExecuteQueryTestCase`.
shahzadlone Jan 24, 2023
e5c70aa
PR: More changes of `QueryTestCase` to `Request..`.
shahzadlone Jan 24, 2023
f4af6b7
PR: Make linter happy `make lint:fix`
shahzadlone Jan 24, 2023
5cbe3b1
PR: Some terminology stuff that was missed.
shahzadlone Jan 24, 2023
e55a45b
PR: Adhere to PR suggestion about typo.
shahzadlone Jan 24, 2023
5856242
PR: Adhere to code review todo `makeSelectionPlan`
shahzadlone Jan 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/http/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
ErrDatabaseNotAvailable = errors.New("no database available")
ErrFormNotSupported = errors.New("content type application/x-www-form-urlencoded not yet supported")
ErrBodyEmpty = errors.New("body cannot be empty")
ErrMissingGQLQuery = errors.New("missing GraphQL query")
ErrMissingGQLRequest = errors.New("missing GraphQL request")
ErrPeerIdUnavailable = errors.New("no peer ID available. P2P might be disabled")
ErrStreamingUnsupported = errors.New("streaming unsupported")
ErrNoEmail = errors.New("email address must be specified for tls with autocert")
Expand Down
18 changes: 9 additions & 9 deletions api/http/handlerfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ func dumpHandler(rw http.ResponseWriter, req *http.Request) {
}

type gqlRequest struct {
Query string `json:"query"`
Request string `json:"query"`
}

func execGQLHandler(rw http.ResponseWriter, req *http.Request) {
query := req.URL.Query().Get("query")
if query == "" {
request := req.URL.Query().Get("query")
if request == "" {
// extract the media type from the content-type header
contentType, _, err := mime.ParseMediaType(req.Header.Get("Content-Type"))
// mime.ParseMediaType will return an error (mime: no media type)
Expand All @@ -105,7 +105,7 @@ func execGQLHandler(rw http.ResponseWriter, req *http.Request) {
return
}

query = gqlReq.Query
request = gqlReq.Request

case contentTypeFormURLEncoded:
handleErr(
Expand All @@ -129,13 +129,13 @@ func execGQLHandler(rw http.ResponseWriter, req *http.Request) {
handleErr(req.Context(), rw, errors.WithStack(err), http.StatusBadRequest)
return
}
query = string(body)
request = string(body)
}
}

// if at this point query is still empty, return an error
if query == "" {
handleErr(req.Context(), rw, ErrMissingGQLQuery, http.StatusBadRequest)
// if at this point request is still empty, return an error
if request == "" {
handleErr(req.Context(), rw, ErrMissingGQLRequest, http.StatusBadRequest)
return
}

Expand All @@ -144,7 +144,7 @@ func execGQLHandler(rw http.ResponseWriter, req *http.Request) {
handleErr(req.Context(), rw, err, http.StatusInternalServerError)
return
}
result := db.ExecQuery(req.Context(), query)
result := db.ExecRequest(req.Context(), request)

if result.Pub != nil {
subscriptionHandler(result.Pub, rw, req)
Expand Down
4 changes: 2 additions & 2 deletions api/http/handlerfuncs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ func TestExecGQLWithEmptyBody(t *testing.T) {
ResponseData: &errResponse,
})

assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "missing GraphQL query")
assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "missing GraphQL request")
assert.Equal(t, http.StatusBadRequest, errResponse.Errors[0].Extensions.Status)
assert.Equal(t, "Bad Request", errResponse.Errors[0].Extensions.HTTPError)
assert.Equal(t, "missing GraphQL query", errResponse.Errors[0].Message)
assert.Equal(t, "missing GraphQL request", errResponse.Errors[0].Message)
}

type mockReadCloser struct {
Expand Down
30 changes: 15 additions & 15 deletions cli/query.go → cli/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ import (
"github.com/sourcenetwork/defradb/errors"
)

var queryCmd = &cobra.Command{
Use: "query [query]",
Short: "Send a DefraDB GraphQL query",
Long: `Send a DefraDB GraphQL query to the database.
var requestCmd = &cobra.Command{
Use: "query [query request]",
Short: "Send a DefraDB GraphQL query request",
Long: `Send a DefraDB GraphQL query request to the database.

A query can be sent as a single argument. Example command:
A query request can be sent as a single argument. Example command:
defradb client query 'query { ... }'

Or it can be sent via stdin by using the '-' special syntax. Example command:
cat query.graphql | defradb client query -
cat request.graphql | defradb client query -

A GraphQL client such as GraphiQL (https://github.com/graphql/graphiql) can be used to interact
with the database more conveniently.

To learn more about the DefraDB GraphQL Query Language, refer to https://docs.source.network.`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
var query string
var request string

fi, err := os.Stdin.Stat()
if err != nil {
Expand Down Expand Up @@ -71,16 +71,16 @@ To learn more about the DefraDB GraphQL Query Language, refer to https://docs.so
return errors.Wrap("failed to read stdin", err)
}
if len(stdin) == 0 {
return errors.New("no query in stdin provided")
return errors.New("no query request in stdin provided")
} else {
query = stdin
request = stdin
}
} else {
query = args[0]
request = args[0]
}

if query == "" {
return errors.New("query cannot be empty")
if request == "" {
return errors.New("request cannot be empty")
}

endpoint, err := httpapi.JoinPaths(cfg.API.AddressToURL(), httpapi.GraphQLPath)
Expand All @@ -89,12 +89,12 @@ To learn more about the DefraDB GraphQL Query Language, refer to https://docs.so
}

p := url.Values{}
p.Add("query", query)
p.Add("query", request)
endpoint.RawQuery = p.Encode()

res, err := http.Get(endpoint.String())
if err != nil {
return errors.Wrap("failed query", err)
return errors.Wrap("failed request", err)
}

defer func() {
Expand Down Expand Up @@ -135,5 +135,5 @@ To learn more about the DefraDB GraphQL Query Language, refer to https://docs.so
}

func init() {
clientCmd.AddCommand(queryCmd)
clientCmd.AddCommand(requestCmd)
}
2 changes: 1 addition & 1 deletion cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var rootCmd = &cobra.Command{
Short: "DefraDB Edge Database",
Long: `DefraDB is the edge database to power the user-centric future.

Start a database node, query a local or remote node, and much more.
Start a database node, issue a request to a local or remote node, and much more.

DefraDB is released under the BSL license, (c) 2022 Democratized Data Foundation.
See https://docs.source.network/BSL.txt for more information.
Expand Down
2 changes: 1 addition & 1 deletion cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func start(ctx context.Context) (*defraInstance, error) {
log.FeedbackInfo(
ctx,
fmt.Sprintf(
"Providing HTTP API at %s%s. Use the GraphQL query endpoint at %s%s/graphql ",
"Providing HTTP API at %s%s. Use the GraphQL request endpoint at %s%s/graphql ",
cfg.API.AddressToURL(),
httpapi.RootPath,
cfg.API.AddressToURL(),
Expand Down
6 changes: 3 additions & 3 deletions client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type DB interface {
Blockstore() blockstore.Blockstore

NewTxn(context.Context, bool) (datastore.Txn, error)
ExecQuery(context.Context, string) *QueryResult
ExecTransactionalQuery(ctx context.Context, query string, txn datastore.Txn) *QueryResult
ExecRequest(context.Context, string) *RequestResult
ExecTransactionalRequest(context.Context, string, datastore.Txn) *RequestResult
Close(context.Context)

Events() events.Events
Expand All @@ -57,7 +57,7 @@ type GQLResult struct {
Data any `json:"data"`
}

type QueryResult struct {
type RequestResult struct {
GQL GQLResult
Pub *events.Publisher[events.Update]
}
3 changes: 2 additions & 1 deletion client/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ type IndexDescription struct {
// A Book type can have many Categories,
// and Categories can belong to many Books.
//
// If we query more for Books, then Categories directly, then
// If we request Books more, then Categories directly, then
// we can set the Book type as the Primary type.
Junction bool

// RelationType is only used in the Index is a Junction Index.
// It specifies what the other type is in the Many-to-Many
// relationship.
Expand Down
2 changes: 1 addition & 1 deletion client/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// Documents in this case refer to the core database type of DefraDB which is a
// "NoSQL Document Datastore".
//
// This section is not concerned with the outer query layer used to interact with the
// This section is not concerned with the outer request layer used to interact with the
// Document API, but instead is solely concerned with carrying out the internal API
// operations.
//
Expand Down
8 changes: 4 additions & 4 deletions client/request/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const (

ExplainLabel = "explain"

LatestCommitsQueryName = "latestCommits"
CommitsQueryName = "commits"
LatestCommitsName = "latestCommits"
CommitsName = "commits"

CommitTypeName = "Commit"
LinksFieldName = "links"
Expand Down Expand Up @@ -78,8 +78,8 @@ var (
}

CommitQueries = map[string]struct{}{
LatestCommitsQueryName: {},
CommitsQueryName: {},
LatestCommitsName: {},
CommitsName: {},
}

VersionFields = []string{
Expand Down
2 changes: 1 addition & 1 deletion client/request/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
// licenses/APL.txt.

/*
Package request defines the GraphQL types used by the query service.
Package request defines the GraphQL types used by the request issuing service.
*/
package request
12 changes: 4 additions & 8 deletions client/request/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ const (
DeleteObjects
)

// Mutation is a field on the MutationType
// of a graphql query. It includes all the possible
// arguments and all
//
// @todo: Change name to ObjectMutation to indicate
// generated object mutation actions
type Mutation struct {
// ObjectMutation is a field on the `mutation` operation of a graphql request. It includes
// all the possible arguments.
type ObjectMutation struct {
Field
Type MutationType

Expand All @@ -44,7 +40,7 @@ type Mutation struct {

// ToSelect returns a basic Select object, with the same Name, Alias, and Fields as
// the Mutation object. Used to create a Select planNode for the mutation return objects.
func (m Mutation) ToSelect() *Select {
func (m ObjectMutation) ToSelect() *Select {
return &Select{
Field: Field{
Name: m.Collection,
Expand Down
6 changes: 3 additions & 3 deletions client/request/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ const (
)

// Select is a complex Field with strong typing.
// It is used for sub-types in a query.
// Includes fields, and query arguments like filters, limits, etc.
// It is used for sub-types in a request.
// Includes fields, and request arguments like filters, limits, etc.
type Select struct {
Field

DocKeys immutable.Option[[]string]
CID immutable.Option[string]

// Root is the top level query parsed type
// Root is the top level type of parsed request
Root SelectionType

Limit immutable.Option[uint64]
Expand Down
2 changes: 1 addition & 1 deletion client/request/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// ObjectSubscription is a field on the SubscriptionType
// of a graphql query. It includes all the possible
// of a graphql request. It includes all the possible
// arguments
type ObjectSubscription struct {
Field
Expand Down
2 changes: 1 addition & 1 deletion core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Parser interface {
IsIntrospection(request string) bool

// Executes the given introspection request.
ExecuteIntrospection(request string) *client.QueryResult
ExecuteIntrospection(request string) *client.RequestResult

// Parses the given request, returning a strongly typed model of that request.
Parse(request string) (*request.Request, []error)
Expand Down
2 changes: 1 addition & 1 deletion db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (c *collection) Update(ctx context.Context, doc *client.Document) error {
}

// Contract: DB Exists check is already performed, and a doc with the given key exists.
// Note: Should we CompareAndSet the update, IE: Query the state, and update if changed
// Note: Should we CompareAndSet the update, IE: Query(read-only) the state, and update if changed
// or, just update everything regardless.
// Should probably be smart about the update due to the MerkleCRDT overhead, shouldn't
// add to the bloat.
Expand Down
18 changes: 9 additions & 9 deletions db/collection_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,29 +183,29 @@ func (c *collection) deleteWithFilter(
txn datastore.Txn,
filter any,
) (*client.DeleteResult, error) {
// Do a selection query to scan through documents using the given filter.
query, err := c.makeSelectionQuery(ctx, txn, filter)
// Make a selection request plan that will scan through only the documents with matching filter.
selectionRequestPlan, err := c.makeSelectionRequestPlan(ctx, txn, filter)
shahzadlone marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
if err := query.Start(); err != nil {
if err := selectionRequestPlan.Start(); err != nil {
return nil, err
}

// If the query object isn't properly closed at any exit point log the error.
// If the request plan isn't properly closed at any exit point log the error.
defer func() {
if err := query.Close(); err != nil {
log.ErrorE(ctx, "Failed to close query after filter delete", err)
if err := selectionRequestPlan.Close(); err != nil {
log.ErrorE(ctx, "Failed to close the request plan, after filter delete", err)
}
}()

results := &client.DeleteResult{
DocKeys: make([]string, 0),
}

// Keep looping until results from the filter query have been iterated through.
// Keep looping until results from the filter request have been iterated through.
for {
next, err := query.Next()
next, err := selectionRequestPlan.Next()
if err != nil {
return nil, err
}
Expand All @@ -215,7 +215,7 @@ func (c *collection) deleteWithFilter(
break
}

doc := query.Value()
doc := selectionRequestPlan.Value()
// Extract the dockey in the string format from the document value.
docKey := doc.GetKey()

Expand Down
Loading