|
1 | 1 | use heck::ToLowerCamelCase; |
2 | | -use proc_macro2::TokenStream; |
| 2 | +use proc_macro2::{Ident, Span, TokenStream}; |
| 3 | +use proc_macro_crate::{crate_name, FoundCrate}; |
3 | 4 | use quote::{quote, quote_spanned}; |
4 | 5 |
|
5 | 6 | use crate::derives::attributes::related_attr; |
@@ -82,9 +83,21 @@ impl DeriveRelatedEntity { |
82 | 83 | }) |
83 | 84 | .collect::<Result<Vec<_>, _>>()?; |
84 | 85 |
|
| 86 | + // Get the path of the `async-graphql` on the application's Cargo.toml |
| 87 | + let async_graphql_crate = match crate_name("async-graphql") { |
| 88 | + // if found, use application's `async-graphql` |
| 89 | + Ok(FoundCrate::Name(name)) => { |
| 90 | + let ident = Ident::new(&name, Span::call_site()); |
| 91 | + quote! { #ident } |
| 92 | + } |
| 93 | + Ok(FoundCrate::Itself) => quote! { async_graphql }, |
| 94 | + // if not, then use the `async-graphql` re-exported by `seaography` |
| 95 | + Err(_) => quote! { seaography::async_graphql }, |
| 96 | + }; |
| 97 | + |
85 | 98 | Ok(quote! { |
86 | 99 | impl seaography::RelationBuilder for #ident { |
87 | | - fn get_relation(&self, context: & 'static seaography::BuilderContext) -> async_graphql::dynamic::Field { |
| 100 | + fn get_relation(&self, context: & 'static seaography::BuilderContext) -> #async_graphql_crate::dynamic::Field { |
88 | 101 | let builder = seaography::EntityObjectRelationBuilder { context }; |
89 | 102 | let via_builder = seaography::EntityObjectViaRelationBuilder { context }; |
90 | 103 | match self { |
|
0 commit comments