简体   繁体   English

如何在 Flutter 中过滤 GraphQL 查询中的数据?

[英]How to filter data in GraphQL query in Flutter?

I am using GraphQL in Flutter.我在 Flutter 中使用 GraphQL。 I do not have much experience of using GraphQL in Flutter.我在 Flutter 中使用 GraphQL 的经验并不多。 The code is given below:代码如下:

WidgetsFlutterBinding.ensureInitialized();

  final HttpLink link = HttpLink(
   uri: 'https://api.spacex.land/graphql/',
  );

 ValueNotifier<GraphQLClient> client = ValueNotifier(
  GraphQLClient(
  cache: InMemoryCache(),
  link: link,
 ),
);

runApp(MyApp(client: client));
}

I have to perform by calling the GraphQL query "launches" filtering by the “mission_name” field exposed by this public backend: https://api.spacex.land/graphql/ .我必须通过此公共后端公开的“mission_name”字段调用 GraphQL 查询“launches”过滤来执行: https ://api.spacex.land/graphql/。 But I do not know how to do it.但我不知道该怎么做。 If anybody know how to do it then please help me.如果有人知道该怎么做,请帮助我。 Thanks谢谢

You have to do filtering by using api specfic keyword for filtering.您必须通过使用 api 特定关键字进行过滤来进行过滤。 In case of https://api.spacex.land/graphql/ it is find keyword, for other api it might be where or filter Below is example of the search done by calling the GraphQL query "launches" filtering by the “mission_name” .https://api.spacex.land/graphql/ 的情况下,它是find关键字,对于其他 api,它可能是wherefilter下面是通过调用GraphQL查询“launches”“mission_name”过滤完成的搜索示例. As a example i put “mission_name” = "Thaicom 6" , you can edit it according to your requirement.举个例子,我把“mission_name” = "Thaicom 6" ,你可以根据你的要求编辑它。

query launchesDetails {
  launches(find: {
     mission_name: "Thaicom 6",
  })   {
     details
     id
     is_tentative
     launch_date_local
     launch_date_unix
     launch_date_utc
     launch_site {
         site_id
         site_name
     }
     launch_success
     launch_year
     mission_name
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM