fix: blanket impl GraphQLFields for Option<T> for nullable queries#121
Merged
fix: blanket impl GraphQLFields for Option<T> for nullable queries#121
impl GraphQLFields for Option<T> for nullable queries#121Conversation
…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
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 allowsOption<T>to be used as the type parameter in generated query functions.2. Codegen nullable detection: Modify codegen to detect nullable return types (
IssuevsIssue!) and emitResult<Option<T>>instead ofResult<T>for those queries. This encodes nullability in the function signature so callers don't need to guess.Together, nullable queries like
issueVcsBranchSearchnow work end-to-end:Also adds
issueVcsBranchSearchtooperations.tomlas the first (and currently only) nullable non-connection query.Closes #120
Test plan
make check— cleanmake test— all offline tests pass (54 unit + 125 integration)cargo run -p lineark-codegen— regenerated, onlyissue_vcs_branch_searchgetsResult<Option<T>>field_selection::tests:option_delegates_selection_to_inner_type—Option<T>::selection() == T::selection()option_preserves_full_type— compile-time proof thatOption<T>::FullType == T::FullTypeoption_nullable_query_deserialization— full chain:GraphQLFields+ serde null/object handling