mara leo
mara leo

Reputation: 33

How to filter data in GraphQL query in Flutter?

I am using GraphQL in Flutter. I do not have much experience of using GraphQL in Flutter. 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/ . But I do not know how to do it. If anybody know how to do it then please help me. Thanks

Upvotes: 0

Views: 965

Answers (1)

H S W
H S W

Reputation: 7119

You have to do filtering by using api specfic keyword for filtering. 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”. As a example i put “mission_name” = "Thaicom 6", you can edit it according to your requirement.

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
  }
}

Upvotes: 1

Related Questions