From af21a3f0ff4f548a14c379d96cb3e4faee84c8bf Mon Sep 17 00:00:00 2001 From: Alex Suraci Date: Tue, 19 Sep 2023 12:52:32 -0400 Subject: [PATCH] interface{} -> any --- dependencies.go | 22 +++++++++++----------- directives.go | 28 ++++++++++++++-------------- directives_test.go | 14 +++++++------- graphqlws/connections.go | 22 +++++++++++----------- graphqlws/logger.go | 16 ++++++++-------- graphqlws/wshandler.go | 4 ++-- handler/handler.go | 10 +++++----- helpers.go | 12 ++++++------ registry.go | 4 ++-- resolvers.go | 4 ++-- scalars/bool_string.go | 6 +++--- scalars/json.go | 10 +++++----- scalars/query_document.go | 22 +++++++++++----------- scalars/string_set.go | 12 ++++++------ schema.go | 4 ++-- schema_test.go | 22 +++++++++++----------- server/graphqlws.go | 2 +- server/graphqlws/connections.go | 22 +++++++++++----------- server/handler.go | 8 ++++---- server/logger/logger.go | 16 ++++++++-------- server/server.go | 4 ++-- typedefs_test.go | 4 ++-- types.go | 4 ++-- values.go | 6 +++--- 24 files changed, 139 insertions(+), 139 deletions(-) diff --git a/dependencies.go b/dependencies.go index ca12ec4..549b0a4 100644 --- a/dependencies.go +++ b/dependencies.go @@ -7,14 +7,14 @@ import ( "github.com/dagger/graphql/language/kinds" ) -type DependencyMap map[string]map[string]interface{} +type DependencyMap map[string]map[string]any func (r *registry) IdentifyDependencies() (DependencyMap, error) { m := DependencyMap{} // get list of initial types, all dependencies should be resolved for _, t := range r.types { - m[t.Name()] = map[string]interface{}{} + m[t.Name()] = map[string]any{} } for _, def := range r.unresolvedDefs { @@ -25,10 +25,10 @@ func (r *registry) IdentifyDependencies() (DependencyMap, error) { } case kinds.ScalarDefinition: scalar := def.(*ast.ScalarDefinition) - m[scalar.Name.Value] = map[string]interface{}{} + m[scalar.Name.Value] = map[string]any{} case kinds.EnumDefinition: enum := def.(*ast.EnumDefinition) - m[enum.Name.Value] = map[string]interface{}{} + m[enum.Name.Value] = map[string]any{} case kinds.InputObjectDefinition: if err := identifyInputDependencies(m, def.(*ast.InputObjectDefinition)); err != nil { return nil, err @@ -51,7 +51,7 @@ func (r *registry) IdentifyDependencies() (DependencyMap, error) { } // attempt to resolve - resolved := map[string]interface{}{} + resolved := map[string]any{} maxIteration := len(m) + 1 count := 0 @@ -90,7 +90,7 @@ func identifyUnionDependencies(m DependencyMap, def *ast.UnionDefinition) error name := def.Name.Value deps, ok := m[name] if !ok { - deps = map[string]interface{}{} + deps = map[string]any{} } for _, t := range def.Types { @@ -112,7 +112,7 @@ func identifyInterfaceDependencies(m DependencyMap, def *ast.InterfaceDefinition name := def.Name.Value deps, ok := m[name] if !ok { - deps = map[string]interface{}{} + deps = map[string]any{} } for _, field := range def.Fields { @@ -144,7 +144,7 @@ func identifyInterfaceDependencies(m DependencyMap, def *ast.InterfaceDefinition func identifySchemaDependencies(m DependencyMap, def *ast.SchemaDefinition) { deps, ok := m["schema"] if !ok { - deps = map[string]interface{}{} + deps = map[string]any{} } for _, op := range def.OperationTypes { @@ -188,7 +188,7 @@ func identifyDirectiveDependencies(m DependencyMap, def *ast.DirectiveDefinition name := "@" + def.Name.Value deps, ok := m[name] if !ok { - deps = map[string]interface{}{} + deps = map[string]any{} } for _, arg := range def.Arguments { @@ -210,7 +210,7 @@ func identifyInputDependencies(m DependencyMap, def *ast.InputObjectDefinition) name := def.Name.Value deps, ok := m[name] if !ok { - deps = map[string]interface{}{} + deps = map[string]any{} } for _, field := range def.Fields { @@ -233,7 +233,7 @@ func identifyObjectDependencies(m DependencyMap, def *ast.ObjectDefinition) erro name := def.Name.Value deps, ok := m[name] if !ok { - deps = map[string]interface{}{} + deps = map[string]any{} } for _, field := range def.Fields { diff --git a/directives.go b/directives.go index 01290b3..aff20e4 100644 --- a/directives.go +++ b/directives.go @@ -41,7 +41,7 @@ type VisitSchemaParams struct { Context context.Context Config *graphql.SchemaConfig Node *ast.SchemaDefinition - Args map[string]interface{} + Args map[string]any } // VisitScalarParams params @@ -49,7 +49,7 @@ type VisitScalarParams struct { Context context.Context Config *graphql.ScalarConfig Node *ast.ScalarDefinition - Args map[string]interface{} + Args map[string]any } // VisitObjectParams params @@ -58,7 +58,7 @@ type VisitObjectParams struct { Config *graphql.ObjectConfig Node *ast.ObjectDefinition Extensions []*ast.ObjectDefinition - Args map[string]interface{} + Args map[string]any } // VisitFieldDefinitionParams params @@ -66,7 +66,7 @@ type VisitFieldDefinitionParams struct { Context context.Context Config *graphql.Field Node *ast.FieldDefinition - Args map[string]interface{} + Args map[string]any ParentName string ParentKind string } @@ -76,7 +76,7 @@ type VisitArgumentDefinitionParams struct { Context context.Context Config *graphql.ArgumentConfig Node *ast.InputValueDefinition - Args map[string]interface{} + Args map[string]any } // VisitInterfaceParams params @@ -84,7 +84,7 @@ type VisitInterfaceParams struct { Context context.Context Config *graphql.InterfaceConfig Node *ast.InterfaceDefinition - Args map[string]interface{} + Args map[string]any } // VisitUnionParams params @@ -92,7 +92,7 @@ type VisitUnionParams struct { Context context.Context Config *graphql.UnionConfig Node *ast.UnionDefinition - Args map[string]interface{} + Args map[string]any } // VisitEnumParams params @@ -100,7 +100,7 @@ type VisitEnumParams struct { Context context.Context Config *graphql.EnumConfig Node *ast.EnumDefinition - Args map[string]interface{} + Args map[string]any } // VisitEnumValueParams params @@ -108,7 +108,7 @@ type VisitEnumValueParams struct { Context context.Context Config *graphql.EnumValueConfig Node *ast.EnumValueDefinition - Args map[string]interface{} + Args map[string]any } // VisitInputObjectParams params @@ -116,7 +116,7 @@ type VisitInputObjectParams struct { Context context.Context Config *graphql.InputObjectConfig Node *ast.InputObjectDefinition - Args map[string]interface{} + Args map[string]any } // VisitInputFieldDefinitionParams params @@ -124,7 +124,7 @@ type VisitInputFieldDefinitionParams struct { Context context.Context Config *graphql.InputObjectFieldConfig Node *ast.InputValueDefinition - Args map[string]interface{} + Args map[string]any } // SchemaDirectiveVisitorMap a map of schema directive visitors @@ -170,9 +170,9 @@ func (c *registry) buildDirectiveFromAST(definition *ast.DirectiveDefinition) er } type applyDirectiveParams struct { - config interface{} + config any directives []*ast.Directive - node interface{} + node any extensions []*ast.ObjectDefinition parentName string parentKind string @@ -196,7 +196,7 @@ func (c *registry) applyDirectives(p applyDirectiveParams) error { return err } - args, err := GetArgumentValues(directive.Args, def.Arguments, map[string]interface{}{}) + args, err := GetArgumentValues(directive.Args, def.Arguments, map[string]any{}) if err != nil { return err } diff --git a/directives_test.go b/directives_test.go index 5d339f9..9af755a 100644 --- a/directives_test.go +++ b/directives_test.go @@ -23,7 +23,7 @@ type Query { ` // create some data - foos := []map[string]interface{}{ + foos := []map[string]any{ { "name": "foo", "description": "a foo", @@ -37,7 +37,7 @@ type Query { "Query": &ObjectResolver{ Fields: FieldResolveMap{ "foos": &FieldResolve{ - Resolve: func(p graphql.ResolveParams) (interface{}, error) { + Resolve: func(p graphql.ResolveParams) (any, error) { return foos, nil }, }, @@ -48,12 +48,12 @@ type Query { "test": &SchemaDirectiveVisitor{ VisitFieldDefinition: func(v VisitFieldDefinitionParams) error { resolveFunc := v.Config.Resolve - v.Config.Resolve = func(p graphql.ResolveParams) (interface{}, error) { + v.Config.Resolve = func(p graphql.ResolveParams) (any, error) { result, err := resolveFunc(p) if err != nil { return result, err } - res := result.([]map[string]interface{}) + res := result.([]map[string]any) res0 := res[0] res0["description"] = v.Args["message"] return res, nil @@ -86,10 +86,10 @@ type Query { return } - d := r.Data.(map[string]interface{}) + d := r.Data.(map[string]any) fooResult := d["foos"] - foos0 := fooResult.([]interface{})[0] - foos0Desc := foos0.(map[string]interface{})["description"] + foos0 := fooResult.([]any)[0] + foos0Desc := foos0.(map[string]any)["description"] if foos0Desc.(string) != "foobar" { t.Error("failed to set field with directive") return diff --git a/graphqlws/connections.go b/graphqlws/connections.go index 823165a..38ee88a 100644 --- a/graphqlws/connections.go +++ b/graphqlws/connections.go @@ -43,22 +43,22 @@ type InitMessagePayload struct { // StartMessagePayload defines the parameters of an operation that // a client requests to be started. type StartMessagePayload struct { - Query string `json:"query"` - Variables map[string]interface{} `json:"variables"` - OperationName string `json:"operationName"` + Query string `json:"query"` + Variables map[string]any `json:"variables"` + OperationName string `json:"operationName"` } // DataMessagePayload defines the result data of an operation. type DataMessagePayload struct { - Data interface{} `json:"data"` - Errors []error `json:"errors"` + Data any `json:"data"` + Errors []error `json:"errors"` } // OperationMessage represents a GraphQL WebSocket message. type OperationMessage struct { - ID string `json:"id"` - Type string `json:"type"` - Payload interface{} `json:"payload"` + ID string `json:"id"` + Type string `json:"type"` + Payload any `json:"payload"` } func (msg OperationMessage) String() string { @@ -71,7 +71,7 @@ func (msg OperationMessage) String() string { // AuthenticateFunc is a function that resolves an auth token // into a user (or returns an error if that isn't possible). -type AuthenticateFunc func(data map[string]interface{}, conn Connection) (context.Context, error) +type AuthenticateFunc func(data map[string]any, conn Connection) (context.Context, error) // ConnectionEventHandlers define the event handlers for a connection. // Event handlers allow other system components to react to events such @@ -282,7 +282,7 @@ func (conn *connection) readLoop() { switch msg.Type { case gqlConnectionAuth: - data := map[string]interface{}{} + data := map[string]any{} if err := json.Unmarshal(rawPayload, &data); err != nil { conn.logger.Debugf("Invalid %s data: %v", msg.Type, err) conn.SendError(errors.New("invalid GQL_CONNECTION_AUTH payload")) @@ -301,7 +301,7 @@ func (conn *connection) readLoop() { // When the GraphQL WS connection is initiated, send an ACK back case gqlConnectionInit: - data := map[string]interface{}{} + data := map[string]any{} if err := json.Unmarshal(rawPayload, &data); err != nil { conn.logger.Debugf("Invalid %s data: %v", msg.Type, err) conn.SendError(errors.New("invalid GQL_CONNECTION_INIT payload")) diff --git a/graphqlws/logger.go b/graphqlws/logger.go index ee0227c..6379b68 100644 --- a/graphqlws/logger.go +++ b/graphqlws/logger.go @@ -1,15 +1,15 @@ package graphqlws type Logger interface { - Infof(format string, data ...interface{}) - Debugf(format string, data ...interface{}) - Errorf(format string, data ...interface{}) - Warnf(format string, data ...interface{}) + Infof(format string, data ...any) + Debugf(format string, data ...any) + Errorf(format string, data ...any) + Warnf(format string, data ...any) } type noopLogger struct{} -func (n *noopLogger) Infof(format string, data ...interface{}) {} -func (n *noopLogger) Debugf(format string, data ...interface{}) {} -func (n *noopLogger) Errorf(format string, data ...interface{}) {} -func (n *noopLogger) Warnf(format string, data ...interface{}) {} +func (n *noopLogger) Infof(format string, data ...any) {} +func (n *noopLogger) Debugf(format string, data ...any) {} +func (n *noopLogger) Errorf(format string, data ...any) {} +func (n *noopLogger) Warnf(format string, data ...any) {} diff --git a/graphqlws/wshandler.go b/graphqlws/wshandler.go index bdd0f72..9f48586 100644 --- a/graphqlws/wshandler.go +++ b/graphqlws/wshandler.go @@ -9,14 +9,14 @@ import ( ) // ConnKey the connection key -var ConnKey interface{} = "conn" +var ConnKey any = "conn" // HandlerConfig config type HandlerConfig struct { Logger Logger Authenticate AuthenticateFunc Schema graphql.Schema - RootValue map[string]interface{} + RootValue map[string]any } // NewHandler creates a new handler diff --git a/handler/handler.go b/handler/handler.go index 4a4ac47..e7a2868 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -35,9 +35,9 @@ type Handler struct { // RequestOptions options type RequestOptions struct { - Query string `json:"query" url:"query" schema:"query"` - Variables map[string]interface{} `json:"variables" url:"variables" schema:"variables"` - OperationName string `json:"operationName" url:"operationName" schema:"operationName"` + Query string `json:"query" url:"query" schema:"query"` + Variables map[string]any `json:"variables" url:"variables" schema:"variables"` + OperationName string `json:"operationName" url:"operationName" schema:"operationName"` } // a workaround for getting`variables` as a JSON string @@ -51,7 +51,7 @@ func getFromForm(values url.Values) *RequestOptions { query := values.Get("query") if query != "" { // get variables map - variables := make(map[string]interface{}, len(values)) + variables := make(map[string]any, len(values)) variablesStr := values.Get("variables") json.Unmarshal([]byte(variablesStr), &variables) @@ -196,7 +196,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // RootObjectFn allows a user to generate a RootObject per request -type RootObjectFn func(ctx context.Context, r *http.Request) map[string]interface{} +type RootObjectFn func(ctx context.Context, r *http.Request) map[string]any // Config configuration type Config struct { diff --git a/helpers.go b/helpers.go index 0c42051..0fd83ec 100644 --- a/helpers.go +++ b/helpers.go @@ -78,7 +78,7 @@ func getDescription(node ast.DescribableNode) string { return "" } -func parseDefaultValue(inputType ast.Type, value interface{}) (interface{}, error) { +func parseDefaultValue(inputType ast.Type, value any) (any, error) { if value == nil { return nil, nil } @@ -92,7 +92,7 @@ func parseDefaultValue(inputType ast.Type, value interface{}) (interface{}, erro case *ast.List: switch a := value.(type) { case []ast.Value: - arr := []interface{}{} + arr := []any{} for _, v := range a { val, err := parseDefaultValue(t.Type, v.GetValue()) if err != nil { @@ -124,7 +124,7 @@ func parseDefaultValue(inputType ast.Type, value interface{}) (interface{}, erro } // gets the default value or defaults to nil -func getDefaultValue(input *ast.InputValueDefinition) (interface{}, error) { +func getDefaultValue(input *ast.InputValueDefinition) (any, error) { if input.DefaultValue == nil { return nil, nil } @@ -184,12 +184,12 @@ func ReadSourceFiles(p string, recursive ...bool) (string, error) { } // UnaliasedPathArray gets the path array for a resolve function without aliases -func UnaliasedPathArray(info graphql.ResolveInfo) []interface{} { - return unaliasedPathArray(info.Operation.GetSelectionSet(), info.Path.AsArray(), []interface{}{}) +func UnaliasedPathArray(info graphql.ResolveInfo) []any { + return unaliasedPathArray(info.Operation.GetSelectionSet(), info.Path.AsArray(), []any{}) } // gets the actual field path for a selection by removing aliases -func unaliasedPathArray(set *ast.SelectionSet, remaining []interface{}, current []interface{}) []interface{} { +func unaliasedPathArray(set *ast.SelectionSet, remaining []any, current []any) []any { if len(remaining) == 0 { return current } diff --git a/registry.go b/registry.go index 542bc67..ada5b05 100644 --- a/registry.go +++ b/registry.go @@ -33,7 +33,7 @@ type registry struct { // newRegistry creates a new registry func newRegistry( ctx context.Context, - resolvers map[string]interface{}, + resolvers map[string]any, directiveMap SchemaDirectiveVisitorMap, extensions []graphql.Extension, document *ast.Document, @@ -148,7 +148,7 @@ func (c *registry) getExtensions(name, kind string) []*ast.ObjectDefinition { } // imports a resolver from an interface -func (c *registry) importResolver(name string, resolver interface{}) error { +func (c *registry) importResolver(name string, resolver any) error { switch res := resolver.(type) { case *graphql.Directive: // allow @ to be prefixed to a directive in the event there is a type with the same diff --git a/resolvers.go b/resolvers.go index 8c5a40e..5857b83 100644 --- a/resolvers.go +++ b/resolvers.go @@ -12,7 +12,7 @@ type Resolver interface { // ResolverMap a map of resolver configurations. // Accept generic interfaces and identify types at build -type ResolverMap map[string]interface{} +type ResolverMap map[string]any // internal resolver map type resolverMap map[string]Resolver @@ -72,7 +72,7 @@ func (c *UnionResolver) getKind() string { // EnumResolver config for enum values type EnumResolver struct { - Values map[string]interface{} + Values map[string]any } // GetKind gets the kind diff --git a/scalars/bool_string.go b/scalars/bool_string.go index 57184d2..35e5e36 100644 --- a/scalars/bool_string.go +++ b/scalars/bool_string.go @@ -12,11 +12,11 @@ var ScalarBoolString = graphql.NewScalar( graphql.ScalarConfig{ Name: "BoolString", Description: "BoolString converts a boolean to/from a string", - Serialize: func(value interface{}) interface{} { + Serialize: func(value any) any { valStr := fmt.Sprintf("%v", value) return valStr == "true" || valStr == "1" }, - ParseValue: func(value interface{}) interface{} { + ParseValue: func(value any) any { b, ok := value.(bool) if !ok { return "false" @@ -25,7 +25,7 @@ var ScalarBoolString = graphql.NewScalar( } return "false" }, - ParseLiteral: func(astValue ast.Value) interface{} { + ParseLiteral: func(astValue ast.Value) any { value := astValue.GetValue() b, ok := value.(bool) if !ok { diff --git a/scalars/json.go b/scalars/json.go index b21d753..b71b34b 100644 --- a/scalars/json.go +++ b/scalars/json.go @@ -11,10 +11,10 @@ var ScalarJSON = graphql.NewScalar( graphql.ScalarConfig{ Name: "JSON", Description: "The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf)", - Serialize: func(value interface{}) interface{} { + Serialize: func(value any) any { return value }, - ParseValue: func(value interface{}) interface{} { + ParseValue: func(value any) any { return value }, ParseLiteral: parseLiteralJSONFn, @@ -22,7 +22,7 @@ var ScalarJSON = graphql.NewScalar( ) // recursively parse ast -func parseLiteralJSONFn(astValue ast.Value) interface{} { +func parseLiteralJSONFn(astValue ast.Value) any { switch kind := astValue.GetKind(); kind { // get value for primitive types case kinds.StringValue, kinds.BooleanValue, kinds.IntValue, kinds.FloatValue: @@ -30,7 +30,7 @@ func parseLiteralJSONFn(astValue ast.Value) interface{} { // make a map for objects case kinds.ObjectValue: - obj := make(map[string]interface{}) + obj := make(map[string]any) for _, v := range astValue.GetValue().([]*ast.ObjectField) { obj[v.Name.Value] = parseLiteralJSONFn(v.Value) } @@ -38,7 +38,7 @@ func parseLiteralJSONFn(astValue ast.Value) interface{} { // make a slice for lists case kinds.ListValue: - list := make([]interface{}, 0) + list := make([]any, 0) for _, v := range astValue.GetValue().([]ast.Value) { list = append(list, parseLiteralJSONFn(v)) } diff --git a/scalars/query_document.go b/scalars/query_document.go index d7148d2..adbae67 100644 --- a/scalars/query_document.go +++ b/scalars/query_document.go @@ -12,19 +12,19 @@ import ( var queryDocOperatorRx = regexp.MustCompile(`^\$`) var storedQueryDocOperatorRx = regexp.MustCompile(`^_`) -func replacePrefixedKeys(obj interface{}, prefixRx *regexp.Regexp, replacement string) interface{} { +func replacePrefixedKeys(obj any, prefixRx *regexp.Regexp, replacement string) any { switch obj.(type) { - case map[string]interface{}: - result := map[string]interface{}{} - for k, v := range obj.(map[string]interface{}) { + case map[string]any: + result := map[string]any{} + for k, v := range obj.(map[string]any) { newKey := prefixRx.ReplaceAllString(k, replacement) result[newKey] = replacePrefixedKeys(v, prefixRx, replacement) } return result - case []interface{}: - result := []interface{}{} - for _, v := range obj.([]interface{}) { + case []any: + result := []any{} + for _, v := range obj.([]any) { result = append(result, replacePrefixedKeys(v, prefixRx, replacement)) } return result @@ -34,16 +34,16 @@ func replacePrefixedKeys(obj interface{}, prefixRx *regexp.Regexp, replacement s } } -func serializeQueryDocFn(value interface{}) interface{} { +func serializeQueryDocFn(value any) any { return replacePrefixedKeys(value, storedQueryDocOperatorRx, "$") } -func parseValueQueryDocFn(value interface{}) interface{} { +func parseValueQueryDocFn(value any) any { return replacePrefixedKeys(value, queryDocOperatorRx, "_") } -func parseLiteralQueryDocFn(astValue ast.Value) interface{} { - var val interface{} +func parseLiteralQueryDocFn(astValue ast.Value) any { + var val any switch astValue.GetKind() { case kinds.StringValue: bvalue := []byte(astValue.GetValue().(string)) diff --git a/scalars/string_set.go b/scalars/string_set.go index 329a66b..6484c42 100644 --- a/scalars/string_set.go +++ b/scalars/string_set.go @@ -7,7 +7,7 @@ import ( "github.com/dagger/graphql/language/ast" ) -func ensureArray(value interface{}) interface{} { +func ensureArray(value any) any { switch kind := reflect.TypeOf(value).Kind(); kind { case reflect.Slice, reflect.Array: return value @@ -15,11 +15,11 @@ func ensureArray(value interface{}) interface{} { if reflect.ValueOf(value).IsNil() { return nil } - return []interface{}{value} + return []any{value} } } -func serializeStringSetFn(value interface{}) interface{} { +func serializeStringSetFn(value any) any { switch kind := reflect.TypeOf(value).Kind(); kind { case reflect.Slice, reflect.Array: v := reflect.ValueOf(value) @@ -28,7 +28,7 @@ func serializeStringSetFn(value interface{}) interface{} { } return value default: - return []interface{}{} + return []any{} } } @@ -39,10 +39,10 @@ var ScalarStringSet = graphql.NewScalar( Name: "StringSet", Description: "StringSet allows either a string or list of strings", Serialize: serializeStringSetFn, - ParseValue: func(value interface{}) interface{} { + ParseValue: func(value any) any { return ensureArray(value) }, - ParseLiteral: func(astValue ast.Value) interface{} { + ParseLiteral: func(astValue ast.Value) any { return ensureArray(parseLiteralJSONFn(astValue)) }, }, diff --git a/schema.go b/schema.go index 69e60e8..02ce8ef 100644 --- a/schema.go +++ b/schema.go @@ -31,8 +31,8 @@ func MakeExecutableSchemaWithContext(ctx context.Context, config ExecutableSchem // https://www.apollographql.com/docs/graphql-tools/generate-schema type ExecutableSchema struct { document *ast.Document - TypeDefs interface{} // a string, []string, or func() []string - Resolvers map[string]interface{} // a map of Resolver, Directive, Scalar, Enum, Object, InputObject, Union, or Interface + TypeDefs any // a string, []string, or func() []string + Resolvers map[string]any // a map of Resolver, Directive, Scalar, Enum, Object, InputObject, Union, or Interface SchemaDirectives SchemaDirectiveVisitorMap // Map of SchemaDirectiveVisitor Extensions []graphql.Extension // GraphQL extensions Debug bool // Prints debug messages during compile diff --git a/schema_test.go b/schema_test.go index 8b3e2ad..baeb68a 100644 --- a/schema_test.go +++ b/schema_test.go @@ -32,7 +32,7 @@ type Query { users: [User] } ` - users := []map[string]interface{}{ + users := []map[string]any{ { "id": "1", "type": "user", @@ -49,10 +49,10 @@ type Query { schema, err := MakeExecutableSchema(ExecutableSchema{ TypeDefs: typeDefs, - Resolvers: map[string]interface{}{ + Resolvers: map[string]any{ "User": &InterfaceResolver{ ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object { - value := p.Value.(map[string]interface{}) + value := p.Value.(map[string]any) typ := value["type"].(string) if typ == "user" { return p.Info.Schema.Type("UserAccount").(*graphql.Object) @@ -66,7 +66,7 @@ type Query { "Query": &ObjectResolver{ Fields: FieldResolveMap{ "users": &FieldResolve{ - Resolve: func(p graphql.ResolveParams) (interface{}, error) { + Resolve: func(p graphql.ResolveParams) (any, error) { return users, nil }, }, @@ -123,10 +123,10 @@ type Query { }` // create some data - foos := []map[string]interface{}{ + foos := []map[string]any{ { "name": "foo", - "meta": map[string]interface{}{ + "meta": map[string]any{ "bar": "baz", }, }, @@ -135,11 +135,11 @@ type Query { // make the schema _, err := MakeExecutableSchema(ExecutableSchema{ TypeDefs: typeDefs, - Resolvers: map[string]interface{}{ + Resolvers: map[string]any{ "Query": &ObjectResolver{ Fields: FieldResolveMap{ "foos": &FieldResolve{ - Resolve: func(p graphql.ResolveParams) (interface{}, error) { + Resolve: func(p graphql.ResolveParams) (any, error) { return foos, nil }, }, @@ -173,7 +173,7 @@ schema { ` // create some data - foos := []map[string]interface{}{ + foos := []map[string]any{ { "name": "foo", "description": "a foo", @@ -183,11 +183,11 @@ schema { // make the schema schema, err := MakeExecutableSchema(ExecutableSchema{ TypeDefs: typeDefs, - Resolvers: map[string]interface{}{ + Resolvers: map[string]any{ "Query": &ObjectResolver{ Fields: FieldResolveMap{ "foos": &FieldResolve{ - Resolve: func(p graphql.ResolveParams) (interface{}, error) { + Resolve: func(p graphql.ResolveParams) (any, error) { return foos, nil }, }, diff --git a/server/graphqlws.go b/server/graphqlws.go index 7c4258c..93fe85d 100644 --- a/server/graphqlws.go +++ b/server/graphqlws.go @@ -26,7 +26,7 @@ func (s *Server) newGraphQLWSConnection(ctx context.Context, r *http.Request, ws ) []error { s.log.Debugf("start operations %s on connection %s", opID, conn.ID()) - rootObject := map[string]interface{}{} + rootObject := map[string]any{} if s.options.RootValueFunc != nil { rootObject = s.options.RootValueFunc(ctx, r) } diff --git a/server/graphqlws/connections.go b/server/graphqlws/connections.go index 4ae1977..af85810 100644 --- a/server/graphqlws/connections.go +++ b/server/graphqlws/connections.go @@ -44,22 +44,22 @@ type InitMessagePayload struct { // StartMessagePayload defines the parameters of an operation that // a client requests to be started. type StartMessagePayload struct { - Query string `json:"query"` - Variables map[string]interface{} `json:"variables"` - OperationName string `json:"operationName"` + Query string `json:"query"` + Variables map[string]any `json:"variables"` + OperationName string `json:"operationName"` } // DataMessagePayload defines the result data of an operation. type DataMessagePayload struct { - Data interface{} `json:"data"` - Errors []error `json:"errors"` + Data any `json:"data"` + Errors []error `json:"errors"` } // OperationMessage represents a GraphQL WebSocket message. type OperationMessage struct { - ID string `json:"id"` - Type string `json:"type"` - Payload interface{} `json:"payload"` + ID string `json:"id"` + Type string `json:"type"` + Payload any `json:"payload"` } func (msg OperationMessage) String() string { @@ -72,7 +72,7 @@ func (msg OperationMessage) String() string { // AuthenticateFunc is a function that resolves an auth token // into a user (or returns an error if that isn't possible). -type AuthenticateFunc func(data map[string]interface{}, conn Connection) (context.Context, error) +type AuthenticateFunc func(data map[string]any, conn Connection) (context.Context, error) // ConnectionEventHandlers define the event handlers for a connection. // Event handlers allow other system components to react to events such @@ -283,7 +283,7 @@ func (conn *connection) readLoop() { switch msg.Type { case gqlConnectionAuth: - data := map[string]interface{}{} + data := map[string]any{} if err := json.Unmarshal(rawPayload, &data); err != nil { conn.logger.Errorf("Invalid %s data: %v", msg.Type, err) conn.SendError(errors.New("invalid GQL_CONNECTION_AUTH payload")) @@ -302,7 +302,7 @@ func (conn *connection) readLoop() { // When the GraphQL WS connection is initiated, send an ACK back case gqlConnectionInit: - data := map[string]interface{}{} + data := map[string]any{} if err := json.Unmarshal(rawPayload, &data); err != nil { conn.logger.Errorf("Invalid %s data: %v", msg.Type, err) conn.SendError(errors.New("invalid GQL_CONNECTION_INIT payload")) diff --git a/server/handler.go b/server/handler.go index 5f0bf2a..f0c2e3c 100644 --- a/server/handler.go +++ b/server/handler.go @@ -15,9 +15,9 @@ import ( // RequestOptions options type RequestOptions struct { - Query string `json:"query" url:"query" schema:"query"` - Variables map[string]interface{} `json:"variables" url:"variables" schema:"variables"` - OperationName string `json:"operationName" url:"operationName" schema:"operationName"` + Query string `json:"query" url:"query" schema:"query"` + Variables map[string]any `json:"variables" url:"variables" schema:"variables"` + OperationName string `json:"operationName" url:"operationName" schema:"operationName"` } // a workaround for getting`variables` as a JSON string @@ -31,7 +31,7 @@ func getFromForm(values url.Values) *RequestOptions { query := values.Get("query") if query != "" { // get variables map - variables := make(map[string]interface{}, len(values)) + variables := make(map[string]any, len(values)) variablesStr := values.Get("variables") json.Unmarshal([]byte(variablesStr), &variables) diff --git a/server/logger/logger.go b/server/logger/logger.go index 3196c0a..531c024 100644 --- a/server/logger/logger.go +++ b/server/logger/logger.go @@ -1,15 +1,15 @@ package logger type Logger interface { - Infof(format string, data ...interface{}) - Debugf(format string, data ...interface{}) - Errorf(format string, data ...interface{}) - Warnf(format string, data ...interface{}) + Infof(format string, data ...any) + Debugf(format string, data ...any) + Errorf(format string, data ...any) + Warnf(format string, data ...any) } type NoopLogger struct{} -func (n *NoopLogger) Infof(format string, data ...interface{}) {} -func (n *NoopLogger) Debugf(format string, data ...interface{}) {} -func (n *NoopLogger) Errorf(format string, data ...interface{}) {} -func (n *NoopLogger) Warnf(format string, data ...interface{}) {} +func (n *NoopLogger) Infof(format string, data ...any) {} +func (n *NoopLogger) Debugf(format string, data ...any) {} +func (n *NoopLogger) Errorf(format string, data ...any) {} +func (n *NoopLogger) Warnf(format string, data ...any) {} diff --git a/server/server.go b/server/server.go index 91bf027..bca0475 100644 --- a/server/server.go +++ b/server/server.go @@ -20,7 +20,7 @@ const ( ) // ConnKey the connection key -var ConnKey interface{} = "conn" +var ConnKey any = "conn" type Server struct { schema graphql.Schema @@ -49,7 +49,7 @@ func New(schema graphql.Schema, options *Options) *Server { } } -type RootValueFunc func(ctx context.Context, r *http.Request) map[string]interface{} +type RootValueFunc func(ctx context.Context, r *http.Request) map[string]any type FormatErrorFunc func(err error) gqlerrors.FormattedError diff --git a/typedefs_test.go b/typedefs_test.go index b8565fe..b262206 100644 --- a/typedefs_test.go +++ b/typedefs_test.go @@ -79,7 +79,7 @@ func TestObjectIsTypeOf(t *testing.T) { foo: Foo }`, }, - Resolvers: map[string]interface{}{ + Resolvers: map[string]any{ "A": &ObjectResolver{ IsTypeOf: func(p graphql.IsTypeOfParams) bool { return true @@ -138,7 +138,7 @@ func TestUnionResolveType(t *testing.T) { foo: Foo }`, }, - Resolvers: map[string]interface{}{ + Resolvers: map[string]any{ "Foo": &UnionResolver{ ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object { return p.Info.Schema.TypeMap()["A"].(*graphql.Object) diff --git a/types.go b/types.go index efea432..622deac 100644 --- a/types.go +++ b/types.go @@ -67,7 +67,7 @@ func (c *registry) buildEnumFromAST(definition *ast.EnumDefinition) error { // builds an enum value from an ast func (c *registry) buildEnumValueFromAST(definition *ast.EnumValueDefinition, enumName string) (*graphql.EnumValueConfig, error) { - var value interface{} + var value any value = definition.Name.Value if r := c.getResolver(enumName); r != nil && r.getKind() == kinds.EnumDefinition { @@ -94,7 +94,7 @@ func (c *registry) buildEnumValueFromAST(definition *ast.EnumValueDefinition, en // builds an input from ast func (c *registry) buildInputObjectFromAST(definition *ast.InputObjectDefinition) error { - var fields interface{} + var fields any name := definition.Name.Value inputConfig := graphql.InputObjectConfig{ Name: name, diff --git a/values.go b/values.go index 2672608..3b9c87b 100644 --- a/values.go +++ b/values.go @@ -15,7 +15,7 @@ import ( // Prepares an object map of argument values given a list of argument // definitions and list of argument AST nodes. -func GetArgumentValues(argDefs []*graphql.Argument, argASTs []*ast.Argument, variableVariables map[string]interface{}) (map[string]interface{}, error) { +func GetArgumentValues(argDefs []*graphql.Argument, argASTs []*ast.Argument, variableVariables map[string]any) (map[string]any, error) { argASTMap := map[string]*ast.Argument{} for _, argAST := range argASTs { @@ -23,7 +23,7 @@ func GetArgumentValues(argDefs []*graphql.Argument, argASTs []*ast.Argument, var argASTMap[argAST.Name.Value] = argAST } } - results := map[string]interface{}{} + results := map[string]any{} for _, argDef := range argDefs { name := argDef.PrivateName @@ -53,7 +53,7 @@ func GetArgumentValues(argDefs []*graphql.Argument, argASTs []*ast.Argument, var } // Returns true if a value is null, undefined, or NaN. -func isNullish(src interface{}) bool { +func isNullish(src any) bool { if src == nil { return true }