Skip to content

Commit ecafd54

Browse files
committed
improve docs
1 parent 5bdae14 commit ecafd54

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ Feel free to open Pull-Request for small fixes and changes. For bigger changes a
4444
an [issue](https://github.com/roneli/fastgql/issues) first to prevent double work and discuss relevant stuff.
4545

4646
## Roadmap 🚧
47-
48-
- More tests
49-
- configurable database connections
47+
- Integration testing, and generation testing
48+
- configurable database connections, augmenters and better schema control
5049
- Support multiple database (mongodb, cockroachDB, neo4j)
51-
- full CRUD creation

pkg/execution/builders/field.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ func GetFilterInput(s *ast.Schema, f *ast.Definition) *ast.Definition {
106106
return s.Types[fmt.Sprintf("%sFilterInput", f.Name)]
107107
}
108108

109+
func GetOperationType(ctx context.Context) OperationType {
110+
opCtx := graphql.GetOperationContext(ctx)
111+
if opCtx.Operation.Operation == "mutation" {
112+
sel := opCtx.Operation.SelectionSet[0]
113+
field := sel.(*ast.Field)
114+
switch {
115+
case strings.HasPrefix(field.Name, "delete"):
116+
return DeleteOperation
117+
case strings.HasPrefix(field.Name, "create"):
118+
return InsertOperation
119+
case strings.HasPrefix(field.Name, "update"):
120+
return UpdateOperation
121+
}
122+
return UnknownOperation
123+
}
124+
return QueryOperation
125+
}
126+
127+
func GetAggregateField(parentField, aggField Field) Field {
128+
fieldName := strings.Split(aggField.Name, "Aggregate")[0][1:]
129+
f, _ := parentField.ForName(fieldName)
130+
return f
131+
}
132+
109133
func CollectOrdering(ordering interface{}) ([]OrderField, error) {
110134
switch orderings := ordering.(type) {
111135
case map[string]interface{}:
@@ -144,30 +168,6 @@ func CollectFields(ctx context.Context, schema *ast.Schema) Field {
144168
return f
145169
}
146170

147-
func GetOperationType(ctx context.Context) OperationType {
148-
opCtx := graphql.GetOperationContext(ctx)
149-
if opCtx.Operation.Operation == "mutation" {
150-
sel := opCtx.Operation.SelectionSet[0]
151-
field := sel.(*ast.Field)
152-
switch {
153-
case strings.HasPrefix(field.Name, "delete"):
154-
return DeleteOperation
155-
case strings.HasPrefix(field.Name, "create"):
156-
return InsertOperation
157-
case strings.HasPrefix(field.Name, "update"):
158-
return UpdateOperation
159-
}
160-
return UnknownOperation
161-
}
162-
return QueryOperation
163-
}
164-
165-
func GetAggregateField(parentField, aggField Field) Field {
166-
fieldName := strings.Split(aggField.Name, "Aggregate")[0][1:]
167-
f, _ := parentField.ForName(fieldName)
168-
return f
169-
}
170-
171171
func CollectFromQuery(field *ast.Field, schema *ast.Schema, opCtx *graphql.OperationContext, args map[string]interface{}) Field {
172172
f := NewField(nil, field, schema, args)
173173
f.Selections = collectFields(&f, schema, opCtx, make(map[string]bool))
@@ -316,6 +316,7 @@ func buildOrderingHelper(argMap map[string]interface{}) []OrderField {
316316
return orderFields
317317
}
318318

319+
// parseFieldType returns the fieldType based on the name/directive or type of the *ast.Field
319320
func parseFieldType(field *ast.Field, typeDef *ast.Definition) fieldType {
320321
switch {
321322
case strings.HasSuffix(field.Name, "Aggregate"):

pkg/execution/builders/sql/aggregators.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ package sql
33
import (
44
"fmt"
55

6-
builders2 "github.com/roneli/fastgql/pkg/execution/builders"
7-
86
"github.com/doug-martin/goqu/v9"
97
"github.com/doug-martin/goqu/v9/exp"
108
"github.com/iancoleman/strcase"
9+
10+
"github.com/roneli/fastgql/pkg/execution/builders"
1111
)
1212

13-
var defaultAggregatorOperators = map[string]builders2.AggregatorOperator{
13+
var defaultAggregatorOperators = map[string]builders.AggregatorOperator{
1414
"max": MaxAggregator,
1515
"min": MinAggregator,
1616
}
1717

18-
func MaxAggregator(table exp.AliasedExpression, fields []builders2.Field) (goqu.Expression, error) {
18+
func MaxAggregator(table exp.AliasedExpression, fields []builders.Field) (goqu.Expression, error) {
1919
maxFields := make([]interface{}, 0, len(fields)*2)
2020
for _, f := range fields {
2121
maxFields = append(maxFields, goqu.L(fmt.Sprintf("'%s'", f.Name)), goqu.MAX(table.Col(strcase.ToSnake(f.Name))))
2222
}
2323
return goqu.Func("json_build_object", maxFields...), nil
2424
}
2525

26-
func MinAggregator(table exp.AliasedExpression, fields []builders2.Field) (goqu.Expression, error) {
26+
func MinAggregator(table exp.AliasedExpression, fields []builders.Field) (goqu.Expression, error) {
2727
minFields := make([]interface{}, 0, len(fields)*2)
2828
for _, f := range fields {
2929
minFields = append(minFields, goqu.L(fmt.Sprintf("'%s'", f.Name)), goqu.MIN(table.Col(strcase.ToSnake(f.Name))))

pkg/execution/builders/sql/builder.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func (b Builder) buildFilterExp(table tableHelper, astDefinition *ast.Definition
404404
return nil, fmt.Errorf("fatal value of key not map")
405405
}
406406
for op, value := range opMap {
407-
opExp, err := b.Operation(table.table, k, op, value)
407+
opExp, err := b.buildOperation(table.table, k, op, value)
408408
if err != nil {
409409
return nil, err
410410
}
@@ -415,14 +415,6 @@ func (b Builder) buildFilterExp(table tableHelper, astDefinition *ast.Definition
415415
return expBuilder, nil
416416
}
417417

418-
func (b Builder) Operation(table exp.AliasedExpression, fieldName, operatorName string, value interface{}) (goqu.Expression, error) {
419-
opFunc, ok := b.Operators[operatorName]
420-
if !ok {
421-
return nil, fmt.Errorf("key operator %s not supported", operatorName)
422-
}
423-
return opFunc(table, b.CaseConverter(fieldName), value), nil
424-
}
425-
426418
func (b Builder) buildRelation(parentQuery *queryHelper, rf builders.Field) error {
427419
tableDef := getTableNameFromField(b.Schema, rf.Definition)
428420
relationQuery, err := b.buildQuery(tableDef, rf)
@@ -533,3 +525,11 @@ func (b Builder) buildFilterQuery(parentTable tableHelper, rf *ast.Definition, r
533525
fq.SelectDataset = fq.Where(expBuilder)
534526
return fq, nil
535527
}
528+
529+
func (b Builder) buildOperation(table exp.AliasedExpression, fieldName, operatorName string, value interface{}) (goqu.Expression, error) {
530+
opFunc, ok := b.Operators[operatorName]
531+
if !ok {
532+
return nil, fmt.Errorf("key operator %s not supported", operatorName)
533+
}
534+
return opFunc(table, b.CaseConverter(fieldName), value), nil
535+
}

pkg/execution/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type Scanner interface {
1010
}
1111

1212
type Driver interface {
13+
// Scanner is the main function of all drivers, a scanner will read the GraphQL AST from the context.Context
1314
Scanner
15+
// Close gracefully requests the driver to close
1416
Close() error
1517
// Dialect returns the dialect name of the driver.
1618
Dialect() string

0 commit comments

Comments
 (0)