1 Star 0 Fork 0

麦冬果果/graphql-go

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rules_variables_in_allowed_position_test.go 8.03 KB
一键复制 编辑 原始数据 按行查看 历史
Hafiz Ismail 提交于 2016-04-12 13:55 +08:00 . Fix typo in unit test, closes #269
package graphql_test
import (
"testing"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/testutil"
)
func TestValidate_VariablesInAllowedPosition_BooleanToBoolean(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($booleanArg: Boolean)
{
complicatedArgs {
booleanArgField(booleanArg: $booleanArg)
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_BooleanToBooleanWithinFragment(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
fragment booleanArgFrag on ComplicatedArgs {
booleanArgField(booleanArg: $booleanArg)
}
query Query($booleanArg: Boolean)
{
complicatedArgs {
...booleanArgFrag
}
}
`)
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($booleanArg: Boolean)
{
complicatedArgs {
...booleanArgFrag
}
}
fragment booleanArgFrag on ComplicatedArgs {
booleanArgField(booleanArg: $booleanArg)
}
`)
}
func TestValidate_VariablesInAllowedPosition_NonNullableBooleanToBoolean(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($nonNullBooleanArg: Boolean!)
{
complicatedArgs {
booleanArgField(booleanArg: $nonNullBooleanArg)
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_NonNullableBooleanToBooleanWithinFragment(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
fragment booleanArgFrag on ComplicatedArgs {
booleanArgField(booleanArg: $nonNullBooleanArg)
}
query Query($nonNullBooleanArg: Boolean!)
{
complicatedArgs {
...booleanArgFrag
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_IntToNonNullableIntWithDefault(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($intArg: Int = 1)
{
complicatedArgs {
nonNullIntArgField(nonNullIntArg: $intArg)
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_ListOfStringToListOfString(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($stringListVar: [String])
{
complicatedArgs {
stringListArgField(stringListArg: $stringListVar)
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_ListOfNonNullableStringToListOfString(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($stringListVar: [String!])
{
complicatedArgs {
stringListArgField(stringListArg: $stringListVar)
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_StringToListOfStringInItemPosition(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($stringVar: String)
{
complicatedArgs {
stringListArgField(stringListArg: [$stringVar])
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_NonNullableStringToListOfStringInItemPosition(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($stringVar: String!)
{
complicatedArgs {
stringListArgField(stringListArg: [$stringVar])
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_ComplexInputToComplexInput(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($complexVar: ComplexInput)
{
complicatedArgs {
complexArgField(complexArg: $complexVar)
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_ComplexInputToComplexInputInFieldPosition(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($boolVar: Boolean = false)
{
complicatedArgs {
complexArgField(complexArg: {requiredArg: $boolVar})
}
}
`)
}
func TestValidate_VariablesInAllowedPosition_NonNullableBooleanToNonNullableBooleanInDirective(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($boolVar: Boolean!)
{
dog @include(if: $boolVar)
}
`)
}
func TestValidate_VariablesInAllowedPosition_NonNullableBooleanToNonNullableBooleanInDirectiveInDirectiveWithDefault(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($boolVar: Boolean = false)
{
dog @include(if: $boolVar)
}
`)
}
func TestValidate_VariablesInAllowedPosition_IntToNonNullableInt(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($intArg: Int) {
complicatedArgs {
nonNullIntArgField(nonNullIntArg: $intArg)
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$intArg" of type "Int" used in position `+
`expecting type "Int!".`, 2, 19, 4, 45),
})
}
func TestValidate_VariablesInAllowedPosition_IntToNonNullableIntWithinFragment(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.VariablesInAllowedPositionRule, `
fragment nonNullIntArgFieldFrag on ComplicatedArgs {
nonNullIntArgField(nonNullIntArg: $intArg)
}
query Query($intArg: Int) {
complicatedArgs {
...nonNullIntArgFieldFrag
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$intArg" of type "Int" used in position `+
`expecting type "Int!".`, 6, 19, 3, 43),
})
}
func TestValidate_VariablesInAllowedPosition_IntToNonNullableIntWithinNestedFragment(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.VariablesInAllowedPositionRule, `
fragment outerFrag on ComplicatedArgs {
...nonNullIntArgFieldFrag
}
fragment nonNullIntArgFieldFrag on ComplicatedArgs {
nonNullIntArgField(nonNullIntArg: $intArg)
}
query Query($intArg: Int) {
complicatedArgs {
...outerFrag
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$intArg" of type "Int" used in position `+
`expecting type "Int!".`, 10, 19, 7, 43),
})
}
func TestValidate_VariablesInAllowedPosition_StringOverBoolean(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($stringVar: String) {
complicatedArgs {
booleanArgField(booleanArg: $stringVar)
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$stringVar" of type "String" used in position `+
`expecting type "Boolean".`, 2, 19, 4, 39),
})
}
func TestValidate_VariablesInAllowedPosition_StringToListOfString(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($stringVar: String) {
complicatedArgs {
stringListArgField(stringListArg: $stringVar)
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$stringVar" of type "String" used in position `+
`expecting type "[String]".`, 2, 19, 4, 45),
})
}
func TestValidate_VariablesInAllowedPosition_BooleanToNonNullableBooleanInDirective(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($boolVar: Boolean) {
dog @include(if: $boolVar)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$boolVar" of type "Boolean" used in position `+
`expecting type "Boolean!".`, 2, 19, 3, 26),
})
}
func TestValidate_VariablesInAllowedPosition_StringToNonNullableBooleanInDirective(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.VariablesInAllowedPositionRule, `
query Query($stringVar: String) {
dog @include(if: $stringVar)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$stringVar" of type "String" used in position `+
`expecting type "Boolean!".`, 2, 19, 3, 26),
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mdgg0816/graphql-go.git
git@gitee.com:mdgg0816/graphql-go.git
mdgg0816
graphql-go
graphql-go
v0.7.6

搜索帮助