graphQL using fragment
Graphql fragment are used to simplified and provide shortcuts definitions to specified the same fields in a graphql query.
In this example, we provide defined ReportFields to consist of propertyType, id and status. Then we hook it up in the actual gteReportsByUserId query as shown here:-
query GetReportsByUserId($includeStatus: Boolean!)
{
getReportsByUserId(userId: "123", limit: 10) {
status
reports {
...ReportFields
}
}
}
fragment ReportFields on RetrievedReport {
propertyType
id
status @include(if: $includeStatus)
}
Save us some typings in our query.
Comments