Introduction
Welcome to the official documentation of the API system for Kibanda Finda and how to integrate with frontend applications. The GraphQL API is responsible for implementing the business requirements for the application. It includes code snippets and explanations of the various parts of the system.
You can try the graphql samples using the graphql explorer (access using http://localhost:8080/graphql) or try the javascript samples using apollo client library available via npm i @apollo/client
Authentication
mutation socialSignIn($data: LoginInput) {
socialSignIn(data: $data) {
token
status
user {
_id
name
picUrl
}
}
}
import { ApolloClient, gql } from '@apollo/client';
const client = new ApolloClient({
uri: 'http://localhost:8080/graphql',
});
const socialSignInMutation = gql`
mutation SocialSignIn($data: LoginInput) {
socialSignIn(data: $data) {
token
status
user {
_id
name
picUrl
}
}
}
`;
client
.mutate({
mutation: socialSignInMutation,
variables: {
data: {
idToken: 'your_id_token_here',
provider: 'Google',
},
},
})
.then((result) => {})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"socialSignIn": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"status": true,
"user": {
"_id": "abc123",
"name": "John Doe",
"picUrl": "https://example.com/profile.jpg"
}
}
}
}
This socialSignIn mutation allows users to sign in using social media credentials. If a user is not found, a new record is created in the database
- Input A
LoginInputobject containing the necessary data for social sign-in.
| Parameter | Type | Description |
|---|---|---|
| idToken | String | Represents the authentication token provided by the identity provider (e.g., Google, Facebook). |
| provider | String | Represents the identity provider used for authentication (e.g., "Google", "Facebook"). |
- Output A
LoginSuccessobject containing the status of the sign-in attempt, an authentication token, and user information.
| Parameter | Type | Description |
|---|---|---|
| status | Boolean | Represents the status of the login attempt. |
| token | String | Contains the authentication token upon successful login. |
| user | UserSummary | Represents a summary of the user who logged in. |
The UserSummary is an object representing the user details as shown below.
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the user. |
| name | String | Represents the name of the user. |
| picUrl | String | Contains the URL or path to the user's profile picture. |
Users
This section describes the various object types, mutations and queries available for users in the GraphQL API
Update Profile
mutation updateProfile($profile: UserInput) {
updateProfile(data: $profile) {
_id
name
picUrl
email
emailVerified
phone
phoneVerified
}
}
import { ApolloClient, gql } from '@apollo/client';
const client = new ApolloClient({
uri: 'http://localhost:8080/graphql',
});
const updateProfileMutation = gql`
mutation UpdateProfile($profile: UserInput) {
updateProfile(data: $profile) {
_id
name
picUrl
email
emailVerified
phone
phoneVerified
}
}
`;
// Usage example:
client
.mutate({
mutation: updateProfileMutation,
variables: {
profile: {
// Provide updated profile information
},
},
})
.then((result) => {})
.catch((error) => {});
The above code sample returns a JSON structured like this
{
"data": {
"updateProfile": {
"_id": "def456",
"name": "Jane Smith",
"picUrl": "https://example.com/new_profile.jpg",
"email": "jane@example.com",
"emailVerified": true,
"phone": "+1234567890",
"phoneVerified": true
}
}
}
The updateProfile mutation allows users to update their profile information.
- Input A
UserInputobject containing the updated profile information.
| Parameter | Type | Description |
|---|---|---|
| name | String | Represents the name of the user. |
| picUrl | String | Contains the URL of the user's picture. |
| String | Represents the email address of the user. | |
| phone | String | Represents the phone number of the user. |
- Output The
Userobject as described below
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the user. |
| name | String | Represents the name of the user. |
| picUrl | String | Contains the URL or path to the user's profile picture. |
| googleId | String | Represents the Google ID associated with the user. |
| facebookId | String | Represents the Facebook ID associated with the user. |
| String | Represents the email address of the user. | |
| emailVerified | Boolean | Indicates whether the user's email is verified. |
| phone | String | Represents the phone number of the user. |
| phoneVerified | Boolean | Indicates whether the user's phone number is verified. |
| createdAt | String | Represents the date and time when the user was created. |
| updatedAt | String | Represents the date and time when the user was last updated. |
My Profile
query myProfile {
myProfile {
_id
name
picUrl
email
emailVerified
phone
phoneVerified
}
}
The above code sample returns a JSON structured like this
{
"data": {
"updateProfile": {
"_id": "def456",
"name": "Jane Smith",
"picUrl": "https://example.com/new_profile.jpg",
"email": "jane@example.com",
"emailVerified": true,
"phone": "+1234567890",
"phoneVerified": true
}
}
}
The myProfile query allows a logged in user to get their profile information.
- Output A
Userobject containing the logged in user profile information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the user. |
| name | String | Represents the name of the user. |
| picUrl | String | Contains the URL or path to the user's profile picture. |
| googleId | String | Represents the Google ID associated with the user. |
| facebookId | String | Represents the Facebook ID associated with the user. |
| String | Represents the email address of the user. | |
| emailVerified | Boolean | Indicates whether the user's email is verified. |
| phone | String | Represents the phone number of the user. |
| phoneVerified | Boolean | Indicates whether the user's phone number is verified. |
| createdAt | String | Represents the date and time when the user was created. |
| updatedAt | String | Represents the date and time when the user was last updated. |
Find User
query findUser($id: String) {
findUser(userId: $id) {
_id
name
picUrl
email
emailVerified
phone
phoneVerified
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const FIND_USER_QUERY = gql`
query FindUser($id: String) {
findUser(userId: $id) {
_id
name
picUrl
email
emailVerified
phone
phoneVerified
}
}
`;
// Execute the query using ApolloClient
client
.query({
query: FIND_USER_QUERY,
variables: { id: 'YOUR_USER_ID' },
})
.then((result) => {
console.log(result.data.findUser);
})
.catch((error) => {});
The above code sample returns a JSON structured like this
{
"data": {
"updateProfile": {
"_id": "def456",
"name": "Jane Smith",
"picUrl": "https://example.com/new_profile.jpg",
"email": "jane@example.com",
"emailVerified": true,
"phone": "+1234567890",
"phoneVerified": true
}
}
}
The findUser query allows a logged in user to get their profile information.
- Input A
idstring that represents the unique identifier of the user you want to find. - Output A
Userobject containing the user's profile information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the user. |
| name | String | Represents the name of the user. |
| picUrl | String | Contains the URL or path to the user's profile picture. |
| googleId | String | Represents the Google ID associated with the user. |
| facebookId | String | Represents the Facebook ID associated with the user. |
| String | Represents the email address of the user. | |
| emailVerified | Boolean | Indicates whether the user's email is verified. |
| phone | String | Represents the phone number of the user. |
| phoneVerified | Boolean | Indicates whether the user's phone number is verified. |
| createdAt | String | Represents the date and time when the user was created. |
| updatedAt | String | Represents the date and time when the user was last updated. |
Find Users
query findUsers($filter: [FilterOption]) {
findUsers(options: $filter) {
_id
name
picUrl
email
emailVerified
phone
phoneVerified
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const FIND_USERS_QUERY = gql`
query FindUsers($filter: [FilterOption]) {
findUsers(options: $filter) {
_id
name
picUrl
email
emailVerified
phone
phoneVerified
}
}
`;
// Define the filter options
const filterOptions = [
// Define your filter options here
// Example: { key: "name", value: "John" }
];
// Execute the query using ApolloClient
client
.query({
query: FIND_USERS_QUERY,
variables: { filter: filterOptions },
})
.then((result) => {
console.log(result.data.findUsers);
})
.catch((error) => {});
The above code sample returns a JSON structured like this
[
{
"data": {
"updateProfile": {
"_id": "def456",
"name": "Jane Smith",
"picUrl": "https://example.com/new_profile.jpg",
"email": "jane@example.com",
"emailVerified": true,
"phone": "+1234567890",
"phoneVerified": true
}
}
}
]
The findUsers query allows a logged in user to get their profile information.
- Input An array of
FilterOptionobjects containing the fields to use to find users.
| Parameter | Type | Description |
|---|---|---|
| key | String | Represents the key or field to filter on. |
| dataType | FilterDataType | Enum for the data value: STRING, BOOLEAN, INT, FLOAT |
| stringValue | String | (optional) Represents the string value for filtering. |
| boolValue | Boolean | (optional) Represents the boolean value for filtering. |
| floatValue | Float | (optional) Represents the float value for filtering. |
- Output An array of
Userobjects containing the user profile information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the user. |
| name | String | Represents the name of the user. |
| picUrl | String | Contains the URL or path to the user's profile picture. |
| googleId | String | Represents the Google ID associated with the user. |
| facebookId | String | Represents the Facebook ID associated with the user. |
| String | Represents the email address of the user. | |
| emailVerified | Boolean | Indicates whether the user's email is verified. |
| phone | String | Represents the phone number of the user. |
| phoneVerified | Boolean | Indicates whether the user's phone number is verified. |
| createdAt | String | Represents the date and time when the user was created. |
| updatedAt | String | Represents the date and time when the user was last updated. |
Get Verification Code
mutation getVerificationCode($data: VerificationCode) {
getVerificationCode(data: $data)
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const GET_VERIFICATION_CODE_MUTATION = gql`
mutation GetVerificationCode($data: VerificationCode) {
getVerificationCode(data: $data)
}
`;
// Define the input data for the mutation
const verificationData = {
phone: '1234567890', // Example phone number
};
// Execute the GraphQL mutation using ApolloClient
client
.mutate({
mutation: GET_VERIFICATION_CODE_MUTATION,
variables: {
data: verificationData,
},
})
.then((response) => {
console.log('Verification code generated successfully');
})
.catch((error) => {
console.error('Error generating verification code:', error);
});
The above code sample returns
trueorfalseif a verification OTP code was sent via SMS
The getVerificationCode mutation is used to dispatch a verification code to a phone number to verify the identity of a user.
- Input A
VerificationCodeobject describing the payment details.
| Parameter | Type | Description |
|---|---|---|
| phone | String | the phone number to verify. Should include the country code |
- Output A
booleanvalue indication if verification code was sent via sms successfully.
Verify Phone
mutation verifyPhone($data: VerifyPhone) {
verifyPhone(data: $data)
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const VERIFY_PHONE_MUTATION = gql`
mutation VerifyPhone($data: VerifyPhone) {
verifyPhone(data: $data)
}
`;
// Define the input data for the mutation
const verificationData = {
phone: '1234567890', // Example phone number
code: '123456', // Example verification code
};
// Execute the GraphQL mutation using ApolloClient
client
.mutate({
mutation: VERIFY_PHONE_MUTATION,
variables: {
data: verificationData,
},
})
.then((response) => {
console.log('Phone verification successful');
})
.catch((error) => {
console.error('Error verifying phone:', error);
});
The above code sample returns
trueorfalseif a verification code was correct
The getVerificationCode mutation is used to dispatch a verification code to a phone number to verify the identity of a user.
- Input A
VerificationCodeobject describing the payment details.
| Parameter | Type | Description |
|---|---|---|
| phone | String | the phone number to verify. Should include the country code |
| code | String | the OTP code sent via SMS for verification purposes |
- Output A
booleanvalue indication if verification code was correct.
Outlets
This section describes the various object types, mutations and queries available for outlets in the GraphQL API
Add Outlet
mutation addOutlet($data: OutletInput) {
addOutlet(data: $data) {
_id
name
streetAddress
meals
features
type
openingTime
closingTime
minPrice
maxPrice
geolocation {
coordinates
}
menus {
_id
name
price
description
picture
}
reviews {
total
average
}
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache()
});
// Define the GraphQL mutation
const ADD_OUTLET_MUTATION = gql`
mutation AddOutlet($data: OutletInput) {
addOutlet(data: $data) {
_id
name
streetAddress
meals
features
type
openingTime
closingTime
minPrice
maxPrice
geolocation {
coordinates
}
menus {
_id
name
price
description
picture
}
reviews {
total
average
}
}
}
`;
// Define the outlet data object
const outletData = {
name: "My Outlet",
displayPicture: "https://example.com/menu_item_1.jpg"
streetAddress: "123 Main Street",
meals: ["Breakfast", "Lunch", "Dinner"],
features: ["12345", "67890"],
type: "Restaurant",
openingTime: "08:00 AM",
closingTime: "10:00 PM",
minPrice: 10,
maxPrice: 50,
geolocation: {
type: "Point",
coordinates: [10.2, 56.25]
}
};
// Execute the mutation using ApolloClient
client.mutate({
mutation: ADD_OUTLET_MUTATION,
variables: { data: outletData }
})
.then(result => { console.log( result.data.addOutlet);})
.catch(error => { });
The above code samples return a JSON structured like this:
{
"_id": "abc123",
"name": "Sample Outlet",
"displayPicture": "https://example.com/outlet_picture.jpg",
"geolocation": {
"latitude": 123.456,
"longitude": -78.91
},
"streetAddress": "123 Main Street",
"features": ["WiFi", "Outdoor Seating"],
"type": "Restaurant",
"openingTime": "08:00 AM",
"closingTime": "10:00 PM",
"meals": ["Breakfast", "Lunch", "Dinner"],
"menus": [],
"reviews": {
"total": 0,
"average": 0
},
"minPrice": 8,
"maxPrice": 30
}
This addOutlet mutation allows authenticated users to add a new outlet in the system.
- Input A
OutletInputobject containing the necessary data for adding a new outlet.
| Parameter | Type | Description |
|---|---|---|
| name | String | Represents the name of the outlet. |
| displayPicture | String | Contains the URL or path to the outlet's display picture. |
| geolocation | geoLocation | Represents the geographical coordinates of the outlet. |
| streetAddress | String | Represents the street address of the outlet. |
| features | [String] | Represents a list of features or amenities of the outlet. |
| type | String | Represents the type or category of the outlet. |
| openingTime | String | Represents the opening time of the outlet. |
| closingTime | String | Represents the closing time of the outlet. |
| meals | [String] | Represents a list of meals or food options available at the outlet. |
| minPrice | Int | Represents the minimum price range at the outlet. |
| maxPrice | Int | Represents the maximum price range at the outlet. |
| author | UserSummary | Represents a summary of the user who authored the outlet. |
- Output A
Outletobject containing the status of the sign-in attempt, an authentication token, and user information.
| Parameter | Type | Description |
|---|---|---|
| name | String | Represents the name of the outlet. |
| displayPicture | String | Contains the URL or path to the outlet's display picture. |
| geolocation | geoLocation | Represents the geographical coordinates of the outlet. |
| streetAddress | String | Represents the street address of the outlet. |
| features | [String] | Represents a list of features or amenities of the outlet. |
| type | String | Represents the type or category of the outlet. |
| openingTime | String | Represents the opening time of the outlet. |
| closingTime | String | Represents the closing time of the outlet. |
| meals | [String] | Represents a list of meals or food options available at the outlet. |
| isOpen | Boolean | Indicates whether the outlet is currently open. |
| isFavourite | Boolean | Indicates whether the outlet is marked as a favorite. |
| menus | [OutletMenu] | Represents a list of menus available at the outlet. |
| reviews | OutletReviewSummary | Represents a summary of reviews for the outlet. |
| minPrice | Int | Represents the minimum price range at the outlet. |
| maxPrice | Int | Represents the maximum price range at the outlet. |
| author | UserSummary | Represents a summary of the user who authored the outlet. |
| ownedBy | String | Represents the owner of the outlet. |
| createdBy | String | Represents the user who created the outlet. |
| createdAt | String | Represents the date and time when the outlet was created. |
| updatedAt | String | Represents the date and time when the outlet was last updated. |
Update Outlet
mutation updateOutlet($data: OutletInput) {
updateOutlet(data: $data) {
_id
name
streetAddress
meals
features
type
openingTime
closingTime
minPrice
maxPrice
geolocation {
coordinates
}
menus {
_id
name
price
description
picture
}
reviews {
total
average
}
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const UPDATE_OUTLET_MUTATION = gql`
mutation UpdateOutlet($data: OutletInput) {
updateOutlet(data: $data) {
_id
name
streetAddress
meals
features
type
openingTime
closingTime
minPrice
maxPrice
geolocation {
coordinates
}
menus {
_id
name
price
description
picture
}
reviews {
total
average
}
}
}
`;
// Define the outlet data object
const outletData = {
_id: 'abc123',
name: 'Updated Outlet',
streetAddress: '456 Oak Street',
meals: ['Breakfast', 'Lunch', 'Dinner'],
features: ['WiFi', 'Outdoor Seating'],
type: 'Cafe',
openingTime: '07:00 AM',
closingTime: '11:00 PM',
minPrice: 15,
maxPrice: 40,
geolocation: {
coordinates: [latitude, longitude],
},
};
// Execute the mutation using ApolloClient
client
.mutate({
mutation: UPDATE_OUTLET_MUTATION,
variables: { data: outletData },
})
.then((result) => {
console.log(result.data.updateOutlet);
})
.catch((error) => {
console.error('Error updating outlet:', error);
});
The above code samples return a JSON structured like this:
{
"_id": "abc123",
"name": "Sample Outlet",
"streetAddress": "123 Main Street",
"meals": ["Breakfast", "Lunch", "Dinner"],
"features": ["WiFi", "Outdoor Seating"],
"type": "Restaurant",
"openingTime": "08:00 AM",
"closingTime": "10:00 PM",
"minPrice": 10,
"maxPrice": 50,
"geolocation": {
"coordinates": [123.456, -78.91]
},
"menus": [
{
"_id": "menu1",
"name": "Menu Item 1",
"price": 10.99,
"description": "Description of Menu Item 1",
"picture": "https://example.com/menu_item_1.jpg"
},
{
"_id": "menu2",
"name": "Menu Item 2",
"price": 12.99,
"description": "Description of Menu Item 2",
"picture": "https://example.com/menu_item_2.jpg"
}
],
"reviews": {
"total": 50,
"average": 4.5
}
}
This updateOutlet mutation allows authenticated users to update information about an existing outlet
- Input A
OutletInputobject containing the necessary data for adding a new outlet.
| Parameter | Type | Description |
|---|---|---|
| name | String | Represents the name of the outlet. |
| displayPicture | String | Contains the URL or path to the outlet's display picture. |
| geolocation | geoLocation | Represents the geographical coordinates of the outlet. |
| streetAddress | String | Represents the street address of the outlet. |
| features | [String] | Represents a list of features or amenities of the outlet. |
| type | String | Represents the type or category of the outlet. |
| openingTime | String | Represents the opening time of the outlet. |
| closingTime | String | Represents the closing time of the outlet. |
| meals | [String] | Represents a list of meals or food options available at the outlet. |
| minPrice | Int | Represents the minimum price range at the outlet. |
| maxPrice | Int | Represents the maximum price range at the outlet. |
| author | UserSummary | Represents a summary of the user who authored the outlet. |
- Output A
Outletobject containing the status of the sign-in attempt, an authentication token, and user information.
| Parameter | Type | Description |
|---|---|---|
| name | String | Represents the name of the outlet. |
| displayPicture | String | Contains the URL or path to the outlet's display picture. |
| geolocation | geoLocation | Represents the geographical coordinates of the outlet. |
| streetAddress | String | Represents the street address of the outlet. |
| features | [String] | Represents a list of features or amenities of the outlet. |
| type | String | Represents the type or category of the outlet. |
| openingTime | String | Represents the opening time of the outlet. |
| closingTime | String | Represents the closing time of the outlet. |
| meals | [String] | Represents a list of meals or food options available at the outlet. |
| minPrice | Int | Represents the minimum price range at the outlet. |
| maxPrice | Int | Represents the maximum price range at the outlet. |
| author | UserSummary | Represents a summary of the user who authored the outlet. |
View Outlet
query viewOutlet($options: [FilterOption]) {
viewOutlet(options: $options) {
_id
name
displayPicture
streetAddress
type
meals
features
minPrice
maxPrice
isOpen
geolocation {
coordinates
}
menus {
_id
name
price
description
picture
}
reviews {
total
average
list {
_id
menuItem
price
rating
location
description
picture
}
}
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const VIEW_OUTLET_QUERY = gql`
query ViewOutlet($options: [FilterOption]) {
viewOutlet(options: $options) {
_id
name
displayPicture
streetAddress
type
meals
features
minPrice
maxPrice
isOpen
geolocation {
coordinates
}
menus {
_id
name
price
description
picture
}
reviews {
total
average
list {
_id
menuItem
price
rating
location
description
picture
}
}
}
}
`;
// Define the query filter options if needed
const filterOptions = [
// Define your filter options here if needed
// Example:
// { key: "name", dataType: "STRING", stringValue: "Outlet Name" }
];
// Execute the query using ApolloClient
client
.query({
query: VIEW_OUTLET_QUERY,
variables: { options: filterOptions },
})
.then((result) => {
// Handle the query result
console.log('Outlet details:', result.data.viewOutlet);
})
.catch((error) => {
// Handle any errors that occur during the query execution
console.error('Error fetching outlet details:', error);
});
The above code samples return a JSON structured like this:
{
"_id": "abc123",
"name": "Sample Outlet",
"displayPicture": "https://example.com/outlet_picture.jpg",
"streetAddress": "123 Main Street",
"type": "Restaurant",
"meals": ["Breakfast", "Lunch", "Dinner"],
"features": ["WiFi", "Outdoor Seating"],
"minPrice": 10,
"maxPrice": 50,
"isOpen": true,
"geolocation": {
"coordinates": [123.456, -78.910]
},
"menus": [
{
"_id": "menu1",
"name": "Menu Item 1",
"price": 10.99,
"description": "Description of Menu Item 1",
"picture": "https://example.com/menu_item_1.jpg"
},
...
],
"reviews": {
"total": 50,
"average": 4.5,
"list": [
{
"_id": "review1",
"menuItem": "Menu Item 1",
"price": 10.99,
"rating": 4.8,
"location": "Indoor",
"description": "Great food and atmosphere!",
"picture": "https://example.com/review_picture1.jpg"
},
...
]
}
}
This viewOutlet query allows (un)authenticated users to find an outlet based on some filtering options and view the master record of the outlet
- Input An array of
FilterOptionobjects containing the necessary fields to find an outet.
| Parameter | Type | Description |
|---|---|---|
| key | String | Represents the key used for filtering the data. |
| dataType | FilterDataType | Represents the data type of the filter value. |
| stringValue | String | (optional) Represents the string value used for filtering. |
| boolValue | Boolean | (optional) Represents the boolean value used for filtering. |
| floatValue | Float | (optional) Represents the float value used for filtering. |
- Output A
Outletobject containing the status of the sign-in attempt, an authentication token, and user information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the outlet. |
| name | String | Represents the name of the outlet. |
| displayPicture | String | Contains the URL of the outlet's display picture. |
| streetAddress | String | Represents the street address of the outlet. |
| type | String | Represents the type or category of the outlet. |
| meals | [String] | Represents the meals offered by the outlet. |
| features | [String] | Represents the features or amenities of the outlet. |
| minPrice | Int | Represents the minimum price range at the outlet. |
| maxPrice | Int | Represents the maximum price range at the outlet. |
| isOpen | Boolean | Indicates whether the outlet is currently open. |
| geolocation | GeoLocation | Represents the geographical coordinates of the outlet. |
| menus | [OutletMenu] | Represents the menu items offered by the outlet. |
| reviews | OutletReviewSummary | Represents the summary of reviews for the outlet. |
GeoLocation: Object containing the latitude and longitude coordinates of the outlet.coordinates: Array containing the latitude and longitude coordinates.
OutletMenu: Object representing a menu item offered by the outlet._id: String representing the unique identifier of the menu item.name: String representing the name of the menu item.price: Float representing the price of the menu item.description: String representing the description of the menu item.picture: String containing the URL of the menu item's picture.
OutletReviewSummary: Object representing the summary of reviews for the outlet.total: Int representing the total number of reviews for the outlet.average: Float representing the average rating of the reviews for the outlet.list: Array containing individual reviews for the outlet, each with the following fields:_id: String representing the unique identifier of the review.menuItem: String representing the name of the menu item reviewed.price: Float representing the price of the menu item reviewed.rating: Float representing the rating given in the review.location: String representing the location where the review was made.description: String representing the description of the review. picture: String containing the URL of the review picture.
Find Outlets
query findOutlets($query: OutletFilterInput) {
findOutlets(query: $query) {
_id
reviews {
total
average
}
isOpen
name
displayPicture
minPrice
maxPrice
type
geolocation {
coordinates
}
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache()
});
// Define the GraphQL query
const FIND_OUTLETS_QUERY = gql`
query FindOutlets($query: OutletFilterInput) {
findOutlets(query: $query) {
_id
reviews {
total
average
}
isOpen
name
displayPicture
minPrice
maxPrice
type
geolocation {
coordinates
}
}
}
`;
// Define the query filter input object
const queryFilter = {
types: ["restaurant"],
meals: ["breakfast", "lunch"],
features: ["indoor"],
minPrice: 100
maxPrice: 350
coords: [12.5, 51.2]
term: "githeri"
}
// Execute the query using ApolloClient
client.query({
query: FIND_OUTLETS_QUERY,
variables: { query: queryFilter }
})
.then(result => { console.log(result.data.findOutlets)})
.catch(error => {});
The above code samples return a JSON structured like this:
{
"data": {
"findOutlets": [
{
"_id": "outlet1",
"reviews": {
"total": 50,
"average": 4.5
},
"isOpen": true,
"name": "Sample Outlet 1",
"displayPicture": "https://example.com/outlet1_picture.jpg",
"minPrice": 10,
"maxPrice": 50,
"type": "Restaurant",
"geolocation": {
"coordinates": [123.456, -78.91]
}
}
]
}
}
This findOutlets query allows (un)authenticated users to find a list outlets based on defined criteria
- Input An array of
OutletFilterInputobjects containing the necessary fields to find an outlet.
| Parameter | Type | Description |
|---|---|---|
| types | [String] | Represents the types of outlets to filter by. |
| meals | [String] | Represents the meals offered by the outlets. |
| features | [String] | Represents the features available at the outlets. |
| minPrice | Float | Represents the minimum price of the outlets. |
| maxPrice | Float | Represents the maximum price of the outlets. |
| coords | [Float] | Represents the coordinates for location-based filtering. |
| term | String | Represents the search term for text-based filtering. |
- Output An array
Outletobjects matching the filter contraints provided.
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the outlet. |
| name | String | Represents the name of the outlet. |
| displayPicture | String | Contains the URL of the outlet's display picture. |
| streetAddress | String | Represents the street address of the outlet. |
| type | String | Represents the type or category of the outlet. |
| meals | [String] | Represents the meals offered by the outlet. |
| features | [String] | Represents the features or amenities of the outlet. |
| minPrice | Int | Represents the minimum price range at the outlet. |
| maxPrice | Int | Represents the maximum price range at the outlet. |
| isOpen | Boolean | Indicates whether the outlet is currently open. |
| geolocation | GeoLocation | Represents the geographical coordinates of the outlet. |
| menus | [OutletMenu] | Represents the menu items offered by the outlet. |
| reviews | OutletReviewSummary | Represents the summary of reviews for the outlet. |
GeoLocation: Object containing the latitude and longitude coordinates of the outlet.coordinates: Array containing the latitude and longitude coordinates.
OutletReviewSummary: Object representing the summary of reviews for the outlet.total: Int representing the total number of reviews for the outlet.average: Float representing the average rating of the reviews for the outlet.
Add Menu Item
mutation addOutletMenuItem($id: String, $data: OutletMenuInput) {
addOutletMenuItem(id: $id, data: $data) {
_id
name
streetAddress
meals
features
type
openingTime
closingTime
minPrice
maxPrice
menus {
_id
name
price
description
picture
}
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const ADD_OUTLET_MENU_ITEM_MUTATION = gql`
mutation AddOutletMenuItem($id: String, $data: OutletMenuInput) {
addOutletMenuItem(id: $id, data: $data) {
_id
name
streetAddress
meals
features
type
openingTime
closingTime
minPrice
maxPrice
menus {
_id
name
price
description
picture
}
}
}
`;
// Define the outlet ID and outlet menu item data
const outletId = 'your_outlet_id';
const outletMenuItemData = {
outletId: 'your_outlet_id',
name: 'New Menu Item',
picture: 'https://example.com/menu_item_picture.jpg',
price: 1299,
description: 'Description of the new menu item',
};
// Execute the mutation using ApolloClient
client
.mutate({
mutation: ADD_OUTLET_MENU_ITEM_MUTATION,
variables: { id: outletId, data: outletMenuItemData },
})
.then((result) => {
console.log(result.data.addOutletMenuItem);
})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"addOutletMenuItem": {
"_id": "menu_item_id",
"name": "New Menu Item",
"streetAddress": "123 Main Street",
"meals": ["Lunch", "Dinner"],
"features": ["Outdoor Seating", "WiFi"],
"type": "Restaurant",
"openingTime": "11:00 AM",
"closingTime": "10:00 PM",
"minPrice": 5,
"maxPrice": 30,
"menus": [
{
"_id": "menu1",
"name": "Menu Item 1",
"price": 10.99,
"description": "Description of Menu Item 1",
"picture": "https://example.com/menu_item_1.jpg"
},
{
"_id": "menu2",
"name": "Menu Item 2",
"price": 12.99,
"description": "Description of Menu Item 2",
"picture": "https://example.com/menu_item_2.jpg"
}
]
}
}
}
This addOutletMenuItem mutation allows authenticated users to add a menu item to an outlet
- Input An
OutletMenuInputobject containing the data describing the menu item
| Parameter | Type | Description |
|---|---|---|
| outletId | String | The ID of the outlet the menu belongs to. |
| name | String | The name of the menu. |
| picture | String | The URL or path to the picture of the menu. |
| price | Int | The price of the menu. |
| description | String | The description of the menu. |
- Output A
Outletobject with the updated menu information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the outlet. |
| name | String | Represents the name of the outlet. |
| displayPicture | String | Contains the URL of the outlet's display picture. |
| streetAddress | String | Represents the street address of the outlet. |
| type | String | Represents the type or category of the outlet. |
| meals | [String] | Represents the meals offered by the outlet. |
| features | [String] | Represents the features or amenities of the outlet. |
| minPrice | Int | Represents the minimum price range at the outlet. |
| maxPrice | Int | Represents the maximum price range at the outlet. |
| menus | [OutletMenu] | Represents the menu items offered by the outlet. |
OutletMenu: Object containing the latitude and longitude coordinates of the outlet.name- The name of the menu.picture- The URL or path to the picture of the menu.price- The price of the menu.description- The description of the menu.
Reviews
Add Review
mutation addOutletReview($data: OutletReviewInput) {
addOutletReview(data: $data) {
_id
rating
description
price
menuItem
location
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const ADD_OUTLET_REVIEW_MUTATION = gql`
mutation AddOutletReview($data: OutletReviewInput) {
addOutletReview(data: $data) {
_id
rating
description
price
menuItem
location
}
}
`;
// Define the outlet review data
const outletReviewData = {
description: 'Great food and atmosphere!',
rating: 4,
menuItem: 'Menu Item 1',
price: 10.99,
picture: 'https://example.com/review_picture.jpg',
location: 'Indoor',
outletId: 'outlet1',
};
// Execute the mutation using ApolloClient
client
.mutate({
mutation: ADD_OUTLET_REVIEW_MUTATION,
variables: { data: outletReviewData },
})
.then((result) => {
console.log(result.data.addOutletReview);
})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"addOutletReview": {
"_id": "review1",
"description": "Great food and atmosphere!",
"rating": 4,
"menuItem": "Menu Item 1",
"price": 10.99,
"picture": "https://example.com/review_picture.jpg",
"location": "Indoor"
}
}
}
This addOutletReview mutation allows authenticated users to review an outlet
- Input An
OutletReviewInputobject containing the data describing the review
| Parameter | Type | Description |
|---|---|---|
| description | String | The description or comment for the outlet review. |
| rating | Int | The rating given to the outlet, usually on a scale. |
| menuItem | String | The name of the menu item being reviewed. |
| price | Float | The price of the menu item being reviewed. |
| picture | String | The URL or path to the picture of the review. |
| location | String | The location of the outlet being reviewed. |
| outletId | String | The ID of the outlet being reviewed. |
- Output A
Outletobject with the updated menu information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet review. |
| outletId | String | The ID of the outlet being reviewed. |
| outletName | String | The name of the outlet being reviewed. |
| description | String | The description or comment for the outlet review. |
| rating | Int | The rating given to the outlet review. |
| menuItem | String | The name of the menu item being reviewed. |
| price | Float | The price of the menu item being reviewed. |
| picture | String | The URL or path to the picture of the review. |
| location | String | The location of the outlet being reviewed. |
| createdBy | String | The user who created the outlet review. |
| createdAt | String | The date and time when the outlet review was created. |
| updatedAt | String | The date and time when the outlet review was updated. |
Outlet Reviews
query findOutletReviews($options: [FilterOption]) {
findOutletReviews(options: $options) {
_id
menuItem
price
rating
location
description
picture
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const FIND_OUTLET_REVIEWS_QUERY = gql`
query FindOutletReviews($options: [FilterOption]) {
findOutletReviews(options: $options) {
_id
menuItem
price
rating
location
description
picture
}
}
`;
// Define the query filter options
const filterOptions = [
// Define your filter options here if needed
// Example:
// { key: "rating", dataType: "FLOAT", floatValue: 4.5 }
];
// Execute the query using ApolloClient
client
.query({
query: FIND_OUTLET_REVIEWS_QUERY,
variables: { options: filterOptions },
})
.then((result) => {
console.log(result.data.findOutletReviews);
})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"findOutletReviews": [
{
"_id": "review1",
"menuItem": "Menu Item 1",
"price": 10.99,
"rating": 4.5,
"location": "Indoor",
"description": "Great food and atmosphere!",
"picture": "https://example.com/review1_picture.jpg"
},
{
"_id": "review2",
"menuItem": "Menu Item 2",
"price": 12.99,
"rating": 4.2,
"location": "Outdoor",
"description": "Excellent service and tasty food!",
"picture": "https://example.com/review2_picture.jpg"
}
]
}
}
This findOutletReviews query allows (un)authenticated users to search for outlet reviews
- Input An
FilterOptionobject containing the data describing the review
| Parameter | Type | Description |
|---|---|---|
| key | String | Represents the key used for filtering the data. |
| dataType | FilterDataType | Represents the data type of the filter value. |
| stringValue | String | (optional) Represents the string value used for filtering. |
| boolValue | Boolean | (optional) Represents the boolean value used for filtering. |
| floatValue | Float | (optional) Represents the float value used for filtering. |
- Output A
Outletobject with the updated menu information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet review. |
| outletId | String | The ID of the outlet being reviewed. |
| outletName | String | The name of the outlet being reviewed. |
| description | String | The description or comment for the outlet review. |
| rating | Int | The rating given to the outlet review. |
| menuItem | String | The name of the menu item being reviewed. |
| price | Float | The price of the menu item being reviewed. |
| picture | String | The URL or path to the picture of the review. |
| location | String | The location of the outlet being reviewed. |
| createdBy | String | The user who created the outlet review. |
| createdAt | String | The date and time when the outlet review was created. |
| updatedAt | String | The date and time when the outlet review was updated. |
Most Rated Outlets
query mostRatedOutlets {
mostRatedOutlets {
_id
reviews {
total
average
}
isOpen
name
displayPicture
minPrice
maxPrice
type
geolocation {
coordinates
}
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const MOST_RATED_OUTLETS_QUERY = gql`
query MostRatedOutlets {
mostRatedOutlets {
_id
reviews {
total
average
}
isOpen
name
displayPicture
minPrice
maxPrice
type
geolocation {
coordinates
}
}
}
`;
// Execute the query using ApolloClient
client
.query({
query: MOST_RATED_OUTLETS_QUERY,
})
.then((result) => {
console.log(result.data.mostRatedOutlets);
})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"mostRatedOutlets": [
{
"_id": "outlet1",
"reviews": {
"total": 50,
"average": 4.5
},
"isOpen": true,
"name": "Outlet 1",
"displayPicture": "https://example.com/outlet1_picture.jpg",
"minPrice": 10,
"maxPrice": 50,
"type": "Restaurant",
"geolocation": {
"coordinates": [0.1289792, 35,897987]
}
}
]
}
}
This mostRatedOutlets query allows (un)authenticated users to access the list of most rated outlets
- Output An array of
Outletobjects containing the data describing the outlet
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet. |
| reviews | Object | Object containing information about outlet reviews. |
| - total | Int | The total number of reviews for the outlet. |
| - average | Float | The average rating of the outlet based on reviews. |
| isOpen | Boolean | Indicates whether the outlet is open or closed. |
| name | String | The name of the outlet. |
| displayPicture | String | The URL or path to the display picture of the outlet. |
| minPrice | Int | The minimum price range of the outlet. |
| maxPrice | Int | The maximum price range of the outlet. |
| type | String | The type or category of the outlet (e.g., restaurant). |
| geolocation | geoLocation | Represents the geographical coordinates of the outlet. |
Options
Add Outlet Option
mutation addOutletOption($data: OutletOptionInput) {
addOutletOption(data: $data) {
_id
name
icon
description
class
createdBy
createdAt
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const ADD_OUTLET_OPTION_MUTATION = gql`
mutation AddOutletOption($data: OutletOptionInput) {
addOutletOption(data: $data) {
_id
name
icon
description
class
createdBy
createdAt
}
}
`;
// Define the outlet option data
const outletOptionData = {
name: 'Outdoor Seating',
icon: 'https://example.com/outdoor_icon.png',
class: 'outdoor-option',
description: 'Outdoor seating available',
};
// Execute the mutation using ApolloClient
client
.mutate({
mutation: ADD_OUTLET_OPTION_MUTATION,
variables: { data: outletOptionData },
})
.then((result) => {
console.log(result.data.addOutletOption);
})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"addOutletOption": {
"_id": "option1",
"name": "Outdoor Seating",
"icon": "https://example.com/outdoor_icon.png",
"class": "outdoor-option",
"description": "Outdoor seating available",
"createdBy": "user123",
"createdAt": "2022-05-10T12:30:45Z"
}
}
}
This addOutletOption mutation allows administrative users to add various options for outlets
- Input An
OutletOptionInputobject containing the data describing the option
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet option. |
| name | String | The name of the outlet option. |
| icon | String | The URL or path to the icon representing the option. |
| class | String | The type of option being added |
| description | String | The description of the outlet option. |
- Output A
OutletOptionobject representing the added option.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet option. |
| name | String | The name of the outlet option. |
| icon | String | The URL or path to the icon representing the option. |
| class | String | The CSS class associated with the outlet option. |
| description | String | The description of the outlet option. |
| createdBy | String | The user who created the outlet option. |
| createdAt | String | The date and time when the outlet option was created. |
| updatedAt | String | The date and time when the outlet option was last updated. |
View Outlet Options
query viewOutletOptions($options: [FilterOption]) {
viewOutletOptions(options: $options) {
_id
name
class
icon
description
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const VIEW_OUTLET_OPTIONS_QUERY = gql`
query ViewOutletOptions($options: [FilterOption]) {
viewOutletOptions(options: $options) {
_id
name
class
icon
description
}
}
`;
// Define the query filter options if needed
const filterOptions = [
// Define your filter options here if needed
// Example:
// { key: "class", dataType: "STRING", stringValue: "xyz" }
];
// Execute the query using ApolloClient
client
.query({
query: VIEW_OUTLET_OPTIONS_QUERY,
variables: { options: filterOptions },
})
.then((result) => {
console.log(result.data.viewOutletOptions);
})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"viewOutletOptions": [
{
"_id": "option1",
"name": "Outdoor Seating",
"class": "outdoor-option",
"icon": "https://example.com/outdoor_icon.png",
"description": "Outdoor seating available"
},
{
"_id": "option2",
"name": "WiFi",
"class": "wifi-option",
"icon": "https://example.com/wifi_icon.png",
"description": "Free WiFi available"
}
]
}
}
This viewOutletOptions query allows (un)authenticated users to view outlet options based on defined criteria
- Input An
FilterOptionobject containing the data describing the review
| Parameter | Type | Description |
|---|---|---|
| key | String | Represents the key used for filtering the data. |
| dataType | FilterDataType | Represents the data type of the filter value. |
| stringValue | String | (optional) Represents the string value used for filtering. |
| boolValue | Boolean | (optional) Represents the boolean value used for filtering. |
| floatValue | Float | (optional) Represents the float value used for filtering. |
- Output A
OutletOptionobject with the updated menu information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet option. |
| name | String | The name of the outlet option. |
| icon | String | The URL or path to the icon representing the option. |
| class | String | The CSS class associated with the outlet option. |
| description | String | The description of the outlet option. |
| createdBy | String | The user who created the outlet option. |
| createdAt | String | The date and time when the outlet option was created. |
| updatedAt | String | The date and time when the outlet option was last updated. |
Update Outlet Option
mutation updateOutletOption($data: OutletOptionInput) {
updateOutletOption(data: $data) {
_id
name
icon
description
class
createdBy
createdAt
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const UPDATE_OUTLET_OPTION_MUTATION = gql`
mutation UpdateOutletOption($data: OutletOptionInput) {
updateOutletOption(data: $data) {
_id
name
icon
description
class
createdBy
createdAt
}
}
`;
// Define the outlet option data
const outletOptionData = {
// Define your updated outlet option data here
// Example:
_id: 'option1',
name: 'Updated Outdoor Seating',
icon: 'https://example.com/updated_outdoor_icon.png',
description: 'Updated outdoor seating available',
class: 'outdoor-option',
};
// Execute the mutation using ApolloClient
client
.mutate({
mutation: UPDATE_OUTLET_OPTION_MUTATION,
variables: { data: outletOptionData },
})
.then((result) => {
// Handle the mutation result
console.log(result.data.updateOutletOption);
})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"updateOutletOption": {
"_id": "option1",
"name": "Updated Outdoor Seating",
"icon": "https://example.com/updated_outdoor_icon.png",
"description": "Updated description for Outdoor Seating",
"class": "updated-outdoor-option",
"createdBy": "user123",
"createdAt": "2022-05-12T09:45:32Z"
}
}
}
This updateOutletOption query allows administrative users to update the outlet options
- Input An
OutletOptionInputobject containing the data describing the option
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet option. |
| name | String | The name of the outlet option. |
| icon | String | The URL or path to the icon representing the option. |
| class | String | The type of option being added |
| description | String | The description of the outlet option. |
- Output A
OutletOptionobject with the updated menu information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet option. |
| name | String | The name of the outlet option. |
| icon | String | The URL or path to the icon representing the option. |
| class | String | The CSS class associated with the outlet option. |
| description | String | The description of the outlet option. |
| createdBy | String | The user who created the outlet option. |
| createdAt | String | The date and time when the outlet option was created. |
| updatedAt | String | The date and time when the outlet option was last updated. |
Likes
Like Outlet
mutation favouriteOutlet($id: String) {
favouriteOutlet(id: $id)
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const FAVOURITE_OUTLET_MUTATION = gql`
mutation FavouriteOutlet($id: String) {
favouriteOutlet(id: $id)
}
`;
// Define the outlet ID to be marked as favourite
const outletId = 'your_outlet_id';
// Execute the mutation using ApolloClient
client
.mutate({
mutation: FAVOURITE_OUTLET_MUTATION,
variables: { id: outletId },
})
.then((result) => {
// Handle the mutation result
console.log(result.data.favouriteOutlet);
})
.catch((error) => {});
The above code samples return a JSON structured like this:
{
"data": {
"favouriteOutlet": true
}
}
This favouriteOutlet query allows authenticated users to toggle if they like an outlet or not
Input the
idof the outlet the user wants to toggle if they like it or notOutput A boolean value indicating if they like or unliked the outlet.
Liked Outlets
query findFavouriteOutlets {
findFavouriteOutlets {
_id
name
displayPicture
type
features
meals
minPrice
maxPrice
isOpen
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const FIND_FAVOURITE_OUTLETS_QUERY = gql`
query FindFavouriteOutlets {
findFavouriteOutlets {
_id
name
displayPicture
type
features
meals
minPrice
maxPrice
isOpen
}
}
`;
// Execute the query using ApolloClient
client
.query({
query: FIND_FAVOURITE_OUTLETS_QUERY,
})
.then((result) => {
// Handle the query result
console.log('Favourite outlets:', result.data.findFavouriteOutlets);
})
.catch((error) => {
// Handle any errors that occur during the query execution
console.error('Error fetching favourite outlets:', error);
});
The above code samples return a JSON structured like this:
{
"data": {
"findFavouriteOutlets": [
{
"_id": "outlet1",
"name": "Favourite Outlet 1",
"displayPicture": "https://example.com/outlet1_picture.jpg",
"type": "Restaurant",
"features": ["Outdoor Seating", "Free WiFi"],
"meals": ["Breakfast", "Lunch", "Dinner"],
"minPrice": 10,
"maxPrice": 50,
"isOpen": true
},
{
"_id": "outlet2",
"name": "Favourite Outlet 2",
"displayPicture": "https://example.com/outlet2_picture.jpg",
"type": "Cafe",
"features": ["Free WiFi"],
"meals": ["Breakfast", "Lunch"],
"minPrice": 8,
"maxPrice": 40,
"isOpen": false
}
]
}
}
This findFavouriteOutlets query allows authenticated users to view the list of outlets they liked
- Output A
Outletobject with the information of outlets the user likes.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet. |
| name | String | The name of the outlet. |
| displayPicture | String | The URL or path to the display picture of the outlet. |
| type | String | The type or category of the outlet (e.g., restaurant). |
| features | Array | An array of strings representing features offered by the outlet. |
| meals | Array | An array of strings representing types of meals served by the outlet. |
| minPrice | Int | The minimum price range offered by the outlet. |
| maxPrice | Int | The maximum price range offered by the outlet. |
| isOpen | Boolean | Indicates whether the outlet is currently open. |
Most Liked Outlets
query mostLikedOutlets {
mostLikedOutlets {
_id
reviews {
total
average
}
isOpen
name
displayPicture
minPrice
maxPrice
type
geolocation {
coordinates
}
}
}
// Import necessary modules
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'YOUR_GRAPHQL_ENDPOINT_URL',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const MOST_LIKED_OUTLETS_QUERY = gql`
query MostLikedOutlets {
mostLikedOutlets {
_id
reviews {
total
average
}
isOpen
name
displayPicture
minPrice
maxPrice
type
geolocation {
coordinates
}
}
}
`;
// Execute the query using ApolloClient
client
.query({
query: MOST_LIKED_OUTLETS_QUERY,
})
.then((result) => {
// Handle the query result
console.log('Most liked outlets:', result.data.mostLikedOutlets);
})
.catch((error) => {
// Handle any errors that occur during the query execution
console.error('Error fetching most liked outlets:', error);
});
The above code samples return a JSON structured like this:
{
"data": {
"mostLikedOutlets": [
{
"_id": "outlet1",
"reviews": {
"total": 50,
"average": 4.5
},
"isOpen": true,
"name": "Outlet 1",
"displayPicture": "https://example.com/outlet1_picture.jpg",
"minPrice": 10,
"maxPrice": 50,
"type": "Restaurant",
"geolocation": {
"coordinates": [0.1289792, 35,897987]
}
},
{
"_id": "outlet2",
"reviews": {
"total": 30,
"average": 4.2
},
"isOpen": false,
"name": "Outlet 2",
"displayPicture": "https://example.com/outlet2_picture.jpg",
"minPrice": 8,
"maxPrice": 40,
"type": "Cafe",
"geolocation": {
"coordinates": [0.1289792, 35,897987]
}
}
]
}
}
This mostLikedOutlets query allows users to access a list of the most liked outlets
- Output A
Outletobject with the updated menu information.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet. |
| reviews | Object | Object containing information about outlet reviews. |
| - total | Int | The total number of reviews for the outlet. |
| - average | Float | The average rating of the outlet based on reviews. |
| isOpen | Boolean | Indicates whether the outlet is open or closed. |
| name | String | The name of the outlet. |
| displayPicture | String | The URL or path to the display picture of the outlet. |
| minPrice | Int | The minimum price range offered by the outlet. |
| maxPrice | Int | The maximum price range offered by the outlet. |
| type | String | The type or category of the outlet (e.g., restaurant). |
| geolocation | geoLocation | Represents the geographical coordinates of the outlet. |
Ownership
This section defines the various functionalities for a user claiming ownership of a registered outlet.
Claim Outlet
mutation claimOutlet($id: String, $data: ClaimOutletInput) {
claimOutlet(id: $id, data: $data)
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const CLAIM_OUTLET_MUTATION = gql`
mutation ClaimOutlet($id: String, $data: ClaimOutletInput) {
claimOutlet(id: $id, data: $data)
}
`;
// Define the input data for the mutation
const claimData = {
name: 'Claimed Outlet Name',
location: '123 Claimed Street',
phone: '123-456-7890',
document: 'Claim Document Base64 data',
};
// Execute the GraphQL mutation using ApolloClient
client
.mutate({
mutation: CLAIM_OUTLET_MUTATION,
variables: {
id: 'your_outlet_id',
data: claimData,
},
})
.then((response) => {
console.log('Outlet claimed successfully:', response);
})
.catch((error) => {
console.error('Error claiming outlet:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"claimOutlet": {
"geolocation": {
"type": "Point",
"coordinates": [-1.2656889999999998, 36.804997799999995]
},
"_id": "65ef1f5608c95845c964f3c1",
"name": "ADVACAFE RESTAURANT",
"displayPicture": "https://lookaside.fbsbx.com/lookaside/crawler/media/?media_id=362149252592333",
"streetAddress": "Westlands Road Crossway Soin Shopping Arcade, Ground Floor",
"type": "63e39d4003c7f3fa60ec7f4b",
"features": [
"63e39d4d03c7f3fa60ec7f4e",
"63e39dde03c7f3fa60ec7f60",
"63e39d6c03c7f3fa60ec7f57",
"63e39dbe03c7f3fa60ec7f5d",
"63e39d5703c7f3fa60ec7f51"
],
"meals": ["63e39e0503c7f3fa60ec7f63"],
"menus": [
{
"_id": "65ef1eba08c95845c964f16c",
"name": "Chicken Burger",
"picture": "https://www.kitchensanctuary.com/wp-content/uploads/2019/08/Crispy-Chicken-Burger-square-FS-4518.jpg",
"price": 900,
"description": "Rerum qui pariatur non ratione optio exercitationem. Et voluptas illum sunt et.",
"createdBy": "65ef1b8e7830e2c6e3092ce3",
"archived": true,
"createdAt": "2024-03-11T15:12:22.422Z",
"updatedAt": "2024-03-11T15:12:22.422Z"
}
],
"openingTime": "10:00",
"closingTime": "20:00",
"minPrice": 150,
"maxPrice": 1000,
"createdBy": "65ef1b337830e2c6e3092cdd",
"archived": false,
"createdAt": "2024-03-11T15:12:22.423Z",
"updatedAt": "2024-03-11T15:12:22.423Z",
"__v": 0,
"verificationDetails": {
"name": "ADVACAFE RESTAURANT",
"location": "Here and There 3",
"phone": "+254711304589",
"document": "https://klurdy-stores.s3.eu-west-2.amazonaws.com/outlets/65ef1f5608c95845c964f3c1/ownership/6626488a5c0a0b69e9edf9a7",
"user": "65ef1bce7830e2c6e3092ce7"
},
"verified": 1
}
}
}
This claimOutlet mutation allows authenticated users to claim ownereship to a registered outlet.
- Input An
idof the outlet and the documents used to apply for ownership as shown below.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the claimed outlet. |
| location | String | The location or address of the outlet. |
| phone | String | A verified phone number of the user to link to the outlet. |
| document | String | A base64 photo fo the document (e.g., business license) associated with the claimed outlet. |
Pending Approvals
query findOutletApprovals {
findOutletApprovals {
_id
name
location
document
phone
user
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const FIND_OUTLET_APPROVALS_QUERY = gql`
query FindOutletApprovals {
findOutletApprovals {
_id
name
location
document
phone
user
}
}
`;
// Execute the GraphQL query using ApolloClient
client
.query({
query: FIND_OUTLET_APPROVALS_QUERY,
})
.then((response) => {
console.log(response.data.findOutletApprovals);
})
.catch((error) => {
console.error('Error fetching outlet approvals:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"findOutletApprovals": [
{
"_id": "1",
"name": "Outlet A",
"location": "123 Main Street",
"document": "Business License",
"phone": "123-456-7890",
"user": "user_id_1"
}
]
}
}
The claimOutlet mutation creates a request for the logged in user to claim ownership of a registered outlet.
- Input A
OutletClaimobject with ownership details.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the claimed outlet. |
| location | String | The location or address of the outlet. |
| phone | String | A verified phone number of the user to link to the outlet. |
| document | String | A base64 photo fo the document (e.g., business license) associated with the claimed outlet. |
- Output An
Outletobject.
Approve Ownership
mutation approveOutlet($id: String, $status: Boolean) {
approveOutlet(id: $id, status: $status) {
_id
name
location
document
phone
user
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const APPROVE_OUTLET_MUTATION = gql`
mutation ApproveOutlet($id: String, $status: Boolean) {
approveOutlet(id: $id, status: $status) {
_id
name
location
document
phone
user
}
}
`;
// Execute the GraphQL mutation using ApolloClient
client
.mutate({
mutation: APPROVE_OUTLET_MUTATION,
variables: {
id: 'your_outlet_id',
status: true, // Set the status to true to approve the outlet
},
})
.then((response) => {
console.log('Outlet approved successfully:', response);
})
.catch((error) => {
console.error('Error approving outlet:', error);
});
The above code sample returns a JSON structured like this, an updated list of outlets to approve
{
"data": {
"approveOutlet": [
{
"_id": "1",
"name": "Outlet A",
"location": "123 Main Street",
"document": "Business License",
"phone": "123-456-7890",
"user": "user_id_1"
}
]
}
}
The approveOutlet mutation creates a request for the logged in user to claim ownership of a registered outlet.
Input A
idof the claim request and thestatusof whether to approve or deny (true or false).Outlet An updated list of
OutletApprovalstill pending.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet claim request. |
| name | String | The name of the claimed outlet. |
| location | String | The location or address of the outlet. |
| phone | String | A verified phone number of the user to link to the outlet. |
| document | String | A base64 photo fo the document (e.g., business license) associated with the claimed outlet. |
My Outlets
query myOutlets {
myOutlets {
_id
name
displayPicture
features
type
verified
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const MY_OUTLETS_QUERY = gql`
query MyOutlets {
myOutlets {
_id
name
displayPicture
features
type
verified
}
}
`;
// Execute the GraphQL query using ApolloClient
client
.query({
query: MY_OUTLETS_QUERY,
})
.then((response) => {
console.log('My outlets:', response.data.myOutlets);
})
.catch((error) => {
console.error('Error fetching my outlets:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"myOutlets": [
{
"_id": "1",
"name": "Outlet A",
"displayPicture": "https://example.com/outlet_a.jpg",
"features": ["Feature 1", "Feature 2"],
"type": "Restaurant",
"verified": true
}
]
}
}
The myOutlets query retrieves a list of outlets owned by the user after verification process.
- Output An array of
Outletobjects belonging to the logged in user.
| Parameter | Type | Description |
|---|---|---|
| _id | String | Represents the unique identifier of the outlet. |
| name | String | Represents the name of the outlet. |
| displayPicture | String | Contains the URL of the outlet's display picture. |
| streetAddress | String | Represents the street address of the outlet. |
| type | String | Represents the type or category of the outlet. |
| meals | [String] | Represents the meals offered by the outlet. |
| features | [String] | Represents the features or amenities of the outlet. |
| minPrice | Int | Represents the minimum price range at the outlet. |
| maxPrice | Int | Represents the maximum price range at the outlet. |
| isOpen | Boolean | Indicates whether the outlet is currently open. |
| geolocation | GeoLocation | Represents the geographical coordinates of the outlet. |
| menus | [OutletMenu] | Represents the menu items offered by the outlet. |
| reviews | OutletReviewSummary | Represents the summary of reviews for the outlet. |
GeoLocation: Object containing the latitude and longitude coordinates of the outlet.coordinates: Array containing the latitude and longitude coordinates.
OutletReviewSummary: Object representing the summary of reviews for the outlet.total: Int representing the total number of reviews for the outlet.average: Float representing the average rating of the reviews for the outlet.
Sponsored Ads
This section covers all the queries, mutations and data objects for engaging with sponsored ads.
Create Ad
mutation createOutletAd($data: OutletAdInput) {
createOutletAd(data: $data) {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const CREATE_OUTLET_AD_MUTATION = gql`
mutation CreateOutletAd($data: OutletAdInput) {
createOutletAd(data: $data) {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
`;
// Define the input data for the mutation
const adData = {
outletId: 'your_outlet_id',
dailyBudget: 100,
displayUrl: 'https://example.com/ad_image.jpg',
displayText: 'Special Offer!',
duration: 30, // in days
time: [1, 2], // 1 - morning, 2 - lunch, 3 - evening
};
// Execute the GraphQL mutation using ApolloClient
client
.mutate({
mutation: CREATE_OUTLET_AD_MUTATION,
variables: {
data: adData,
},
})
.then((response) => {
console.log(
'Outlet ad created successfully:',
response.data.createOutletAd
);
})
.catch((error) => {
console.error('Error creating outlet ad:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"createOutletAd": {
"_id": "ad_id",
"outletId": "outlet_id",
"dailyBudget": 100,
"displayUrl": "https://example.com/ad_image.jpg",
"displayText": "Special Offer!",
"duration": 30,
"time": "2022-04-29T12:00:00Z",
"views": [
{
"date": "2022-05-01",
"count": 100
}
],
"clicks": [
{
"date": "2022-05-01",
"count": 10
}
],
"paid": true,
"activeUntil": "2022-05-29T12:00:00Z"
}
}
}
This createOutletAd mutation allows a user owning one or more outlets to create ads in the platform.
Input An OutletAdInput object defining the ad parameters.
| Parameter | Type | Description |
|---|---|---|
| dailyBudget | Int | The daily budget for the outlet ad. |
| displayUrl | String | The URL of the image for the ad display. |
| displayText | String | The text to display in the ad. |
| duration | Int | The duration of the ad (in days). |
| time | [Int] | An array of integers representing the time slots when the ad will be displayed. |
| outletId | String | The ID of the outlet associated with the ad. |
| coords | [Float] | An array of floats representing the coordinates of the outlet location. |
Output An OutletAd object defining the ad created.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet ad. |
| outletId | String | The ID of the outlet associated with the ad. |
| dailyBudget | Int | The daily budget for the outlet ad. |
| displayUrl | String | The URL of the image for the ad display. |
| displayText | String | The text to display in the ad. |
| duration | Int | The duration of the ad (in days). |
| time | [Int] | An array of integers representing the time slots when the ad will be displayed. |
| views | [AdInteraction] | An array of ad interaction objects representing the views of the ad. |
| clicks | [AdInteraction] | An array of ad interaction objects representing the clicks on the ad. |
| paid | Boolean | Indicates whether the ad has been paid for. |
| activeUntil | String | The date until which the ad is active. |
| createdBy | UserSummary | Information about the user who created the ad. |
AdInteraction: Object representing the logged interactions for the ad.date: The day the ad interactions were recorded.count: the total interactions logged for the day.
Update Ad
mutation updateOutletAd($id: String, $data: OutletAdInput) {
updateOutletAd(id: $id, data: $data) {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const UPDATE_OUTLET_AD_MUTATION = gql`
mutation UpdateOutletAd($id: String, $data: OutletAdInput) {
updateOutletAd(id: $id, data: $data) {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
`;
// Define the input data for the mutation
const adId = 'ad_id_to_update';
const updatedAdData = {
outletId: 'updated_outlet_id',
dailyBudget: 150,
displayUrl: 'https://example.com/updated_ad_image.jpg',
displayText: 'Updated Special Offer!',
duration: 45, // in days
time: [1, 2], // 1 - morning, 2 - lunch, 3 - evening
};
// Execute the GraphQL mutation using ApolloClient
client
.mutate({
mutation: UPDATE_OUTLET_AD_MUTATION,
variables: {
id: adId,
data: updatedAdData,
},
})
.then((response) => {
console.log(
'Outlet ad updated successfully:',
response.data.updateOutletAd
);
})
.catch((error) => {
console.error('Error updating outlet ad:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"updateOutletAd": {
"_id": "ad_id",
"outletId": "outlet_id",
"dailyBudget": 100,
"displayUrl": "https://example.com/ad_image.jpg",
"displayText": "Special Offer!",
"duration": 30,
"time": "2022-04-29T12:00:00Z",
"views": [
{
"date": "2022-05-01",
"count": 100
}
],
"clicks": [
{
"date": "2022-05-01",
"count": 10
}
],
"paid": true,
"activeUntil": "2022-05-29T12:00:00Z"
}
}
}
This updateOutletAd mutation allows owners of the outlet to update an existing ad.
Input An OutletAdInput object defining the ad parameters and the id of the ad you want to update.
| Parameter | Type | Description |
|---|---|---|
| dailyBudget | Int | The daily budget for the outlet ad. |
| displayUrl | String | The URL of the image for the ad display. |
| displayText | String | The text to display in the ad. |
| duration | Int | The duration of the ad (in days). |
| time | [Int] | An array of integers representing the time slots when the ad will be displayed. |
| outletId | String | The ID of the outlet associated with the ad. |
| coords | [Float] | An array of floats representing the coordinates of the outlet location. |
Output An OutletAd object defining the ad created.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet ad. |
| outletId | String | The ID of the outlet associated with the ad. |
| dailyBudget | Int | The daily budget for the outlet ad. |
| displayUrl | String | The URL of the image for the ad display. |
| displayText | String | The text to display in the ad. |
| duration | Int | The duration of the ad (in days). |
| time | [Int] | An array of integers representing the time slots when the ad will be displayed. |
| views | [AdInteraction] | An array of ad interaction objects representing the views of the ad. |
| clicks | [AdInteraction] | An array of ad interaction objects representing the clicks on the ad. |
| paid | Boolean | Indicates whether the ad has been paid for. |
| activeUntil | String | The date until which the ad is active. |
| createdBy | UserSummary | Information about the user who created the ad. |
AdInteraction: Object representing the logged interactions for the ad.date: The day the ad interactions were recorded.count: the total interactions logged for the day.
Log Ad Interaction
mutation addAddInteraction($id: String, $type: String) {
addAddInteraction(id: $id, type: $type)
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const ADD_AD_INTERACTION_MUTATION = gql`
mutation AddAdInteraction($id: String, $type: String) {
addAdInteraction(id: $id, type: $type)
}
`;
// Define the input data for the mutation
const adId = 'ad_id';
const interactionType = 'views'; // or "clicks" based on your requirement
// Execute the GraphQL mutation using ApolloClient
client
.mutate({
mutation: ADD_AD_INTERACTION_MUTATION,
variables: {
id: adId,
type: interactionType,
},
})
.then((response) => {
console.log('Ad interaction added successfully:', response);
})
.catch((error) => {
console.error('Error adding ad interaction:', error);
});
The above code does not return anything
This addAddInteraction mutation allows the ad interactions to be logged into the platform.
Input An id of the ad and type of the interaction.Currently views or clicks.
Filter Ads
query findAds($options: [FilterOption]) {
findAds(options: $options) {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const FIND_ADS_QUERY = gql`
query FindAds($options: [FilterOption]) {
findAds(options: $options) {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
`;
// Define any filter options if needed
const filterOptions = [
// Define your filter options here if needed
];
// Execute the GraphQL query using ApolloClient
client
.query({
query: FIND_ADS_QUERY,
variables: {
options: filterOptions,
},
})
.then((response) => {
console.log('Ads found:', response.data.findAds);
})
.catch((error) => {
console.error('Error finding ads:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"findAds": [
{
"_id": "ad_id",
"outletId": "outlet_id",
"dailyBudget": 100,
"displayUrl": "https://example.com/ad_image.jpg",
"displayText": "Special Offer!",
"duration": 30,
"time": "2022-04-29T12:00:00Z",
"views": [
{
"date": "2022-05-01",
"count": 100
}
],
"clicks": [
{
"date": "2022-05-01",
"count": 10
}
],
"paid": true,
"activeUntil": "2022-05-29T12:00:00Z"
}
]
}
}
This findAds query allows the developer to filter through the ads in the system.
- Input An array of
FilterOptionobjects containing the necessary fields to find an ad.
| Parameter | Type | Description |
|---|---|---|
| key | String | Represents the key used for filtering the data. |
| dataType | FilterDataType | Represents the data type of the filter value. |
| stringValue | String | (optional) Represents the string value used for filtering. |
| boolValue | Boolean | (optional) Represents the boolean value used for filtering. |
| floatValue | Float | (optional) Represents the float value used for filtering. |
- Output An array of
OutletAdobjects containing that match the filter criteria.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet ad. |
| outletId | String | The ID of the outlet associated with the ad. |
| dailyBudget | Int | The daily budget for the outlet ad. |
| displayUrl | String | The URL of the image for the ad display. |
| displayText | String | The text to display in the ad. |
| duration | Int | The duration of the ad (in days). |
| time | [Int] | An array of integers representing the time slots when the ad will be displayed. |
| views | [AdInteraction] | An array of ad interaction objects representing the views of the ad. |
| clicks | [AdInteraction] | An array of ad interaction objects representing the clicks on the ad. |
| paid | Boolean | Indicates whether the ad has been paid for. |
| activeUntil | String | The date until which the ad is active. |
| createdBy | UserSummary | Information about the user who created the ad. |
AdInteraction: Object representing the logged interactions for the ad.date: The day the ad interactions were recorded.count: the total interactions logged for the day.
Ads Nearby
query findAdsNearby($coords: [Float]) {
findAdsNearby(coords: $coords) {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache()
});
// Define the GraphQL query
const FIND_ADS_NEARBY_QUERY = gql`
query FindAdsNearby($coords: [Float]) {
findAdsNearby(coords: $coords) {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
`;
// Define the coordinates for nearby location
const coordinates = [latitude, longitude]; // Replace latitude and longitude with actual values
// Execute the GraphQL query using ApolloClient
client.query({
query: FIND_ADS_NEARBY_QUERY,
variables: {
coords: coordinates
}
}).then(response => {
console.log('Ads nearby found:', response.data.findAdsNearby);
}).catch(error => {
console.error('Error finding ads nearby:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"findAdsNearby": [
{
"_id": "ad_id",
"outletId": "outlet_id",
"dailyBudget": 100,
"displayUrl": "https://example.com/ad_image.jpg",
"displayText": "Special Offer!",
"duration": 30,
"time": "2022-04-29T12:00:00Z",
"views": [
{
"date": "2022-05-01",
"count": 100
}
],
"clicks": [
{
"date": "2022-05-01",
"count": 10
}
],
"paid": true,
"activeUntil": "2022-05-29T12:00:00Z"
}
]
}
}
This findAdsNearby query allows the developer to filter through the ads in the system targeting a certain geoposition.
Input An array of
coordsrepresnting the latitude and longitude.Output An array of
OutletAdobjects containing that match the filter criteria.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet ad. |
| outletId | String | The ID of the outlet associated with the ad. |
| dailyBudget | Int | The daily budget for the outlet ad. |
| displayUrl | String | The URL of the image for the ad display. |
| displayText | String | The text to display in the ad. |
| duration | Int | The duration of the ad (in days). |
| time | [Int] | An array of integers representing the time slots when the ad will be displayed. |
| views | [AdInteraction] | An array of ad interaction objects representing the views of the ad. |
| clicks | [AdInteraction] | An array of ad interaction objects representing the clicks on the ad. |
| paid | Boolean | Indicates whether the ad has been paid for. |
| activeUntil | String | The date until which the ad is active. |
| createdBy | UserSummary | Information about the user who created the ad. |
AdInteraction: Object representing the logged interactions for the ad.date: The day the ad interactions were recorded.count: the total interactions logged for the day.
My Ads
query findMyAds {
findMyAds {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache()
});
// Define the GraphQL query
const FIND_MY_ADS_QUERY = gql`
query FindMyAds {
findMyAds {
_id
outletId
dailyBudget
displayUrl
displayText
duration
time
views {
date
count
}
clicks {
date
count
}
paid
activeUntil
}
}
`;
// Execute the GraphQL query using ApolloClient
client.query({
query: FIND_MY_ADS_QUERY
}).then(response => {
console.log('My ads found:', response.data.findMyAds);
}).catch(error => {
console.error('Error finding my ads:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"findMyAds": [
{
"_id": "ad_id",
"outletId": "outlet_id",
"dailyBudget": 100,
"displayUrl": "https://example.com/ad_image.jpg",
"displayText": "Special Offer!",
"duration": 30,
"time": "2022-04-29T12:00:00Z",
"views": [
{
"date": "2022-05-01",
"count": 100
}
],
"clicks": [
{
"date": "2022-05-01",
"count": 10
}
],
"paid": true,
"activeUntil": "2022-05-29T12:00:00Z"
}
]
}
}
This findMyAds query allows the logged in user to view their ads.
- Output An array of
OutletAdobjects containing that match the filter criteria.
| Parameter | Type | Description |
|---|---|---|
| _id | String | The unique identifier of the outlet ad. |
| outletId | String | The ID of the outlet associated with the ad. |
| dailyBudget | Int | The daily budget for the outlet ad. |
| displayUrl | String | The URL of the image for the ad display. |
| displayText | String | The text to display in the ad. |
| duration | Int | The duration of the ad (in days). |
| time | [Int] | An array of integers representing the time slots when the ad will be displayed. |
| views | [AdInteraction] | An array of ad interaction objects representing the views of the ad. |
| clicks | [AdInteraction] | An array of ad interaction objects representing the clicks on the ad. |
| paid | Boolean | Indicates whether the ad has been paid for. |
| activeUntil | String | The date until which the ad is active. |
| createdBy | UserSummary | Information about the user who created the ad. |
AdInteraction: Object representing the logged interactions for the ad.date: The day the ad interactions were recorded.count: the total interactions logged for the day.
Payments
This section documents how to facilitate payments in the app using M-Pesa. Currently, payments are implemented for ads only.
Pay
mutation pay($data: PaymentInput) {
pay(data: $data) {
paymentRequestId
success
message
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL mutation
const PAY_MUTATION = gql`
mutation Pay($data: PaymentInput) {
pay(data: $data) {
paymentRequestId
success
message
}
}
`;
// Define the input data for the mutation
const paymentData = {
type: 1, // Example type value
typeId: 'type_id_value', // Example typeId value
amount: 100.0, // Example amount value
phone: '1234567890', // Example phone number
};
// Execute the GraphQL mutation using ApolloClient
client
.mutate({
mutation: PAY_MUTATION,
variables: {
data: paymentData,
},
})
.then((response) => {
console.log('Payment response:', response.data.pay);
})
.catch((error) => {
console.error('Error making payment:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"pay": {
"paymentRequestId": "payment_request_id_value",
"success": true,
"message": "Payment successful"
}
}
}
This pay mutation allows users to initiate m-pesa payments requests that uses STK push API.
- Input A
PaymentInputobject describing the payment details.
| Parameter | Type | Description |
|---|---|---|
| type | Int | Type of payment. 1 represents ad. Can be extended to accomodate other payment types likde deliveries etc |
| typeId | String | Identifier for the type eg if type is ad, the typeId is the adId |
| amount | Float | Amount of the payment |
| phone | String | Phone number for payment, must be an mpesa number |
- Output A
PaymentResponseobject describing if the payment was initiated successfully. The client should subscribe to a server sent event using thepaymentRequestIdas the channel. The url for this subscriprion should be like sohttps://your-api-server.com/api/payments/sse/${paymentRequestId}
| Parameter | Type | Description |
|---|---|---|
| paymentRequestId | String | Identifier for the payment request from mpesa API |
| success | Boolean | Indicates whether the payment was successful (true/false) |
| message | String | Message indicating the status of the payment |
Payment Subscription
The payment initiated above creates an STK push to the phone number provided. The user of the phone number will enter their mpesa PIN and confim the transaction. The payment can succeed of fail due to a variety of reasons like insufficient balance on mpesa wallet. After confirming/cancelling the transaction, mpesa communicates with the platform via a provided callback API. This callback API is responsible for sending a Server Sent Event (SSE) back to the user. The data sent to the user is as follows
| Parameter | Type | Description |
|---|---|---|
| status | Boolean | Indicates whether the payment was successful (true/false) |
| message | String | If successful, the message is the receipt number. If failed, the error message |
Find Payments
query findPayments($options: [FilterOption]) {
findPayments(options: $options) {
_id
type
typeId
paymentRequestId
providerValue
status
statusMessage
receiptNo
amount
createdBy
createdAt
}
}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
// Create an instance of ApolloClient
const client = new ApolloClient({
uri: 'your_graphql_endpoint',
cache: new InMemoryCache(),
});
// Define the GraphQL query
const FIND_PAYMENTS_QUERY = gql`
query FindPayments($options: [FilterOption]) {
findPayments(options: $options) {
_id
type
typeId
paymentRequestId
providerValue
status
statusMessage
receiptNo
amount
createdBy
createdAt
}
}
`;
// Define any filter options if needed
const filterOptions = []; // Example filter options, replace with actual values if needed
// Execute the GraphQL query using ApolloClient
client
.query({
query: FIND_PAYMENTS_QUERY,
variables: {
options: filterOptions,
},
})
.then((response) => {
console.log('Payments found:', response.data.findPayments);
})
.catch((error) => {
console.error('Error finding payments:', error);
});
The above code sample returns a JSON structured like this
{
"data": {
"findPayments": [
{
"_id": "payment_id_value",
"type": 1,
"typeId": "type_id_value",
"paymentRequestId": "payment_request_id_value",
"providerValue": "provider_value",
"status": 1,
"statusMessage": "Payment successful",
"receiptNo": "receipt_number_value",
"amount": 100.0,
"createdBy": "user_id_value",
"createdAt": "2022-05-10T12:34:56Z"
}
]
}
}
This findPayments query allows developers to filter through payments made via the app.
- Input An array of
FilterOptionobjects containing the necessary fields to find an ad payments
| Parameter | Type | Description |
|---|---|---|
| key | String | Represents the key used for filtering the data. |
| dataType | FilterDataType | Represents the data type of the filter value. |
| stringValue | String | (optional) Represents the string value used for filtering. |
| boolValue | Boolean | (optional) Represents the boolean value used for filtering. |
| floatValue | Float | (optional) Represents the float value used for filtering. |
- Output An array of
Paymentobjects matching the filter criteria
| Parameter | Type | Description |
|---|---|---|
| _id | String | Unique identifier for the payment |
| type | Int | Type of payment 1=ad |
| typeId | String | Identifier for the type of payment |
| paymentRequestId | String | Identifier for the payment request from mpesa |
| providerValue | String | This is the phone number used to make the payment |
| status | Int | Status code indicating the status of the payment 1=pending, 2=success, 3=failed |
| statusMessage | String | Message indicating the status of the payment |
| receiptNo | String | Receipt number for the payment from mpesa |
| amount | Float | Amount of the payment |
| createdBy | String | User who created the payment |
| createdAt | String | Timestamp indicating when the payment was created |
Errors
The API uses the following error codes:
| Error Code | Meaning |
|---|---|
| 400 | Bad Request -- Your request is invalid. |
| 401 | Unauthorized -- Your API key is wrong. |
| 403 | Forbidden -- The kitten requested is hidden for administrators only. |
| 404 | Not Found -- The specified kitten could not be found. |
| 500 | Internal Server Error -- We had a problem with our server. Try again later. |