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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
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),
	})
}
func TestValidate_NoUndefinedVariables_VariableNotDefined(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
      query Foo($a: String, $b: String, $c: String) {
        field(a: $a, b: $b, c: $c, d: $d)
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Variable "$d" is not defined by operation "Foo".`, 3, 39, 2, 7),
	})
}
func TestValidate_ScalarLeafs_ScalarSelectionNotAllowedWithDirectivesAndArgs(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
      fragment scalarSelectionsNotAllowedWithDirectivesAndArgs on Dog {
        doesKnowCommand(dogCommand: SIT) @include(if: true) { sinceWhen }
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Field "doesKnowCommand" of type "Boolean" must not have a sub selection.`, 3, 61),
	})
}
func TestValidate_PossibleFragmentSpreads_ObjectIntoNotImplementingInterface(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
      fragment invalidObjectWithinInterface on Pet { ...humanFragment }
      fragment humanFragment on Human { pets { name } }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Fragment "humanFragment" cannot be spread here as objects of `+
			`type "Pet" can never be of type "Human".`, 2, 54),
	})
}
func TestValidate_ScalarLeafs_InterfaceTypeMissingSelection(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
      {
        human { pets }
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Field "pets" of type "[Pet]" must have a sub selection.`, 3, 17),
	})
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoNonOverlappingUnion(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
      fragment invalidInterfaceWithinUnion on HumanOrAlien { ...petFragment }
      fragment petFragment on Pet { name }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Fragment "petFragment" cannot be spread here as objects of `+
			`type "HumanOrAlien" can never be of type "Pet".`, 2, 62),
	})
}
func TestValidate_ScalarLeafs_ScalarSelectionNotAllowedOnBoolean(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
      fragment scalarSelectionsNotAllowedOnBoolean on Dog {
        barks { sinceWhen }
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Field "barks" of type "Boolean" must not have a sub selection.`, 3, 15),
	})
}
func TestValidate_ScalarLeafs_ScalarSelectionNotAllowedOnEnum(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
      fragment scalarSelectionsNotAllowedOnEnum on Cat {
        furColor { inHexdec }
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Field "furColor" of type "FurColor" must not have a sub selection.`, 3, 18),
	})
}
func TestValidate_PossibleFragmentSpreads_UnionIntoNonOverlappingUnion(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
      fragment invalidUnionWithinUnion on CatOrDog { ...humanOrAlienFragment }
      fragment humanOrAlienFragment on HumanOrAlien { __typename }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Fragment "humanOrAlienFragment" cannot be spread here as objects of `+
			`type "CatOrDog" can never be of type "HumanOrAlien".`, 2, 54),
	})
}
func TestValidate_NoUndefinedVariables_VariableNotDefinedByUnnamedQuery(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
      {
        field(a: $a)
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Variable "$a" is not defined.`, 3, 18, 2, 7),
	})
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoNonImplementingObject(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
      fragment invalidInterfaceWithinObject on Cat { ...intelligentFragment }
      fragment intelligentFragment on Intelligent { iq }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Fragment "intelligentFragment" cannot be spread here as objects of `+
			`type "Cat" can never be of type "Intelligent".`, 2, 54),
	})
}
func TestValidate_ScalarLeafs_ScalarSelectionNotAllowedWithDirectives(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
      fragment scalarSelectionsNotAllowedWithDirectives on Dog {
        name @include(if: true) { isAlsoHumanName }
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Field "name" of type "String" must not have a sub selection.`, 3, 33),
	})
}
func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObject(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
      fragment invalidObjectWithinObject on Cat { ...dogFragment }
      fragment dogFragment on Dog { barkVolume }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Fragment "dogFragment" cannot be spread here as objects of `+
			`type "Cat" can never be of type "Dog".`, 2, 51),
	})
}
func TestValidate_FragmentsOnCompositeTypes_EnumIsInvalidFragmentType(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.FragmentsOnCompositeTypesRule, `
      fragment scalarFragment on FurColor {
        bad
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Fragment "scalarFragment" cannot condition on non composite type "FurColor".`, 2, 34),
	})
}
func TestValidate_UniqueArgumentNames_DuplicateDirectiveArguments(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.UniqueArgumentNamesRule, `
      {
        field @directive(arg1: "value", arg1: "value")
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`There can be only one argument named "arg1".`, 3, 26, 3, 41),
	})
}
func TestValidate_FragmentsOnCompositeTypes_InputObjectIsInvalidFragmentType(t *testing.T) {
	testutil.ExpectFailsRule(t, graphql.FragmentsOnCompositeTypesRule, `
      fragment inputFragment on ComplexInput {
        stringField
      }
    `, []gqlerrors.FormattedError{
		testutil.RuleError(`Fragment "inputFragment" cannot condition on non composite type "ComplexInput".`, 2, 33),
	})
}