本文整理汇总了Golang中github.com/graphql-go/graphql/testutil.RuleError函数的典型用法代码示例。如果您正苦于以下问题:Golang RuleError函数的具体用法?Golang RuleError怎么用?Golang RuleError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RuleError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestValidate_NoUnusedFragments_ContainsUnknownFragmentsWithRefCycle
func TestValidate_NoUnusedFragments_ContainsUnknownFragmentsWithRefCycle(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUnusedFragmentsRule, `
query Foo {
human(id: 4) {
...HumanFields1
}
}
query Bar {
human(id: 4) {
...HumanFields2
}
}
fragment HumanFields1 on Human {
name
...HumanFields3
}
fragment HumanFields2 on Human {
name
}
fragment HumanFields3 on Human {
name
}
fragment Unused1 on Human {
name
...Unused2
}
fragment Unused2 on Human {
name
...Unused1
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "Unused1" is never used.`, 22, 7),
testutil.RuleError(`Fragment "Unused2" is never used.`, 26, 7),
})
}
示例2: TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDeeply
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDeeply(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragA on Dog { ...fragB }
fragment fragB on Dog { ...fragC }
fragment fragC on Dog { ...fragO }
fragment fragX on Dog { ...fragY }
fragment fragY on Dog { ...fragZ }
fragment fragZ on Dog { ...fragO }
fragment fragO on Dog { ...fragP }
fragment fragP on Dog { ...fragA, ...fragX }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Cannot spread fragment "fragA" within itself via fragB, fragC, fragO, fragP.`,
2, 31,
3, 31,
4, 31,
8, 31,
9, 31),
testutil.RuleError(`Cannot spread fragment "fragO" within itself via fragP, fragX, fragY, fragZ.`,
8, 31,
9, 41,
5, 31,
6, 31,
7, 31),
})
}
示例3: TestValidate_OverlappingFieldsCanBeMerged_ReportsEachConflictOnce
func TestValidate_OverlappingFieldsCanBeMerged_ReportsEachConflictOnce(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.OverlappingFieldsCanBeMergedRule, `
{
f1 {
...A
...B
}
f2 {
...B
...A
}
f3 {
...A
...B
x: c
}
}
fragment A on Type {
x: a
}
fragment B on Type {
x: b
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fields "x" conflict because a and b are different fields.`, 18, 9, 21, 9),
testutil.RuleError(`Fields "x" conflict because a and c are different fields.`, 18, 9, 14, 11),
testutil.RuleError(`Fields "x" conflict because b and c are different fields.`, 21, 9, 14, 11),
})
}
示例4: TestValidate_NoUndefinedVariables_MultipleVariablesNotDefined
func TestValidate_NoUndefinedVariables_MultipleVariablesNotDefined(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
query Foo($b: String) {
field(a: $a, b: $b, c: $c)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$a" is not defined by operation "Foo".`, 3, 18, 2, 7),
testutil.RuleError(`Variable "$c" is not defined by operation "Foo".`, 3, 32, 2, 7),
})
}
示例5: TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDeeplyTwoPaths
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDeeplyTwoPaths(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragA on Dog { ...fragB, ...fragC }
fragment fragB on Dog { ...fragA }
fragment fragC on Dog { ...fragA }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Cannot spread fragment "fragA" within itself via fragB.`, 2, 31, 3, 31),
testutil.RuleError(`Cannot spread fragment "fragA" within itself via fragC.`, 2, 41, 4, 31),
})
}
示例6: TestValidate_NoUnusedVariables_MultipleVariablesNotUsed
func TestValidate_NoUnusedVariables_MultipleVariablesNotUsed(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUnusedVariablesRule, `
query Foo($a: String, $b: String, $c: String) {
field(b: $b)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$a" is never used in operation "Foo".`, 2, 17),
testutil.RuleError(`Variable "$c" is never used in operation "Foo".`, 2, 41),
})
}
示例7: TestValidate_KnownArgumentNames_UnknownArgsAmongstKnownArgs
func TestValidate_KnownArgumentNames_UnknownArgsAmongstKnownArgs(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
fragment oneGoodArgOneInvalidArg on Dog {
doesKnowCommand(whoknows: 1, dogCommand: SIT, unknown: true)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "whoknows" on field "doesKnowCommand" of type "Dog".`, 3, 25),
testutil.RuleError(`Unknown argument "unknown" on field "doesKnowCommand" of type "Dog".`, 3, 55),
})
}
示例8: TestValidate_UniqueArgumentNames_ManyDuplicateFieldArguments
func TestValidate_UniqueArgumentNames_ManyDuplicateFieldArguments(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueArgumentNamesRule, `
{
field(arg1: "value", arg1: "value", arg1: "value")
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can be only one argument named "arg1".`, 3, 15, 3, 30),
testutil.RuleError(`There can be only one argument named "arg1".`, 3, 15, 3, 45),
})
}
示例9: TestValidate_UniqueInputFieldNames_ManyDuplicateInputObjectFields
func TestValidate_UniqueInputFieldNames_ManyDuplicateInputObjectFields(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueInputFieldNamesRule, `
{
field(arg: { f1: "value", f1: "value", f1: "value" })
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can be only one input field named "f1".`, 3, 22, 3, 35),
testutil.RuleError(`There can be only one input field named "f1".`, 3, 22, 3, 48),
})
}
示例10: TestValidate_VariablesAreInputTypes_1
func TestValidate_VariablesAreInputTypes_1(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.VariablesAreInputTypesRule, `
query Foo($a: Dog, $b: [[CatOrDog!]]!, $c: Pet) {
field(a: $a, b: $b, c: $c)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$a" cannot be non-input type "Dog".`, 2, 21),
testutil.RuleError(`Variable "$b" cannot be non-input type "[[CatOrDog!]]!".`, 2, 30),
testutil.RuleError(`Variable "$c" cannot be non-input type "Pet".`, 2, 50),
})
}
示例11: TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingMultipleNonNullableArguments
func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingMultipleNonNullableArguments(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
{
complicatedArgs {
multipleReqs
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Field "multipleReqs" argument "req1" of type "Int!" is required but not provided.`, 4, 13),
testutil.RuleError(`Field "multipleReqs" argument "req2" of type "Int!" is required but not provided.`, 4, 13),
})
}
示例12: TestValidate_ProvidedNonNullArguments_DirectiveArguments_WithDirectiveWithMissingTypes
func TestValidate_ProvidedNonNullArguments_DirectiveArguments_WithDirectiveWithMissingTypes(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
{
dog @include {
name @skip
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Directive "@include" argument "if" of type "Boolean!" is required but not provided.`, 3, 15),
testutil.RuleError(`Directive "@skip" argument "if" of type "Boolean!" is required but not provided.`, 4, 18),
})
}
示例13: TestValidate_KnownDirectives_WithMisplacedDirectives
func TestValidate_KnownDirectives_WithMisplacedDirectives(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownDirectivesRule, `
query Foo @include(if: true) {
name @operationOnly
...Frag @operationOnly
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Directive "include" may not be used on QUERY.`, 2, 17),
testutil.RuleError(`Directive "operationOnly" may not be used on FIELD.`, 3, 14),
testutil.RuleError(`Directive "operationOnly" may not be used on FRAGMENT_SPREAD.`, 4, 17),
})
}
示例14: TestValidate_UniqueVariableNames_DuplicateVariableNames
func TestValidate_UniqueVariableNames_DuplicateVariableNames(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueVariableNamesRule, `
query A($x: Int, $x: Int, $x: String) { __typename }
query B($x: String, $x: Int) { __typename }
query C($x: Int, $x: Int) { __typename }
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can only be one variable named "x".`, 2, 16, 2, 25),
testutil.RuleError(`There can only be one variable named "x".`, 2, 16, 2, 34),
testutil.RuleError(`There can only be one variable named "x".`, 3, 16, 3, 28),
testutil.RuleError(`There can only be one variable named "x".`, 4, 16, 4, 25),
})
}
示例15: TestValidate_AnonymousOperationMustBeAlone_MultipleAnonOperations
func TestValidate_AnonymousOperationMustBeAlone_MultipleAnonOperations(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.LoneAnonymousOperationRule, `
{
fieldA
}
{
fieldB
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`This anonymous operation must be the only defined operation.`, 2, 7),
testutil.RuleError(`This anonymous operation must be the only defined operation.`, 5, 7),
})
}