0

我正在努力弄清楚如何将两个不同的 GraphQL 对象结合在一起。在我整理的 PoC 中,我有一个Invoice对象:

#[derive(SimpleObject, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Invoice {
  invoice_no: String,
  invoice_date: NaiveDate,
  amount: Decimal,
  paid: bool,
  customer_no: i32
}

使用适当的查询:

async fn invoice(
        &self,
        ctx: &Context<'_>,
        invoice_no: String,
    ) -> FieldResult<Invoice> {}

    async fn invoices(
        &self,
        ctx: &Context<'_>,
        start_date: Option<NaiveDate>,
        end_date: Option<NaiveDate>,
        customer_no: Option<i32>,
        paid: Option<bool>,
        after: Option<String>,
        before: Option<String>,
        first: Option<i32>,
        last: Option<i32>,
    ) -> Result<Connection<usize, Invoice, Summary, EmptyFields>> {}

当我启动我的应用程序时,这完全符合预期,并且所有查询都正常工作。

我有另一个应用程序,但这是一个Customer对象:

#[derive(SimpleObject, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Customer {
  customer_no: i32,
  city: String,
  name: String
}

它具有与 类似的查询Invoice,但还包括:

#[graphql(entity)]
async fn find_customer_by_customer_no(
    &self,
    ctx: &Context<'_>,
    #[graphql(key)] customer_no: i32,
) -> FieldResult<Option<Customer>> {}

我在这个服务中也有一个表示Invoice来将它们合并在一起:

struct Invoice {
  customer_no: i32
}


#[Object(extends)]
impl Invoice {
    #[graphql(external)]
    async fn customer_no(&self) -> &i32 {
        &self.customer_no
    }
    
    async fn customer(&self, ctx: &Context<'_>) -> Option<Customer> {
      // Implementation
    }
}

同样,我自己可以完美地查询所有客户。当我设置一个 Apollo 联合网关时,我得到一个包含InvoiceCustomer查询的模式。但是,该customer字段永远不会添加到Invoice对象中。Apollo 网关在启动时不会报告任何错误。将字段添加到对象中我缺少什么?

4

0 回答 0