在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):davidpdrsn/juniper-from-schema开源软件地址(OpenSource Url):https://github.com/davidpdrsn/juniper-from-schema开源编程语言(OpenSource Language):Rust 99.9%开源软件介绍(OpenSource Introduction):juniper-from-schemaThis library contains a procedural macro that reads a GraphQL schema file, and generates the corresponding Juniper macro calls. This means you can have a real schema file and be guaranteed that it matches your Rust implementation. It also removes most of the boilerplate involved in using Juniper. Looking for juniper 0.15 support?The version of juniper-from-schema that is released on crates.io (0.5.2) doesn't support juniper 0.15. However the master branch does! So you will have to use a git dependency for now. We plan to do an official release soon. Follow this milestone to see whats left. ExampleImagine you have a GraphQL schema like this: schema {
query: Query
}
type Query {
helloWorld(name: String!): String! @juniper(ownership: "owned")
} That can be implemented like so: use juniper_from_schema::graphql_schema_from_file;
// This is the important line
graphql_schema_from_file!("readme_schema.graphql");
pub struct Context;
impl juniper::Context for Context {}
pub struct Query;
// This trait is generated by `graphql_schema_from_file!` based on the schema
impl QueryFields for Query {
fn field_hello_world(
&self,
_executor: &juniper::Executor<Context>,
name: String,
) -> juniper::FieldResult<String> {
Ok(format!("Hello, {}!", name))
}
}
fn main() {
let ctx = Context;
let query = "query { helloWorld(name: \"Ferris\") }";
let (result, errors) = juniper::execute_sync(
query,
None,
&Schema::new(Query, juniper::EmptyMutation::new()),
&juniper::Variables::new(),
&ctx,
)
.unwrap();
assert_eq!(errors.len(), 0);
assert_eq!(
result
.as_object_value()
.unwrap()
.get_field_value("helloWorld")
.unwrap()
.as_scalar_value::<String>()
.unwrap(),
"Hello, Ferris!",
);
} See the crate documentation for a usage examples and more info. N+1sIf you're having issues with N+1 query bugs consider using juniper-eager-loading. It was built to integrate seamlessly with juniper-from-schema. Development
If you're seeing |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论