graphql
graphql copied to clipboard
[Q] Is type assertion check needed for resolver params?
Type cast code: https://github.com/graphql-go/graphql/blob/master/examples/todo/main.go#L156
idQuery, isOK := params.Args["id"].(string)
args for type: https://github.com/graphql-go/graphql/blob/master/examples/todo/main.go#L149
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?
In this specific case, since the id
argument could be null, isOk
can be either true or false. But if you specify the argument's type as String!
, which is a non null string type, you'll be right and isOk
should be always true.
@Fontinalis Thanks. So I am thinking can this package can do this type assertion based on GraphQL fields' type for developer. So we don't need write this thing again and again.