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

Allow TryIntoStruct to unpack EdgeParameters as well. #350

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

obi1kenobi
Copy link
Owner

@obi1kenobi obi1kenobi commented Jul 7, 2023

Edges defined in Trustfall schemas may take parameters, for example:

type NewsWebsite {
    latest_stories(count: Int!): [Story!]!
}

This trait can be used to deserialize &EdgeParameters into a struct specific to the parameters of that edge:

struct LatestStoriesParameters {
    count: usize
}

For example:

use trustfall_core::TryIntoStruct;

fn resolve_latest_stories(contexts: ContextIterator<Vertex>, parameters: &EdgeParameters) {
    let parameters: LatestStoriesParameters = parameters
        .try_into_struct()
        .expect("edge parameters did not match struct definition");
    let count = parameters.count;

    // then resolve the edge with the given count
}

Resolves #343.

Edges defined in Trustfall schemas may take parameters, for example:

```graphql
type NewsWebsite {
    latest_stories(count: Int!): [Story!]!
}
```

This trait can be used to deserialize [`&EdgeParameters`](crate::ir::EdgeParameters)
into a struct specific to the parameters of that edge:
```rust
struct LatestStoriesParameters {
    count: usize
}
```

For example:
```rust
use trustfall_core::TryIntoStruct;

fn resolve_latest_stories(contexts: ContextIterator<Vertex>, parameters: &EdgeParameters) {
    let parameters: LatestStoriesParameters = parameters
        .try_into_struct()
        .expect("edge parameters did not match struct definition");
    let count = parameters.count;
    // then resolve the edge with the given count
}
```

Resolves #343.
@obi1kenobi obi1kenobi enabled auto-merge (squash) July 7, 2023 19:38
@obi1kenobi obi1kenobi added A-adapter Area: plugging data sources into the interpreter L-rust Language: affects use cases in the Rust programming language R-relnotes Release: document this in the release notes of the next release labels Jul 7, 2023
@obi1kenobi obi1kenobi merged commit bbade61 into main Jul 7, 2023
11 checks passed
@obi1kenobi obi1kenobi deleted the try_into_struct_for_edge_parameters branch July 7, 2023 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-adapter Area: plugging data sources into the interpreter L-rust Language: affects use cases in the Rust programming language R-relnotes Release: document this in the release notes of the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement TryIntoStruct for EdgeParameters
1 participant