Sha256: eaf39132542aa2fec299f92735ef479bf659f6cca99f44713a0502b89816f3ee

Contents?: true

Size: 1.32 KB

Versions: 26

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Language::Parser do
  subject { GraphQL::Language::Parser }

  describe "anonymous fragment extension" do
    let(:document) { GraphQL.parse(query_string) }
    let(:query_string) {%|
      fragment on NestedType @or(something: "ok") {
        anotherNestedField
      }
    |}

    let(:fragment) { document.definitions.first }

    it "creates an anonymous fragment definition" do
      assert fragment.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
      assert_equal nil, fragment.name
      assert_equal 1, fragment.selections.length
      assert_equal "NestedType", fragment.type.name
      assert_equal 1, fragment.directives.length
      assert_equal [2, 7], fragment.position
    end
  end

  it "parses empty arguments" do
    strings = [
      "{ field { inner } }",
      "{ field() { inner }}",
    ]
    strings.each do |query_str|
      doc = subject.parse(query_str)
      field = doc.definitions.first.selections.first
      assert_equal 0, field.arguments.length
      assert_equal 1, field.selections.length
    end
  end

  it "parses the test schema" do
    schema = Dummy::Schema
    schema_string = GraphQL::Schema::Printer.print_schema(schema)
    document = subject.parse(schema_string)
    assert_equal schema_string, document.to_query_string
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
graphql-1.6.6 spec/graphql/language/parser_spec.rb
graphql-1.6.5 spec/graphql/language/parser_spec.rb
graphql-1.6.4 spec/graphql/language/parser_spec.rb
graphql-1.5.15 spec/graphql/language/parser_spec.rb
graphql-1.6.3 spec/graphql/language/parser_spec.rb
graphql-1.6.2 spec/graphql/language/parser_spec.rb
graphql-1.6.1 spec/graphql/language/parser_spec.rb
graphql-1.6.0 spec/graphql/language/parser_spec.rb
graphql-1.5.14 spec/graphql/language/parser_spec.rb
graphql-1.5.13 spec/graphql/language/parser_spec.rb
graphql-1.5.7.1 spec/graphql/language/parser_spec.rb
graphql-1.5.12 spec/graphql/language/parser_spec.rb
graphql-1.5.11 spec/graphql/language/parser_spec.rb
graphql-1.5.10 spec/graphql/language/parser_spec.rb
graphql-1.5.9 spec/graphql/language/parser_spec.rb
graphql-1.5.8 spec/graphql/language/parser_spec.rb
graphql-1.5.7 spec/graphql/language/parser_spec.rb
graphql-1.5.6 spec/graphql/language/parser_spec.rb
graphql-1.5.5 spec/graphql/language/parser_spec.rb
graphql-1.5.4 spec/graphql/language/parser_spec.rb