Skip to content

fix: blanket impl GraphQLFields for Option<T> for nullable queries#121

Merged
flipbit03 merged 2 commits intomainfrom
fix/graphqlfields-blanket-option
Mar 6, 2026
Merged

fix: blanket impl GraphQLFields for Option<T> for nullable queries#121
flipbit03 merged 2 commits intomainfrom
fix/graphqlfields-blanket-option

Conversation

@flipbit03
Copy link
Copy Markdown
Owner

@flipbit03 flipbit03 commented Mar 6, 2026

Summary

Two complementary fixes for nullable GraphQL query support:

1. Blanket impl (SDK): Add impl<T: GraphQLFields> GraphQLFields for Option<T> that delegates to the inner type's selection. This allows Option<T> to be used as the type parameter in generated query functions.

2. Codegen nullable detection: Modify codegen to detect nullable return types (Issue vs Issue!) and emit Result<Option<T>> instead of Result<T> for those queries. This encodes nullability in the function signature so callers don't need to guess.

Together, nullable queries like issueVcsBranchSearch now work end-to-end:

// Returns Result<Option<T>> — caller knows it might be null
let result = client.issue_vcs_branch_search::<Issue>(branch).await?;
match result {
    Some(issue) => println!("Found: {}", issue.identifier),
    None => println!("No issue for this branch"),
}

Also adds issueVcsBranchSearch to operations.toml as the first (and currently only) nullable non-connection query.

Closes #120

Test plan

  • make check — clean
  • make test — all offline tests pass (54 unit + 125 integration)
  • cargo run -p lineark-codegen — regenerated, only issue_vcs_branch_search gets Result<Option<T>>
  • 3 new unit tests in field_selection::tests:
    • option_delegates_selection_to_inner_typeOption<T>::selection() == T::selection()
    • option_preserves_full_type — compile-time proof that Option<T>::FullType == T::FullType
    • option_nullable_query_deserialization — full chain: GraphQLFields + serde null/object handling

…ueries

Generated query functions for nullable schema fields (e.g.
`issueVcsBranchSearch: Issue`) can now be called with `Option<T>` as the
type parameter. The blanket impl delegates selection to the inner type,
and serde handles null deserialization as `None`.

Closes #120
Nullable return types (e.g. `Issue` vs `Issue!`) now correctly produce
`Result<Option<T>>` instead of `Result<T>`. Combined with the blanket
`GraphQLFields for Option<T>` impl, this lets callers handle null
responses without custom methods like `execute_optional`.

Adds `issueVcsBranchSearch` to operations.toml as the first (and
currently only) nullable non-connection query.

Closes #120
@flipbit03 flipbit03 merged commit 69ec4aa into main Mar 6, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codegen: generated query functions don't handle nullable return types

1 participant