async-graphql / examples

217 stars 54 forks source link

how to disable implicit field renaming? #85

Closed theunkn0wn1 closed 2 months ago

theunkn0wn1 commented 2 months ago

async-graphql seems to be renaming struct fields that are snake_case to conform to pascalCase. This should be an optional behavior that is opt-in.

I am evaluating using async-graphql to replace pieces of an existing api that is exclusively snake_case. implicitly renaming these fields will break the API.

    #[derive(SimpleObject)]
    struct DemoObject {
        foo: String,
        my_snake_case: usize
    }
   // ...
    #[Object]
    impl Query {
            async fn demo(&self) -> DemoObject {
            todo!()
        }
    }

image

theunkn0wn1 commented 2 months ago

Oops, this is the wrong repository for this

theunkn0wn1 commented 2 months ago

For anyone finding this in the future, async-graphql will implicitly rename fields. To avoid this behavior, add #[graphql(rename_fields="snake_case")] as such:


    #[derive(SimpleObject)]
    #[graphql(rename_fields="snake_case")]
    struct DemoObject {
        foo: String,
        my_snake_case: usize
    }
`

This information should be in the book front and center.