@abernix I have the following code in which I cannot receive any response from the apollo playground and also I can´t save any in DB as it works before with createUser and other resolvers I have.
The code for mutation is
Mutation: {
createService: async(parent, { service: {
name, description, price, discount, priceDiscount,
type, nameAttendances:[{ root: {name}}, {secondary: {username} }], calendar: {
datesAvailable,
datesOccupied
},
images: {
url, width, height
}
} } , context, info) => {
console.log(service)
const serviceDB = await db.getCollection('services');
const serviceJoinRetailer = db.joinRetailCollection(
retailer,
null,
);
const createdAt = Date("<YYYY-mm-ddTHH:MM:ss>")
console.log(newService)
const newService = {
_id, id, name, description, price,
priceDiscount, discount, calendar, type, images,
includes, details, created_at: createdAt,
username, datesAvailable, datesOccupied, url, width,
height
}
console.log(`service created: ${newService}`)
/* const serviceAdded = serviceDB.findOne({$or: [{name}, {_id}]})
if( serviceAdded ) {
throw new Error("El servicio ya fue registrado pr")
} */
//serviceDB.findOne({$or: [{name}, {id}]}))
try {
const service = new Service(service)
const createService = (await serviceDB.insertOne(service));
console.log(newService)
return createService
}
catch (e) {
console.log
}
},
types
const { gql } = require("apollo-server-express");
const servicesType = gql`
type Service implements MutationResponse {
code: String!
success: Boolean!
message: String!
_id:ID!
id: String!
name: String!
priceDiscount: Int
discount:Boolean
description: String!
price: Int!
includes: [Options]
images: [Image!]
details: DetailsService
namesAttendances: [AllUsers]!
calendar: AvailableCalendar
type: ServiceType
isPromotion: Boolean
isSingle: Boolean
isSubscription: Boolean
created_at: String
}
type AvailableCalendar {
datesAvailable: [CalendarAvailable]
datesOccupied: [CalendarOccupied]
}
type Image {
url: String!
height: Int
width: Int
}
type DetailsService {
sessions: Int
durationHours: Int
}
type Options {
numberInclude: Int
nameOptionInclude: String
}
t
type AllUsers implements MutationResponse{
code: String!
success: Boolean!
message: String!
root: RetailerRoot
secondary: [SecondaryUser]
}
type CalendarAvailable {
time: String!
day: String!
}
type CalendarOccupied {
time: String!
day: String!
}
type Url {
url: String!
}
enum AccountType {
ROOT
ADMIN
SECONDARY
}
enum ServiceType {
SERVICE_SINGLE
PROMOTIONS
SUBSCRIPTION
}
input CreateServiceInput {
service: ServiceInput
}
input ServiceInput {
id: String!
name: String!
description: String!
price: Int!
details: DetailsServiceInput
type: ServiceType
discount: Boolean
priceDiscount: Int!
includes: [OptionsInput]
images: [ImageInput]
namesAttendances: [AllUserInput]!
calendar: [CalendarInput]
created_at: String
}
input AllUserInput {
root: RetailerInput
secondary: [SecondaryUserInput]
}
input ImageInput {
url: String!
height: Int
width: Int
}
input OptionsInput {
numberInclude: Int
nameOptionInclude: String
}
input DetailsServiceInput {
sessions: Int
durationHours: Int
}
input CalendarInput {
datesAvailable: [CalendarAvailableInput]
datesOccupied: [DatesOccupiedInput]
}
input CalendarAvailableInput {
time: String!
day: String!
}
input DatesOccupiedInput {
time: String!
day: String!
}
type Query {
getAllServicesOfBussiness(idReatailer: ID!): [Service]
getAllServicesByCategory(category: String): [Service]!
getAllServicesBySubcategory(subcategory: String): [Service]
}
type Mutation {
createService(service: ServiceInput): Service
updateService(service: ServiceInput): Service
deleteService(_id: ID): Boolean
}
`;
module.exports = servicesType;
In apollo playground I enter this
mutation createService($service:ServiceInput){ createService(service: $service){ _id name description price type discount priceDiscount details{ sessions durationHours } images { url height width } includes { numberInclude nameOptionInclude } calendar { datesAvailable { time day } datesOccupied { time day } } namesAttendances { root { name } secondary { username } } type } }
query part:
{ "service":{ "id":"123", "name": "Designer", "description": "Corete de Pelo", "price": 200, "type": "SERVICE_SINGLE", "discount": true, "priceDiscount": 100, "details": { "sessions": 2, "durationHours": 1 }, "images": [ { "url": "", "width": 100, "height": 100 }, { "url": "", "width": 100, "height": 100 } ], "includes": { "numberInclude": 1, "nameOptionInclude": "Hey brother" }, "calendar": [ { "datesAvailable": [ { "time":["12/24"], "day": ["12/03/24"] }, { "time":["12/24"], "day": ["12/03/24"] } ], "datesOccupied": [ { "time":"12/24", "day": "12/03/24" }, { "time":"12/24", "day": "12/03/24" } ] } ], "namesAttendances": [ { "root": { "name": "Sandra" }, "secondary": [ { "username": "Sarah" }, { "username": "Sofía" } ] } ] } }
the response:
{ "data": { "createService": null } }
Also in the DB it doesn´t save anything.
I think the problem is how I am introducing the input
Hope somebody can help me to resolve this or any way to do this in a better way.
Kind regards