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

added support to disable dataloader #1501

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion gateway/utils/graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ func (graph *Module) execGraphQLDocument(ctx context.Context, node ast.Node, tok
cb(nil, nil)
return
}
req := &model.ReadRequest{Operation: utils.All, Find: map[string]interface{}{linkedInfo.To: val}, PostProcess: map[string]*model.PostProcess{}}
req := &model.ReadRequest{Operation: utils.All, Find: map[string]interface{}{linkedInfo.To: val}, PostProcess: map[string]*model.PostProcess{}, Options: &model.ReadOptions{}}
options, hasOptions, _ := generateOptions(ctx, field.Arguments, store)
if hasOptions {
req.Options.Debug = options.Debug
}
graph.processLinkedResult(ctx, field, *fieldStruct, token, req, store, cb)
return
}
Expand All @@ -287,6 +291,14 @@ func (graph *Module) execGraphQLDocument(ctx context.Context, node ast.Node, tok
return
}

if schema != nil {
fieldStruct, p := schema[field.Name.Value]
if p && fieldStruct.IsLinked {
linkedInfo := fieldStruct.LinkedTable
schema, _ = graph.schema.GetSchema(linkedInfo.DBType, linkedInfo.Table)
}
}

graph.processQueryResult(ctx, field, token, store, currentValue, schema, cb)
return

Expand Down
27 changes: 26 additions & 1 deletion gateway/utils/graphql/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ func (graph *Module) execReadRequest(ctx context.Context, field *ast.Field, toke
return
}

isDataloaderDisabled, err := isDataLoaderDisabled(ctx, field, store)
if err != nil {
cb("", "", nil, err)
return
}

go func() {
// batch operation cannot be performed with aggregation or joins or when post processing is applied
req.IsBatch = !(len(req.Aggregate) > 0 || len(req.Options.Join) > 0)
req.IsBatch = !(isDataloaderDisabled || len(req.Aggregate) > 0 || len(req.Options.Join) > 0)
req.Options.HasOptions = hasOptions
result, metaData, err := graph.crud.Read(ctx, dbAlias, col, req, reqParams)
if err != nil {
Expand All @@ -149,6 +155,25 @@ func (graph *Module) execReadRequest(ctx context.Context, field *ast.Field, toke
}()
}

func isDataLoaderDisabled(ctx context.Context, field *ast.Field, store utils.M) (bool, error) {
for _, arg := range field.Arguments {
switch arg.Name.Value {
case "disableDataloader": // create
val, err := utils.ParseGraphqlValue(arg.Value, store)
if err != nil {
helpers.Logger.LogWarn(helpers.GetRequestID(ctx), fmt.Sprintf("Unable to extract argument from graphql query (%s)", arg.Name.Value), map[string]interface{}{"argValue": arg.Value.GetValue()})
continue
}
tempBool, ok := val.(bool)
if !ok {
return false, helpers.Logger.LogError(helpers.GetRequestID(ctx), "Field (disableDataloader) should be of type boolean", nil, nil)
}
return tempBool, nil
}
}
return false, nil
}

func (graph *Module) runAuthForJoins(ctx context.Context, dbType, dbAlias, token string, req *model.ReadRequest, join []*model.JoinOption) error {
for _, j := range join {
returnWhere := model.ReturnWhereStub{Col: j.Table, PrefixColName: len(req.Options.Join) > 0, ReturnWhere: dbType != string(model.Mongo), Where: map[string]interface{}{}}
Expand Down