|
1 | 1 | # frozen_string_literal: true
|
2 | 2 | require "spec_helper"
|
| 3 | +require_relative "../subscriptions_spec" |
3 | 4 |
|
4 | 5 | describe GraphQL::Execution::Interpreter do
|
5 | 6 | module InterpreterTest
|
@@ -547,6 +548,66 @@ def self.resolve_type(type, obj, ctx)
|
547 | 548 | end
|
548 | 549 | end
|
549 | 550 |
|
| 551 | + describe "Lazy skips" do |
| 552 | + class LazySkipSchema < GraphQL::Schema |
| 553 | + class Query < GraphQL::Schema::Object |
| 554 | + def self.authorized?(obj, ctx) |
| 555 | + -> { true } |
| 556 | + end |
| 557 | + field :skip, String, null: true |
| 558 | + |
| 559 | + def skip |
| 560 | + context.skip |
| 561 | + end |
| 562 | + |
| 563 | + field :lazy_skip, String, null: true |
| 564 | + def lazy_skip |
| 565 | + -> { context.skip } |
| 566 | + end |
| 567 | + end |
| 568 | + |
| 569 | + class NothingSubscription < GraphQL::Schema::Subscription |
| 570 | + field :nothing, String, null: true |
| 571 | + def authorized?(*) |
| 572 | + -> { true } |
| 573 | + end |
| 574 | + |
| 575 | + def update |
| 576 | + { nothing: object } |
| 577 | + end |
| 578 | + end |
| 579 | + |
| 580 | + class Subscription < GraphQL::Schema::Object |
| 581 | + field :nothing, subscription: NothingSubscription |
| 582 | + end |
| 583 | + |
| 584 | + query Query |
| 585 | + subscription Subscription |
| 586 | + use InMemoryBackend::Subscriptions, extra: nil |
| 587 | + lazy_resolve Proc, :call |
| 588 | + end |
| 589 | + |
| 590 | + focus |
| 591 | + it "skips properly" do |
| 592 | + res = LazySkipSchema.execute("{ skip }") |
| 593 | + assert_equal({}, res["data"]) |
| 594 | + refute res.key?("errors") |
| 595 | + # This failed on 1.12.10, too |
| 596 | + # res = LazySkipSchema.execute("{ lazySkip }") |
| 597 | + # pp res |
| 598 | + # assert_equal({}, res["data"]) |
| 599 | + # refute res.key?("errors") |
| 600 | + |
| 601 | + res = LazySkipSchema.execute("subscription { nothing { nothing } }") |
| 602 | + pp res |
| 603 | + assert_equal({}, res["data"]) |
| 604 | + refute res.key?("errors") |
| 605 | + LazySkipSchema.subscriptions.trigger(:nothing, {}, :nothing_at_all) |
| 606 | + key, updates = LazySkipSchema.subscriptions.deliveries.first |
| 607 | + assert_equal "nothing_at_all", updates[0]["data"]["nothing"]["nothing"] |
| 608 | + end |
| 609 | + end |
| 610 | + |
550 | 611 | describe "GraphQL::ExecutionErrors from non-null list fields" do
|
551 | 612 | module ListErrorTest
|
552 | 613 | class BaseField < GraphQL::Schema::Field
|
|
0 commit comments