Skip to content

Ability to create a snake_case field with the graphql_object! macro #201

Closed
@sylvain101010

Description

@sylvain101010

Hi, as I wasn't able to find any way to do this I open this issue:

a way to create snake_case fields should be provided.

Now we can create an object

graphql_object!(Human: () |&self| {
    field id() -> Option<&str> {
        self.id.as_str()
    }

    field appearsIN() -> Vec<Episode> {
        vec![Episode::NewHope, Episode::Jedi]
    }
});

which results in

query {
human(id: "1234") {
    id
    appearsIN
  }
}

but we can't create the following object due to the automatic field transformation

query {
human(id: "1234") {
    id
    appears_in
  }
}

indeed

graphql_object!(Human: () |&self| {
    field id() -> Option<&str> {
        self.id.as_str()
    }

    field appears_in() -> Vec<Episode> {
        vec![Episode::NewHope, Episode::Jedi]
    }
});

will results in

query {
human(id: "1234") {
    id
    appearsIn
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    easyenhancementImprovement of existing features or bugfix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions