Skip to content

Commit

Permalink
PR: Fix - handle the filter type error and update genTypeQueryableFi…
Browse files Browse the repository at this point in the history
…eldList according to Johns suggestion. Update the schema tests that also fixes an order field.
  • Loading branch information
shahzadlone committed Sep 18, 2022
1 parent af0022f commit b9ec3d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
37 changes: 9 additions & 28 deletions query/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/logging"

gql "github.com/graphql-go/graphql"
gqlp "github.com/graphql-go/graphql/language/parser"
Expand Down Expand Up @@ -1135,8 +1134,13 @@ func (g *Generator) genTypeFilterArgInput(obj *gql.Object) *gql.InputObject {
Type: operatorType,
}
} else { // objects (relations)
genName := genTypeName(field.Type, "FilterArg")
filterType, isFilterable := g.manager.schema.TypeMap()[genName]
if !isFilterable {
filterType = &gql.InputObjectField{}
}
fields[field.Name] = &gql.InputObjectFieldConfig{
Type: g.manager.schema.TypeMap()[genTypeName(field.Type, "FilterArg")],
Type: filterType,
}
}
}
Expand Down Expand Up @@ -1261,32 +1265,9 @@ func (g *Generator) genTypeQueryableFieldList(
name := obj.Name()

// add the generated types to the type map
if err := g.manager.schema.AppendType(config.filter); err != nil {
log.ErrorE(
ctx,
"Failed to append runtime schema with filter",
err,
logging.NewKV("SchemaItem", config.filter),
)
}

if err := g.manager.schema.AppendType(config.groupBy); err != nil {
log.ErrorE(
ctx,
"Failed to append runtime schema with groupBy",
err,
logging.NewKV("SchemaItem", config.groupBy),
)
}

if err := g.manager.schema.AppendType(config.order); err != nil {
log.ErrorE(
ctx,
"Failed to append runtime schema with order",
err,
logging.NewKV("SchemaItem", config.order),
)
}
g.manager.schema.TypeMap()[config.filter.Name()] = config.filter
g.manager.schema.TypeMap()[config.groupBy.Name()] = config.groupBy
g.manager.schema.TypeMap()[config.order.Name()] = config.order

field := &gql.Field{
// @todo: Handle collection name from @collection directive
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/schema/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ var defaultBookArgsWithoutFilter = trimFields(
buildOrderArg("book", []argDef{
{
fieldName: "author",
typeName: "",
typeName: "authorOrderArg",
},
{
fieldName: "author_id",
Expand Down

0 comments on commit b9ec3d1

Please sign in to comment.