在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):nrc/graphql开源软件地址(OpenSource Url):https://github.com/nrc/graphql开源编程语言(OpenSource Language):Rust 100.0%开源软件介绍(OpenSource Introduction):GraphQL server framework in RustThis framework lets you write type-safe, efficient GraphQL servers in Rust. We make heavy use of macros to cut down on boilerplate and the trait system to allow maximum flexibility. This project is at 'proof of concept' stage. It can only handle minimal examples and some key components are missing. However, I believe the results are already promising - Rust and GraphQL are a great match! In the future we should use Rusts emerging async IO systems to make extremely performant servers. ExampleUse the schema! {
schema {
query: Query,
}
type Query {
hero(episode: Episode): Character,
human(id : ID!): Human,
}
enum Episode {
NEWHOPE,
EMPIRE,
JEDI,
}
interface Character {
id: ID!,
name: String!,
friends: [Character],
appearsIn: [Episode]!,
}
type Human implements Character {
id: ID!,
name: String!,
friends: [Character],
appearsIn: [Episode]!,
homePlanet: String,
}
} You can see the output for this example use of the The macro generates concrete and abstract versions of each item. The library user
must specify implementations for functions (e.g., TODO these are equivalent to resolvers in the JS frameworks struct MyServer;
impl Root for MyServer {
type Query = DbQuery;
fn query(&self) -> QlResult<DbQuery> {
Ok(DbQuery)
}
}
ImplRoot!(MyServer);
struct DbQuery;
impl AbstractQuery for DbQuery {
fn hero(&self, episode: Option<Episode>) -> QlResult<Option<Character>> {
match episode {
Some(Episode::JEDI) => {
// In real life, this would query the DB or execute business logic.
Ok(Some(Character {
id: Id("0".to_owned()),
name: "Luke".to_owned(),
friends: Some(vec![]),
appearsIn: vec![],
}))
}
_ => unimplemented!(),
}
}
fn human(&self, _id: Id) -> QlResult<Option<Human>> {
...
}
} If you don't want to use the generated representation for a certain item, you
can provide your own (perhaps using a struct MyHuman {
id: usize,
db_table: DbTablePtr,
}
ImplHuman!(MyHuman);
impl AbstractHuman for MyHuman {
fn resolve_field(&self, field: &query::Field) -> QlResult<result::Value> {
...
}
} TODO show |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论