本文整理汇总了Golang中github.com/graphql-go/graphql/testutil.ExpectFailsRule函数的典型用法代码示例。如果您正苦于以下问题:Golang ExpectFailsRule函数的具体用法?Golang ExpectFailsRule怎么用?Golang ExpectFailsRule使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ExpectFailsRule函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectly
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectly(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragA on Dog { ...fragA }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Cannot spread fragment "fragA" within itself.`, 2, 31),
})
}
示例2: TestValidate_NoUndefinedVariables_VaMultipleUndefinedVariablesProduceMultipleErrors
func TestValidate_NoUndefinedVariables_VaMultipleUndefinedVariablesProduceMultipleErrors(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
query Foo($b: String) {
...FragAB
}
query Bar($a: String) {
...FragAB
}
fragment FragAB on Type {
field1(a: $a, b: $b)
...FragC
field3(a: $a, b: $b)
}
fragment FragC on Type {
field2(c: $c)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$a" is not defined by operation "Foo".`, 9, 19, 2, 7),
testutil.RuleError(`Variable "$c" is not defined by operation "Foo".`, 14, 19, 2, 7),
testutil.RuleError(`Variable "$a" is not defined by operation "Foo".`, 11, 19, 2, 7),
testutil.RuleError(`Variable "$b" is not defined by operation "Bar".`, 9, 26, 5, 7),
testutil.RuleError(`Variable "$c" is not defined by operation "Bar".`, 14, 19, 5, 7),
testutil.RuleError(`Variable "$b" is not defined by operation "Bar".`, 11, 26, 5, 7),
})
}
示例3: TestValidate_OverlappingFieldsCanBeMerged_VeryDeepConflict
func TestValidate_OverlappingFieldsCanBeMerged_VeryDeepConflict(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.OverlappingFieldsCanBeMergedRule, `
{
field {
deepField {
x: a
}
},
field {
deepField {
x: b
}
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(
`Fields "field" conflict because subfields "deepField" conflict because subfields "x" conflict because `+
`a and b are different fields.`,
3, 9,
4, 11,
5, 13,
8, 9,
9, 11,
10, 13),
})
}
示例4: 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),
})
}
示例5: 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),
})
}
示例6: TestValidate_OverlappingFieldsCanBeMerged_ReportsDeepConflictToNearestCommonAncestor
func TestValidate_OverlappingFieldsCanBeMerged_ReportsDeepConflictToNearestCommonAncestor(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.OverlappingFieldsCanBeMergedRule, `
{
field {
deepField {
x: a
}
deepField {
x: b
}
},
field {
deepField {
y
}
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(
`Fields "deepField" conflict because subfields "x" conflict because `+
`a and b are different fields.`,
4, 11,
5, 13,
7, 11,
8, 13),
})
}
示例7: TestValidate_NoCircularFragmentSpreads_SpreadingRecursivelyWithinFieldFails
func TestValidate_NoCircularFragmentSpreads_SpreadingRecursivelyWithinFieldFails(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragA on Human { relatives { ...fragA } },
`, []gqlerrors.FormattedError{
testutil.RuleError(`Cannot spread fragment "fragA" within itself.`, 2, 45),
})
}
示例8: 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),
})
}
示例9: TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfIndirectlyReportsOppositeOrder
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfIndirectlyReportsOppositeOrder(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragB on Dog { ...fragA }
fragment fragA on Dog { ...fragB }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Cannot spread fragment "fragB" within itself via fragA.`, 2, 31, 3, 31),
})
}
示例10: TestValidate_PossibleFragmentSpreads_ObjectIntoNotContainingUnion
func TestValidate_PossibleFragmentSpreads_ObjectIntoNotContainingUnion(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidObjectWithinUnion on CatOrDog { ...humanFragment }
fragment humanFragment on Human { pets { name } }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "humanFragment" cannot be spread here as objects of `+
`type "CatOrDog" can never be of type "Human".`, 2, 55),
})
}
示例11: TestValidate_PossibleFragmentSpreads_UnionIntoNotContainedObject
func TestValidate_PossibleFragmentSpreads_UnionIntoNotContainedObject(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidUnionWithinObject on Human { ...catOrDogFragment }
fragment catOrDogFragment on CatOrDog { __typename }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "catOrDogFragment" cannot be spread here as objects of `+
`type "Human" can never be of type "CatOrDog".`, 2, 52),
})
}
示例12: TestValidate_KnownArgumentNames_InvalidArgName
func TestValidate_KnownArgumentNames_InvalidArgName(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
fragment invalidArgName on Dog {
doesKnowCommand(unknown: true)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "unknown" on field "doesKnowCommand" of type "Dog".`, 3, 25),
})
}
示例13: TestValidate_NoUnusedVariables_VariableNotUsed
func TestValidate_NoUnusedVariables_VariableNotUsed(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUnusedVariablesRule, `
query ($a: String, $b: String, $c: String) {
field(a: $a, b: $b)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Variable "$c" is never used.`, 2, 38),
})
}
示例14: TestValidate_ScalarLeafs_ObjectTypeMissingSelection
func TestValidate_ScalarLeafs_ObjectTypeMissingSelection(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
query directQueryOnObjectWithoutSubFields {
human
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Field "human" of type "Human" must have a sub selection.`, 3, 9),
})
}
示例15: TestValidate_KnownArgumentNames_UndirectiveArgsAreInvalid
func TestValidate_KnownArgumentNames_UndirectiveArgsAreInvalid(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
{
dog @skip(unless: true)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "unless" on directive "@skip".`, 3, 19),
})
}