graphql-rust / graphql-client

Typed, correct GraphQL requests and responses in Rust
Apache License 2.0
1.14k stars 157 forks source link

Fragments as Traits #466

Closed slyons closed 9 months ago

slyons commented 9 months ago

Let's say I have some fragments:

fragment TeamIdent on Team {
  _id
  name
}

fragment ProjectIdent on Project {
    _id
    name
    team {
        ...TeamIdent
    }
}

And the query:

query ListAll($email: String = "") {
  User(email: $email) {
    _id
    projects {
      ...ProjectIdent
    }
    pipelines {
      name
      _id
      project {
        ...ProjectIdent
      }
    }
}

Would it be at all possible to create traits from those fragments so that I could create re-usable functions around them? Like ListAllUserProjects could implement trait ProjectIdent so that _id and _name were abstracted as functions.

I'm selecting the same fields for a very nested graph definition and I was hoping there was a way I could make it more generic.

maxbraeutigam commented 3 months ago

Hi @slyons, would you be so kind to show, how to use the trait of a fragment?