Skip to content

feat: allow dots in StringMapInput type #296

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

Merged
merged 9 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
47 changes: 47 additions & 0 deletions gateway/schema/scalars.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,50 @@ var jsonStringScalar = graphql.NewScalar(graphql.ScalarConfig{
return nil
},
})

var stringMapInput = graphql.NewScalar(graphql.ScalarConfig{
Name: "StringMapInput",
Description: "Input type for a map from strings to strings.",
Serialize: func(value interface{}) interface{} {
return value
},
ParseValue: func(value interface{}) interface{} {
switch val := value.(type) {
case map[string]interface{}, map[string]string:
return val
default:
return nil // to tell GraphQL that the value is invalid
}
},
ParseLiteral: func(valueAST ast.Value) any {
switch value := valueAST.(type) {
case *ast.ListValue:
result := map[string]string{}
for _, item := range value.Values {
obj, ok := item.(*ast.ObjectValue)
if !ok {
return nil
}

for _, field := range obj.Fields {
switch field.Name.Value {
case "key":
if key, ok := field.Value.GetValue().(string); ok {
result[key] = ""
}
case "value":
if val, ok := field.Value.GetValue().(string); ok {
for key := range result {
result[key] = val
}
}
}
}
}

return result
default:
return nil // to tell GraphQL that the value is invalid
}
},
})
2 changes: 1 addition & 1 deletion gateway/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (g *Gateway) handleObjectFieldSpecType(fieldSpec spec.Schema, typePrefix st
// Hagndle map types
if len(fieldSpec.AdditionalProperties.Schema.Type) == 1 && fieldSpec.AdditionalProperties.Schema.Type[0] == "string" {
// This is a map[string]string
return stringMapScalar, stringMapScalar, nil
return stringMapScalar, stringMapInput, nil
}
}

Expand Down