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

Add support for link properties in derive macro #201

Open
XAMPPRocky opened this issue Jan 3, 2023 · 3 comments
Open

Add support for link properties in derive macro #201

XAMPPRocky opened this issue Jan 3, 2023 · 3 comments

Comments

@XAMPPRocky
Copy link

As far I can tell there's no way to use link properties in the derive macro currently, instead you need to map from edged_protocol::Value into the type you want in order to be able to use a type that contains a link. This is very unergonomic as most if not all the types we've been using thus far have some sort of link property that we want to access in Rust.

It would be nice if links were properly supported. I'd be happy to lend some time to help implementing this, but I would need guidance on how the decoding of links should work so I can generate the code in the decode implementation.

@tailhook
Copy link
Contributor

tailhook commented Jan 4, 2023

decoding of links

If you mean "decoding of link properties", they are the same as normal properties, except for a flag. We probably have to make a Rust attribute, that basically asserts on that:

#[derive(Queryable)]
struct UserLink {
    // asserts link flag on the `relationship` property descriptor is set
    #[edgedb(link_property)]
    relationship: Relationship,
    
    // asserts link flag is not set (i.e. a normal property by default)
    username: String,
}

@XAMPPRocky
Copy link
Author

If you mean "decoding of link properties", they are the same as normal properties, except for a flag. We probably have to make a Rust attribute

That is what I meant, what you proposed is what I was thinking (though I think I would have it as #[edgedb(link)] as it's just as clear IMO and shorter). The part I'm unsure about is "how do you add that flag with edgedb_protocol::queryable::Decoder".

@tailhook
Copy link
Contributor

tailhook commented Jan 5, 2023

(though I think I would have it as #[edgedb(link)] as it's just as clear IMO and shorter).

Some of the fields in the structure are an actual links. We don't mark those and I think it's fine. Link properties are somewhat special as they appear on objects where they are not defined in the schema (i.e. User object can get relationship link property which is defined on on User schema but on the link itself, so in different places User object will get different link properties).

The part I'm unsure about is "how do you add that flag with edgedb_protocol::queryable::Decoder".

I'm not sure I understand the question. But flag is here:

pub flag_link_property: bool,

And can be checked like this:
if(!shape.elements[idx].flag_implicit) {

Although, as I'm looking on the code, we don't check the flag anywhere. So you should be able to read link property as a normal property right now without any annotation. Which I consider a bug, but you can abuse it for now.

@tailhook tailhook added this to the EdgeDB 3.0 milestone Feb 1, 2023
@tailhook tailhook removed this from the EdgeDB 3.0 milestone Feb 27, 2023
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

No branches or pull requests

2 participants