Sha256: 2fa00cb72db3096238e271bab151c56faf907ffe73febcb31e1145b4aecbdfcc

Contents?: true

Size: 1.53 KB

Versions: 15

Compression:

Stored size: 1.53 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::FragmentsAreOnCompositeTypes do
  let(:query_string) {%|
    query getCheese {
      cheese(id: 1) {
        ... on Cheese {
          source
          ... on Boolean {
            something
          }
        }
        ... intFields
        ... on DairyProduct {
          name
        }
        ... on DairyProductInput {
          something
        }
      }
    }

    fragment intFields on Int {
      something
    }
  |}

  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FragmentsAreOnCompositeTypes]) }
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
  let(:errors) { validator.validate(query)[:errors] }

  it "requires Object/Union/Interface fragment types" do
    expected = [
      {
        "message"=>"Invalid fragment on type Boolean (must be Union, Interface or Object)",
        "locations"=>[{"line"=>6, "column"=>11}],
        "path"=>["query getCheese", "cheese", "... on Cheese", "... on Boolean"],
      },
      {
        "message"=>"Invalid fragment on type DairyProductInput (must be Union, Interface or Object)",
        "locations"=>[{"line"=>14, "column"=>9}],
        "path"=>["query getCheese", "cheese", "... on DairyProductInput"],
      },
      {
        "message"=>"Invalid fragment on type Int (must be Union, Interface or Object)",
        "locations"=>[{"line"=>20, "column"=>5}],
        "path"=>["fragment intFields"],
      },
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
graphql-0.18.14 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.13 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.12 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.11 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.10 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.9 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.8 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.7 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.6 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.5 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.4 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.3 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.2 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.1 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.18.0 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb