Queries Mutations and Fragments

Queries Mutations and Fragments

Queries

Fetching data in a simple, predictable way is one of the core features of Apollo Client. Queries are used to fetch GraphQL data attach the result to your UI. In frontend mobile and dashboard we have written multiple queries in mobile app located in food-delivery-app/src/apollo/client.js and food-delivery-app/src/apollo/server.js in Dashboard Queries are located in food-delivery-admin/src/apollo/server.js As an example look into food-delivery-app/src/apollo/client.js and the constant getNotifications the query is written as

query GetNotifications{
    notifications{
    _id
    order
    status
    }
}

On line 1 GetNotifications is the query name for the frontend while on line 2 notifications is the query name for backend. The parameters written inside notifications are output parameters they will be returned by the GraphQL endpoint.

Now let's take a look at another example this time we are going to pass some parameters as input to a query. The constant foods is a simple example for this located at food-delivery-app/src/apollo/server.js

query FoodByCategory($category:String!){
    foodByCategory(category:$category){
    _id
    title
    description
    variations{
        _id
        type
        price
    }
    category{_id}
    img_url
    likes
    liked
    }
}

On line 1 FoodByCategory is the query name for the frontend we are passing a String where it's variable name is category $ sign is used for variable name while ! is used for required field. On line 2 foodByCategory is the query name for the backend

Last updated