Sha256: 7d05a2d997c28cae97777df71a19395b0fcdb625650680f1816c0089b15ccc72

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 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) }

  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}]
      },
      {
        "message"=>"Invalid fragment on type DairyProductInput (must be Union, Interface or Object)",
        "locations"=>[{"line"=>14, "column"=>9}],
      },
      {
        "message"=>"Invalid fragment on type Int (must be Union, Interface or Object)",
        "locations"=>[{"line"=>20, "column"=>5}]
      },
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-0.15.3 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.15.2 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.14.2 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.15.1 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.15.0 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.14.1 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.14.0 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
graphql-0.13.0 spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb