add a test for the printing of link directive
This commit is contained in:
parent
95b4e613b1
commit
fb5805a44e
|
@ -547,6 +547,86 @@ pub async fn test_entity_inaccessible() {
|
|||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
pub async fn test_link_directive() {
|
||||
struct User {
|
||||
id: ID,
|
||||
}
|
||||
|
||||
#[Object(extends)]
|
||||
impl User {
|
||||
#[graphql(external)]
|
||||
async fn id(&self) -> &ID {
|
||||
&self.id
|
||||
}
|
||||
|
||||
async fn reviews(&self) -> Vec<Review> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct Review;
|
||||
|
||||
#[Object]
|
||||
impl Review {
|
||||
async fn body(&self) -> String {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn author(&self) -> User {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn product(&self) -> Product {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct Product {
|
||||
upc: String,
|
||||
}
|
||||
|
||||
#[Object(extends)]
|
||||
impl Product {
|
||||
#[graphql(external)]
|
||||
async fn upc(&self) -> &str {
|
||||
&self.upc
|
||||
}
|
||||
|
||||
async fn reviews(&self) -> Vec<Review> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct Query;
|
||||
|
||||
#[Object]
|
||||
impl Query {
|
||||
#[graphql(entity)]
|
||||
async fn find_user_by_id(&self, id: ID) -> User {
|
||||
User { id }
|
||||
}
|
||||
|
||||
#[graphql(entity)]
|
||||
async fn find_product_by_upc(&self, upc: String) -> Product {
|
||||
Product { upc }
|
||||
}
|
||||
}
|
||||
|
||||
let schema_sdl = Schema::build(Query, EmptyMutation, EmptySubscription)
|
||||
.enable_apollo_fed2_link()
|
||||
.finish()
|
||||
.sdl_with_options(SDLExportOptions::new().federation());
|
||||
|
||||
let path = std::path::Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||
.join("tests/schemas/test_fed2_link.schema.graphqls");
|
||||
let expected_schema = std::fs::read_to_string(&path).unwrap();
|
||||
if schema_sdl != expected_schema {
|
||||
std::fs::write(path, schema_sdl).unwrap();
|
||||
panic!("schema was not up-to-date. verify changes and re-run if correct.")
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
pub async fn test_entity_tag() {
|
||||
struct MyCustomObjTagged;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
|
||||
|
||||
|
||||
extend type Product @key(fields: "upc") {
|
||||
upc: String! @external
|
||||
reviews: [Review!]!
|
||||
}
|
||||
|
||||
|
||||
type Review {
|
||||
body: String!
|
||||
author: User!
|
||||
product: Product!
|
||||
}
|
||||
|
||||
|
||||
extend type User @key(fields: "id") {
|
||||
id: ID! @external
|
||||
reviews: [Review!]!
|
||||
}
|
||||
|
||||
extend schema @link(
|
||||
url: "https://specs.apollo.dev/federation/v2.0",
|
||||
import: ["@key", "@tag", "@shareable", "@inaccessible", "@override", "@external", "@provides", "@requires"]
|
||||
)
|
Loading…
Reference in New Issue