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

Tool cannot handle fields with name self #20

Open
banool opened this issue Jul 31, 2023 · 5 comments
Open

Tool cannot handle fields with name self #20

banool opened this issue Jul 31, 2023 · 5 comments

Comments

@banool
Copy link
Contributor

banool commented Jul 31, 2023

It is valid to have fields with the name self in a GraphQL schema but the tool doesn't handle it well:

thread 'main' panicked at '`r#self` cannot be a raw identifier', /Users/dport/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.66/src/fallback.rs:780:17
@banool
Copy link
Contributor Author

banool commented Jul 31, 2023

Some more information on keywords where the raw string handling doesn't work: https://internals.rust-lang.org/t/raw-identifiers-dont-work-for-all-identifiers/9094.

@banool
Copy link
Contributor Author

banool commented Jul 31, 2023

It seems like this function attempts to handle it but it apparently doesn't work as intended: https://github.com/banool/async-graphql-reverse/blob/5cea02a58e84c25ce2989a48b0d069d2c095018d/src/render/fields.rs#L364.

@banool
Copy link
Contributor Author

banool commented Jul 31, 2023

This is a little tricky to solve because it depends on how the generated types are used. For example I want to use the types with serde, so you'd need some custom serde attributes. If they're being used with serde, the field can be renamed and an attribute can be applied. But this library doesn't really focus on that use case.

@banool
Copy link
Contributor Author

banool commented Jul 31, 2023

The graphql-client generates code that looks like this, which is pretty much what I'd hope for here:

    pub struct ResponseData {
        #[serde(rename = "self")]
        pub self_: Any,
    }

@banool
Copy link
Contributor Author

banool commented Jul 31, 2023

I solve this in my fork here: https://github.com/banool/async-graphql-reverse/.

Repository owner deleted a comment from freshy969 Feb 20, 2024
Repository owner deleted a comment from SourceAura Feb 23, 2024
Repository owner deleted a comment from pavana21 Feb 23, 2024
Repository owner deleted a comment Mar 2, 2024
Repository owner deleted a comment Mar 2, 2024
Repository owner deleted a comment Mar 2, 2024
@github-staff github-staff deleted a comment from thangtq-pionero Apr 26, 2024
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

4 participants
@banool and others