Last active
April 18, 2020 03:39
-
-
Save vladbatushkov/69f41e6e12c88612a98497e52a7ceb9e to your computer and use it in GitHub Desktop.
GraphQL query to list Airports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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