Skip to content

Panic when using interfaces: Field homePlanet not found on type Some("Droid") #815

Closed
@LukasKalbertodt

Description

@LukasKalbertodt

Reproducing

Using the current master (4ffd276). I am using the example from the docs of graphql_interface:

use juniper::{graphql_interface, GraphQLObject};

#[graphql_interface(for = [Human, Droid])] // enumerating all implementers is mandatory
trait Character {
    fn id(&self) -> &str;
}

#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)] // notice the enum type name, not trait name
struct Human {
    id: String,
    home_planet: String,
}
#[graphql_interface]
impl Character for Human {
    fn id(&self) -> &str {
        &self.id
    }
}

#[derive(GraphQLObject)]
#[graphql(impl = [CharacterValue])]
struct Droid {
    id: String,
    primary_function: String,
}
#[graphql_interface]
impl Character for Droid {
    fn id(&self) -> &str {
        &self.id
    }
}

On my root query type I have a simple dummy resolver:

#[graphql_object(Context = Context)]
impl Query {
    fn characters() -> Vec<CharacterValue> {
        vec![
            Human { id: "3".into(), home_planet: "banana".into() }.into(),
            Droid { id: "7".into(), primary_function: "nope".into() }.into(),
        ]
    }
}

The generated schema is as expected. When running this query:

query {
  characters { id }
}

... everything works nicely. I get {"data": {"characters": [{"id": "3"}, {"id": "7"} ] } } back. However, when I query like this:

query {
  characters {
    id,
    ... on Human {
      homePlanet,
    }
  }
}

This causes a panic! Specifically:

thread 'tokio-runtime-worker' panicked at 'Field homePlanet not found on type Some("Droid")', /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:234:21

Stacktrace in my application:
stack backtrace:
   0: std::panicking::begin_panic
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:505
   1: juniper::types::async_await::resolve_selection_set_into_async_recursive::{{closure}}::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:234
   2: core::option::Option<T>::unwrap_or_else
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:424
   3: juniper::types::async_await::resolve_selection_set_into_async_recursive::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:233
   4: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
   5: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
   6: juniper::types::async_await::GraphQLValueAsync::resolve_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:104
   7: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
   8: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
   9: juniper::executor::Executor<CtxT,S>::resolve_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:468
  10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  11: juniper::executor::Executor<CtxT,S>::resolve_with_ctx_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:486
  12: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  13: <test::CharacterValue as juniper::types::async_await::GraphQLValueAsync<__S>>::resolve_into_type_async::{{closure}}::{{closure}}
             at ./main.rs:83
  14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  15: <futures_util::future::future::flatten::Flatten<Fut,<Fut as core::future::future::Future>::Output> as core::future::future::Future>::poll
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/future/future/flatten.rs:51
  16: <futures_util::future::future::Then<Fut1,Fut2,F> as core::future::future::Future>::poll
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/lib.rs:107
  17: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  18: juniper::types::async_await::resolve_selection_set_into_async_recursive::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:326
  19: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  20: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  21: juniper::types::async_await::GraphQLValueAsync::resolve_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:104
  22: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  23: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  24: juniper::executor::Executor<CtxT,S>::resolve_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:468
  25: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  26: juniper::executor::Executor<CtxT,S>::resolve_into_value_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:512
  27: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  28: juniper::types::containers::resolve_into_list_async::{{closure}}::{{closure}}::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/containers.rs:310
  29: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  30: <futures_util::stream::futures_ordered::OrderWrapper<T> as core::future::future::Future>::poll
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/futures_ordered.rs:52
  31: <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/futures_unordered/mod.rs:542
  32: futures_util::stream::stream::StreamExt::poll_next_unpin
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/stream/mod.rs:1323
  33: <futures_util::stream::futures_ordered::FuturesOrdered<Fut> as futures_core::stream::Stream>::poll_next
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/futures_ordered.rs:170
  34: futures_util::stream::stream::StreamExt::poll_next_unpin
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/stream/mod.rs:1323
  35: <futures_util::stream::stream::next::Next<St> as core::future::future::Future>::poll
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/stream/next.rs:35
  36: juniper::types::containers::resolve_into_list_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/containers.rs:314
  37: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  38: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  39: juniper::executor::Executor<CtxT,S>::resolve_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:468
  40: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  41: juniper::executor::Executor<CtxT,S>::resolve_with_ctx_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:486
  42: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  43: <test::Query as juniper::types::async_await::GraphQLValueAsync<__S>>::resolve_field_async::{{closure}}
             at ./main.rs:15
  44: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  45: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  46: juniper::types::async_await::resolve_selection_set_into_async_recursive::{{closure}}::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:266
  47: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  48: <juniper::types::async_await::resolve_selection_set_into_async_recursive::{{closure}}::AsyncValueFuture<A,B,C,D> as core::future::future::Future>::poll
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:190
  49: <futures_util::stream::futures_ordered::OrderWrapper<T> as core::future::future::Future>::poll
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/futures_ordered.rs:52
  50: <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/futures_unordered/mod.rs:542
  51: futures_util::stream::stream::StreamExt::poll_next_unpin
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/stream/mod.rs:1323
  52: <futures_util::stream::futures_ordered::FuturesOrdered<Fut> as futures_core::stream::Stream>::poll_next
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/futures_ordered.rs:170
  53: futures_util::stream::stream::StreamExt::poll_next_unpin
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/stream/mod.rs:1323
  54: <futures_util::stream::stream::next::Next<St> as core::future::future::Future>::poll
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/stream/next.rs:35
  55: juniper::types::async_await::resolve_selection_set_into_async_recursive::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:363
  56: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  57: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  58: juniper::types::async_await::GraphQLValueAsync::resolve_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/types/async_await.rs:104
  59: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  60: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  61: juniper::executor::Executor<CtxT,S>::resolve_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:468
  62: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  63: juniper::executor::Executor<CtxT,S>::resolve_into_value_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:512
  64: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  65: juniper::executor::execute_validated_query_async::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/executor/mod.rs:963
  66: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  67: juniper::execute::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/lib.rs:296
  68: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  69: juniper::http::GraphQLRequest<S>::execute::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/http/mod.rs:119
  70: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  71: juniper::http::GraphQLBatchRequest<S>::execute::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper/src/http/mod.rs:303
  72: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  73: juniper_hyper::execute_request::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper_hyper/src/lib.rs:199
  74: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  75: juniper_hyper::graphql::{{closure}}
             at /home/lukas/.cargo/git/checkouts/juniper-aa5e857cd28538c7/4ffd276a/juniper_hyper/src/lib.rs:53
  76: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
[...]
  78: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  79: <std::panic::AssertUnwindSafe<F> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:325
  80: <futures_util::future::future::catch_unwind::CatchUnwind<Fut> as core::future::future::Future>::poll::{{closure}}
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/future/future/catch_unwind.rs:28
  81: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:308
  82: std::panicking::try::do_call
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:381
  83: __rust_try
  84: std::panicking::try
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:345
  85: std::panic::catch_unwind
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:382
  86: <futures_util::future::future::catch_unwind::CatchUnwind<Fut> as core::future::future::Future>::poll
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/future/future/catch_unwind.rs:28
[...]            
  88: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/lukas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  89: <hyper::proto::h1::dispatch::Server<S,hyper::body::body::Body> as hyper::proto::h1::dispatch::Dispatch>::poll_msg
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.7/src/proto/h1/dispatch.rs:476
  90: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_write
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.7/src/proto/h1/dispatch.rs:284
  91: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.7/src/proto/h1/dispatch.rs:151
  92: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_inner
             at /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.7/src/proto/h1/dispatch.rs:127

This is a bug, right? I think the GraphQL spec allows these queries, even if not all objects are of that downcasted type. In either way, it shouldn't panic, right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions