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

Re enable range operation #29

Merged
merged 4 commits into from
Sep 25, 2024
Merged
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
19 changes: 13 additions & 6 deletions connector/static_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package connector

import (
"slices"

"github.com/hasura/ndc-sdk-go/schema"
"github.com/hasura/ndc-sdk-go/utils"
)
Expand Down Expand Up @@ -330,20 +332,25 @@ var objectTypeMap = map[string]schema.ObjectType{
},
}

var unsupportedRangeQueryScalars = []string{"binary", "completion", "_id", "wildcard", "match_only_text", "search_as_you_type"}

// getComparisonOperatorDefinition generates and returns a map of comparison operators based on the provided data type.
func getComparisonOperatorDefinition(dataType string) map[string]schema.ComparisonOperatorDefinition {
var comparisonOperators = map[string]schema.ComparisonOperatorDefinition{
"match": schema.NewComparisonOperatorCustom(schema.NewNamedType(dataType)).Encode(),
"match_phrase": schema.NewComparisonOperatorCustom(schema.NewNamedType(dataType)).Encode(),
"term": schema.NewComparisonOperatorCustom(schema.NewNamedType(dataType)).Encode(),
// "range": schema.NewComparisonOperatorCustom(schema.NewNamedType("range")).Encode(), // TODO: add back once object types are supported as comparison operators
"terms": schema.NewComparisonOperatorCustom(schema.NewArrayType(schema.NewNamedType(dataType))).Encode(),
"terms": schema.NewComparisonOperatorCustom(schema.NewArrayType(schema.NewNamedType(dataType))).Encode(),
}

// if dataType == "date" { // TODO: add back once object types are supported as comparison operators
// requiredObjectTypes["date_range_query"] = objectTypeMap["date_range_query"]
// comparisonOperators["range"] = schema.NewComparisonOperatorCustom(schema.NewNamedType("date_range_query")).Encode()
// }
if !slices.Contains(unsupportedRangeQueryScalars, dataType) {
comparisonOperators["range"] = schema.NewComparisonOperatorCustom(schema.NewNamedType("range")).Encode()
}

if dataType == "date" {
requiredObjectTypes["date_range_query"] = objectTypeMap["date_range_query"]
comparisonOperators["range"] = schema.NewComparisonOperatorCustom(schema.NewNamedType("date_range_query")).Encode()
}

if dataType == "text" {
comparisonOperators["match_phrase_prefix"] = schema.NewComparisonOperatorCustom(schema.NewNamedType(dataType)).Encode()
Expand Down