Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What are some examples of complex query structures supported by Runway
    Statamic GraphQL Runway Eloquent advanced queries filtering sorting pagination mutations Statamic API


What are some examples of complex query structures supported by Runway


Runway supports some advanced query structures for Eloquent models in Statamic's GraphQL API:

1. Filtering and Sorting:
- You can filter and sort the results of your GraphQL queries using Eloquent scopes.
- For example, to fetch the first 25 products sorted by name:

graphql
     products(limit: 25, sort: "name") {
         data {
             id
             name
             price
             description
         }
     }
     

2. Nested Relationships:
- If your Eloquent models have relationships (e.g., "Belongs To" or "Has Many"), you can query the related models in your GraphQL queries.
- For example, to fetch a product and its associated brand:

graphql
     product(id: "2") {
         id
         name
         brand {
             id
             name
             created_at
             updated_at
         }
     }
     

3. Pagination:
- Runway supports pagination for your GraphQL queries, allowing you to fetch a subset of results at a time.
- You can use the `limit` and `offset` parameters to control the pagination.
- For example, to fetch the second page of 25 products:

graphql
     products(limit: 25, offset: 25) {
         data {
             id
             name
             price
             description
         }
     }
     

4. Mutations:
- In addition to queries, Runway also supports GraphQL mutations, which allow you to create, update, or delete Eloquent models.
- For example, to create a new product:

graphql
     mutation {
         createProduct(input: {
             name: "New Product"
             price: 99.99
         }) {
             id
             name
             price
         }
     }
     

By leveraging these advanced query structures, you can build powerful and flexible GraphQL APIs for your Statamic-powered applications that leverage Eloquent models.

Citations:
[1] https://statamic.com/addons/rad-pack/runway
[2] https://runway.duncanmcclean.com/graphql
[3] https://runway.duncanmcclean.com/rest-api
[4] https://help.runwayml.com/hc/en-us/articles/15161225169171-Gen-1-advanced-settings
[5] https://accreditly.io/articles/how-to-use-graphql-in-statamic