-
Notifications
You must be signed in to change notification settings - Fork 46
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: Cleanup parsing logic #909
Changes from all commits
a495605
09ee245
59a2552
dbc0c29
2aa6fce
b29ef39
70b551b
905e0b1
8541eb7
b57cbb9
223ee45
2b32b4d
54c01da
96a2e5f
9dd361f
08200c1
8fd6daa
fea5168
03af621
22ea7bf
cf81e28
fc63d4f
23660f6
fd4d0ef
79d15b4
743183e
29ef5f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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] | ||
} |
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, | ||
} | ||
} |
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 |
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] | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: remove or add corresponding issue number. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of scope |
||
// evaluation. | ||
type Filter struct { | ||
// parsed filter conditions | ||
Conditions map[string]any | ||
} |
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 | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: remove or add corresponding issue number. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of scope |
||
// 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, | ||
} | ||
} |
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 | ||
} | ||
) |
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is the purpose of the
consts.go
file different from the types file? I thought there was consensus to keep types under it's own namespace usingtypes
package ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having a types file in directory full of other files with other types is not very helpful IMO. A types file made sense when there was only a sub set of the model in it (and even that was odd as is was super-arbitrary as to what was in it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree that it was odd, I am talking from the perspective of keeping things in harmony as the code base grows and having a convention that would be well understood by the team, for example, I am happy with storing constants in
consts.go
file as it is very self-evident to know what that file contains. Would like to see us use consistent patterns to store constants, variables etc. (for structs probably more useful names split under different files). I really enjoyed a popular convention in C++ that said no more than one class / struct per file (perhaps too strict for Go peepz haha).