Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active April 18, 2020 03:39
Show Gist options
  • Save vladbatushkov/69f41e6e12c88612a98497e52a7ceb9e to your computer and use it in GitHub Desktop.
Save vladbatushkov/69f41e6e12c88612a98497e52a7ceb9e to your computer and use it in GitHub Desktop.
GraphQL query to list Airports
const GET_AIRPORTS = gql`
query airportsPaginateQuery(
$first: Int
$offset: Int
$orderBy: [_AirportOrdering]
$filter: _AirportFilter
) {
Airport(
first: $first
offset: $offset
orderBy: $orderBy
filter: $filter
) {
code
name
city
country
location {
longitude
latitude
}
}
}
`;
const getFilter = () =>
Object.keys(filterState)
.map(x => ({ [x + "_contains"]: filterState[x] }))
.reduce((a, b) => ({ ...a, ...b }), {});
const { loading, data, error } = useQuery(GET_AIRPORTS, {
variables: {
first: rowsPerPage,
offset: rowsPerPage * page,
orderBy: orderBy + "_" + order,
filter: getFilter()
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment