summaryrefslogtreecommitdiff
path: root/spec/support_specs/graphql/field_selection_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support_specs/graphql/field_selection_spec.rb')
-rw-r--r--spec/support_specs/graphql/field_selection_spec.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/support_specs/graphql/field_selection_spec.rb b/spec/support_specs/graphql/field_selection_spec.rb
new file mode 100644
index 00000000000..8818e59e598
--- /dev/null
+++ b/spec/support_specs/graphql/field_selection_spec.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Graphql::FieldSelection do
+ it 'can report on the paths that are selected' do
+ selection = described_class.new({
+ 'foo' => nil,
+ 'bar' => nil,
+ 'quux' => {
+ 'a' => nil,
+ 'b' => { 'x' => nil, 'y' => nil }
+ },
+ 'qoox' => {
+ 'q' => nil,
+ 'r' => { 's' => { 't' => nil } }
+ }
+ })
+
+ expect(selection.paths).to include(
+ %w[foo],
+ %w[quux a],
+ %w[quux b x],
+ %w[qoox r s t]
+ )
+ end
+
+ it 'can serialize a field selection nicely' do
+ selection = described_class.new({
+ 'foo' => nil,
+ 'bar' => nil,
+ 'quux' => {
+ 'a' => nil,
+ 'b' => { 'x' => nil, 'y' => nil }
+ },
+ 'qoox' => {
+ 'q' => nil,
+ 'r' => { 's' => { 't' => nil } }
+ }
+ })
+
+ expect(selection.to_s).to eq(<<~FRAG.strip)
+ foo
+ bar
+ quux {
+ a
+ b {
+ x
+ y
+ }
+ }
+ qoox {
+ q
+ r {
+ s {
+ t
+ }
+ }
+ }
+ FRAG
+ end
+end