Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rules_variables_in_allowed_position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,13 @@ func TestValidate_VariablesInAllowedPosition_StringToNonNullableBooleanInDirecti
`expecting type "Boolean!".`, 2, 19, 3, 26),
})
}
func TestValidate_VariablesInAllowedPosition_IntToNonNullableIntArgDefaulted(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($intArg: Int)
{
complicatedArgs {
nonNullIntArgFieldWithDefault(nonNullIntArgWithDefault: $intArg)
}
}
`)
}
9 changes: 9 additions & 0 deletions testutil/rules_test_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ func init() {
},
},
},
"nonNullIntArgFieldWithDefault": &graphql.Field{
Type: graphql.String,
Args: graphql.FieldConfigArgument{
"nonNullIntArgWithDefault": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.Int),
DefaultValue: 1,
},
},
},
"stringArgField": &graphql.Field{
Type: graphql.String,
Args: graphql.FieldConfigArgument{
Expand Down
6 changes: 5 additions & 1 deletion validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ func (ctx *ValidationContext) VariableUsages(node HasSelectionSet) []*VariableUs
kinds.Variable: {
Kind: func(p visitor.VisitFuncParams) (string, interface{}) {
if node, ok := p.Node.(*ast.Variable); ok && node != nil {
inputType := typeInfo.InputType()
if nonNull, ok := inputType.(*NonNull); ok && typeInfo.argument != nil && typeInfo.argument.DefaultValue != nil {
inputType = nonNull.OfType
}
usages = append(usages, &VariableUsage{
Node: node,
Type: typeInfo.InputType(),
Type: inputType,
})
}
return visitor.ActionNoChange, nil
Expand Down