-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Cleanup parsing logic (#909)
* Remove unused QueryType prop * Remove unused order.statement prop * Replace optionalDocKeys with client.Option Type was added before we had client.Option * Remove legacy commit entry Should have been removed in the PR that removed the commit query * Remove unused statement property * Remove unused func from interface * Remove Root from Field * Remove unused func * Parse aggregates in parser package * Remove statement from parser.Select * Remove ast from OperationDefinition * Remove unused Name from OperationDefinition * Make parser.Alias optional The parser models will shortly be exposed as part of the public interface, and it should not be on the users to have to always populate this property. It also makes more sense IMO to do it this way regardless, as alias is optional, but render-keys are not. * Make commit.DocKey option type Makes it far clearer that it is optional * Use option for parser.limit Also flattens them, as the previous structure suggested if one was present then the other was mandatory. Also switches from int64 to uint64 as they should not be negative (and makes it more consitent with a few other similar props who use uint64). * Use option for parser.order * Remove '.'s from parser.order.fields No reason for this to exist, and will confuse anyone using it. * Use option for parser.GroupBy * Use option for parser.Filter * Cleanup commit-query branching Now using proper consts, and defined in the same location as everything else. * Remove unused param * Remove unused commit.GetRoot func * Remove unused mutation.GetRoot func * Tidy up parser.Root references Previous if was conceptually incorrect. None option added no value (select.Root now defaults to Object, which could be handy for users anyway). Also types the enum. * Move parser.types to client dir Also breaks up types.go in preparation for the moving of the rest of the model. * Rename parser.Query to parser.Request As agreed as a team, commit does not seek to rename all variables referencing this - that can be done later to save drowning this large PR with minor changes * Move request model out of parser package The parser package is now responisble for converting an gql-ast into a shared model. Soon it will be responisble for converting a string into the shared model. Mostly a copy-paste commit.
- Loading branch information
1 parent
9490679
commit 6ccae7f
Showing
39 changed files
with
948 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package request | ||
|
||
import "github.com/sourcenetwork/defradb/client" | ||
|
||
type Aggregate struct { | ||
Field | ||
|
||
Targets []*AggregateTarget | ||
} | ||
|
||
type AggregateTarget struct { | ||
HostName string | ||
ChildName client.Option[string] | ||
|
||
Limit client.Option[uint64] | ||
Offset client.Option[uint64] | ||
OrderBy client.Option[OrderBy] | ||
Filter client.Option[Filter] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package request | ||
|
||
import "github.com/sourcenetwork/defradb/client" | ||
|
||
var ( | ||
_ Selection = (*CommitSelect)(nil) | ||
) | ||
|
||
type CommitSelect struct { | ||
Field | ||
|
||
DocKey client.Option[string] | ||
FieldName client.Option[string] | ||
Cid client.Option[string] | ||
Depth client.Option[uint64] | ||
|
||
Limit client.Option[uint64] | ||
Offset client.Option[uint64] | ||
OrderBy client.Option[OrderBy] | ||
GroupBy client.Option[GroupBy] | ||
|
||
Fields []Selection | ||
} | ||
|
||
func (c CommitSelect) ToSelect() *Select { | ||
return &Select{ | ||
Field: Field{ | ||
Name: c.Name, | ||
Alias: c.Alias, | ||
}, | ||
Limit: c.Limit, | ||
Offset: c.Offset, | ||
OrderBy: c.OrderBy, | ||
GroupBy: c.GroupBy, | ||
Fields: c.Fields, | ||
Root: CommitSelection, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
/* | ||
Package request defines the GraphQL types used by the query service. | ||
*/ | ||
package request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package request | ||
|
||
import "github.com/sourcenetwork/defradb/client" | ||
|
||
// Field implements Selection | ||
type Field struct { | ||
Name string | ||
Alias client.Option[string] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package request | ||
|
||
// Filter contains the parsed condition map to be | ||
// run by the Filter Evaluator. | ||
// @todo: Cache filter structure for faster condition | ||
// evaluation. | ||
type Filter struct { | ||
// parsed filter conditions | ||
Conditions map[string]any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package request | ||
|
||
type GroupBy struct { | ||
Fields []string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package request | ||
|
||
import "github.com/sourcenetwork/defradb/client" | ||
|
||
type MutationType int | ||
|
||
const ( | ||
NoneMutationType = MutationType(iota) | ||
CreateObjects | ||
UpdateObjects | ||
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 { | ||
Field | ||
Type MutationType | ||
|
||
// Schema is the target schema/collection | ||
// if this mutation is on an object. | ||
Schema string | ||
|
||
IDs client.Option[[]string] | ||
Filter client.Option[Filter] | ||
Data string | ||
|
||
Fields []Selection | ||
} | ||
|
||
// 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 { | ||
return &Select{ | ||
Field: Field{ | ||
Name: m.Schema, | ||
Alias: m.Alias, | ||
}, | ||
Fields: m.Fields, | ||
DocKeys: m.IDs, | ||
Filter: m.Filter, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package request | ||
|
||
type ( | ||
OrderDirection string | ||
|
||
OrderCondition struct { | ||
// field may be a compound field statement | ||
// since the order statement allows ordering on | ||
// sub objects. | ||
// | ||
// Given the statement: {order: {author: {birthday: DESC}}} | ||
// The field value would be "author.birthday" | ||
// and the direction would be "DESC" | ||
Fields []string | ||
Direction OrderDirection | ||
} | ||
|
||
OrderBy struct { | ||
Conditions []OrderCondition | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package request | ||
|
||
type Request struct { | ||
Queries []*OperationDefinition | ||
Mutations []*OperationDefinition | ||
} | ||
|
||
type Selection any | ||
|
||
type OperationDefinition struct { | ||
Selections []Selection | ||
IsExplain bool | ||
} |
Oops, something went wrong.