GraphQL Where Select 子查询

GraphQL Where Select Sub Query

这些天,我学习了GraphQLLaravel框架,Lighthouse Library。 我尝试过 SELECT Query.

因此,不知GraphQL能否在select下面SQL查询

SELECT * FROM TABLE_A WHERE type=1 AND chart_id=(SELECT id FROM TABLE_B WHERE phone='0000~~')

我预计,客户端首先从该查询中获得结果。

SELECT id FROM TABLE_B WHERE phone='0000~~'

然后进行二次查询,我想我可以得到结果。

但我想知道我能否从 1 个请求中获得结果。谢谢。

您可以尝试关注

 $phoneNumber = '0000~~';

 $data = DB::table('tableA')->where('type',1)
            ->whereIn('chart_id',function($query) use ($phoneNumber) {
                $query->select('id')
                      ->from('tableB')
                     ->where('phone', '=',$phoneNumber);
         })->get();

如果 tableAtableB 之间存在关系,您可以执行以下操作

 TableA::where('type',1)
        ->whereHas('tableBRelationshipName', function ($q) use ($phoneNumber) {
             $q->select('id')
             $q->where('phone','=',$phoneNumber);
 })->get();