fbpx

Enjoy

Upto

50%
Getting Started
Essentials

API Server Mutations and Fragments

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
    }
}

The query name for the frontend is GetNotifications on line 1, while the query name for the backend is notifications on line 2. The GraphQL endpoint will return the output parameters that are written inside notifications.
Now let’s look at another example where we’ll send some parameters to a query as input. A straightforward example of this is the constant foods, which can be found 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
    }
}

FoodByCategory is the frontend’s query name, and on line 1 we pass a String whose variable name is category. For variable names, the $ sign is used, and for necessary fields, the! sign is used. FoodByCategory is the backend query name, and it appears on line 2.

On this page
    WhatsApp Chat