Async-graphql: How to rename a field on a async_graphql::Object?

Created on 3 Jun 2020  路  5Comments  路  Source: async-graphql/async-graphql

I have a situation as shown below:

pub struct MyStruct;

#[async_graphql::Object]
impl MyStruct {
    // I want to rename this field to 'type' because the crate changes it into 'rType'
    pub async fn r#type(&self) -> i32 { 1337 }
}

I have tried applying [arg(name="type")] but that didn't work.

All 5 comments

pub struct MyStruct;

#[async_graphql::Object]
impl MyStruct {
   #[field(name="type")]
    pub async fn r#type(&self) -> i32 { 1337 }
}

#[arg(name="..")] is use for fields argument.

I want to rename this field to 'type' because the crate changes it into 'rType'

If so, it's a bug and I'll see how it works.

This is a bug and you don't need to manually change the field name.

syn gives me rType and doesn't tell me it's actually an r#type, you have to rename the field manually.

That's a bummer, that's lost information. But renaming it isn't too much of a hassle either. Thanks for taking a look 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GQAdonis picture GQAdonis  路  3Comments

danielSanchezQ picture danielSanchezQ  路  4Comments

dhendrie91 picture dhendrie91  路  3Comments

servonlewis picture servonlewis  路  4Comments

frigus02 picture frigus02  路  5Comments