Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a __typename handler branch in stubgen. #500

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ jobs:

- name: Install rust + caching
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""

- name: Set up sccache
uses: mozilla-actions/[email protected]
Expand Down
6 changes: 6 additions & 0 deletions trustfall_stubgen/src/adapter_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ fn emit_property_handling(
external_imports.insert(parse_import("trustfall::provider::ContextOutcomeIterator"));
external_imports.insert(parse_import("trustfall::provider::ResolveInfo"));
external_imports.insert(parse_import("trustfall::FieldValue"));
external_imports.insert(parse_import("trustfall::provider::Typename"));
external_imports.insert(parse_import("trustfall::provider::resolve_property_with"));

quote! {
fn resolve_property(
Expand All @@ -168,6 +170,10 @@ fn emit_property_handling(
property_name: &Arc<str>,
resolve_info: &ResolveInfo,
) -> ContextOutcomeIterator<'a, Self::Vertex, FieldValue> {
if property_name.as_ref() == "__typename" {
return resolve_property_with(contexts, |vertex| vertex.typename().into());
}

match type_name.as_ref() {
#arms
_ => unreachable!("attempted to read property '{property_name}' on unexpected type: {type_name}"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{Arc, OnceLock};

use trustfall::{FieldValue, Schema, provider::{ContextIterator, ContextOutcomeIterator, EdgeParameters, ResolveEdgeInfo, ResolveInfo, VertexIterator, resolve_coercion_using_schema}};
use trustfall::{FieldValue, Schema, provider::{ContextIterator, ContextOutcomeIterator, EdgeParameters, ResolveEdgeInfo, ResolveInfo, Typename, VertexIterator, resolve_coercion_using_schema, resolve_property_with}};

use super::vertex::Vertex;

Expand Down Expand Up @@ -171,6 +171,9 @@ impl<'a> trustfall::provider::Adapter<'a> for Adapter {
property_name: &Arc<str>,
resolve_info: &ResolveInfo,
) -> ContextOutcomeIterator<'a, Self::Vertex, FieldValue> {
if property_name.as_ref() == "__typename" {
return resolve_property_with(contexts, |vertex| vertex.typename().into());
}
match type_name.as_ref() {
"Comment" => {
super::properties::resolve_comment_property(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{Arc, OnceLock};

use trustfall::{FieldValue, Schema, provider::{ContextIterator, ContextOutcomeIterator, EdgeParameters, ResolveEdgeInfo, ResolveInfo, VertexIterator, resolve_coercion_using_schema}};
use trustfall::{FieldValue, Schema, provider::{ContextIterator, ContextOutcomeIterator, EdgeParameters, ResolveEdgeInfo, ResolveInfo, Typename, VertexIterator, resolve_coercion_using_schema, resolve_property_with}};

use super::vertex::Vertex;

Expand Down Expand Up @@ -68,6 +68,9 @@ impl<'a> trustfall::provider::Adapter<'a> for Adapter {
property_name: &Arc<str>,
resolve_info: &ResolveInfo,
) -> ContextOutcomeIterator<'a, Self::Vertex, FieldValue> {
if property_name.as_ref() == "__typename" {
return resolve_property_with(contexts, |vertex| vertex.typename().into());
}
match type_name.as_ref() {
"const2" => {
super::properties::resolve_const2_property(
Expand Down