graphql-go / graphql-go/graphql

[Q] Is type assertion check needed for resolver params?

Open
#564 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

Type cast code: https://github.com/graphql-go/graphql/blob/master/examples/todo/main.go#L156

```go
idQuery, isOK := params.Args["id"].(string)
```
args for type: https://github.com/graphql-go/graphql/blob/master/examples/todo/main.go#L149
```go
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.String,
},
},
```

Since the arguments validation is done in GraphQL schema layer.The `id` parameter must be a string type in resolver.
So I think it's unnecessary to check `isOk` variable. Am I correct?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.