Enatega

Queries 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 enatega-multivendor-app/src/apollo/client.js and enatega-multivendor-app/src/apollo/server.js in Dashboard Queries are located in enatega-multivendor-admin/src/apollo/server.js As an example look into enatega-multivendor-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 meals, which can be found at enatega-multivendor-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.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top