queryArguments constructs a minified arguments string for variables. E.g., map[string]any{"a": Int(123), "b": NewBoolean(true)} -> "$a:Int!$b:Boolean".
(variables map[string]any)
| 56 | // |
| 57 | // E.g., map[string]any{"a": Int(123), "b": NewBoolean(true)} -> "$a:Int!$b:Boolean". |
| 58 | func queryArguments(variables map[string]any) string { |
| 59 | // Sort keys in order to produce deterministic output for testing purposes. |
| 60 | // TODO: If tests can be made to work with non-deterministic output, then no need to sort. |
| 61 | keys := make([]string, 0, len(variables)) |
| 62 | for k := range variables { |
| 63 | keys = append(keys, k) |
| 64 | } |
| 65 | sort.Strings(keys) |
| 66 | |
| 67 | var buf bytes.Buffer |
| 68 | for _, k := range keys { |
| 69 | _, _ = io.WriteString(&buf, "$") |
| 70 | _, _ = io.WriteString(&buf, k) |
| 71 | _, _ = io.WriteString(&buf, ":") |
| 72 | writeArgumentType(&buf, reflect.TypeOf(variables[k]), true) |
| 73 | // Don't insert a comma here. |
| 74 | // Commas in GraphQL are insignificant, and we want minified output. |
| 75 | // See https://spec.graphql.org/October2021/#sec-Insignificant-Commas. |
| 76 | } |
| 77 | return buf.String() |
| 78 | } |
| 79 | |
| 80 | // writeArgumentType writes a minified GraphQL type for t to w. |
| 81 | // value indicates whether t is a value (required) type or pointer (optional) type. |
no test coverage detected