Skip to content

Commit

Permalink
interface{} -> any
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed Sep 19, 2023
1 parent 32c52f3 commit af21a3f
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 139 deletions.
22 changes: 11 additions & 11 deletions dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
28 changes: 14 additions & 14 deletions directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ type VisitSchemaParams struct {
Context context.Context
Config *graphql.SchemaConfig
Node *ast.SchemaDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitScalarParams params
type VisitScalarParams struct {
Context context.Context
Config *graphql.ScalarConfig
Node *ast.ScalarDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitObjectParams params
Expand All @@ -58,15 +58,15 @@ type VisitObjectParams struct {
Config *graphql.ObjectConfig
Node *ast.ObjectDefinition
Extensions []*ast.ObjectDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitFieldDefinitionParams params
type VisitFieldDefinitionParams struct {
Context context.Context
Config *graphql.Field
Node *ast.FieldDefinition
Args map[string]interface{}
Args map[string]any
ParentName string
ParentKind string
}
Expand All @@ -76,55 +76,55 @@ type VisitArgumentDefinitionParams struct {
Context context.Context
Config *graphql.ArgumentConfig
Node *ast.InputValueDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitInterfaceParams params
type VisitInterfaceParams struct {
Context context.Context
Config *graphql.InterfaceConfig
Node *ast.InterfaceDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitUnionParams params
type VisitUnionParams struct {
Context context.Context
Config *graphql.UnionConfig
Node *ast.UnionDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitEnumParams params
type VisitEnumParams struct {
Context context.Context
Config *graphql.EnumConfig
Node *ast.EnumDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitEnumValueParams params
type VisitEnumValueParams struct {
Context context.Context
Config *graphql.EnumValueConfig
Node *ast.EnumValueDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitInputObjectParams params
type VisitInputObjectParams struct {
Context context.Context
Config *graphql.InputObjectConfig
Node *ast.InputObjectDefinition
Args map[string]interface{}
Args map[string]any
}

// VisitInputFieldDefinitionParams params
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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions directives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Query {
`

// create some data
foos := []map[string]interface{}{
foos := []map[string]any{
{
"name": "foo",
"description": "a foo",
Expand All @@ -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
},
},
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions graphqlws/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down
16 changes: 8 additions & 8 deletions graphqlws/logger.go
Original file line number Diff line number Diff line change
@@ -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) {}
4 changes: 2 additions & 2 deletions graphqlws/wshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit af21a3f

Please sign in to comment.