Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion app/graphql/queries/user_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const user_schema = `#graphql
CUSTOMER
}

enum GenderEnum {
male
female
others
}

directive @auth on FIELD_DEFINITION
directive @userType(requires: [UserType]) on FIELD_DEFINITION

Expand All @@ -16,7 +22,29 @@ const user_schema = `#graphql
}

type Mutation {
createMe(firstName: String, lastName: String): UserResponse
createMe(firstName: String, lastName: String, gender: GenderEnum, age: Int, totalMoney: Float): UserResponse
createOrder(orderInput: OrderInput): OrderResponse
}

input OrderInput {
name: String
orderID: Int
singleProduct: ProductInput
manyProducts: [ProductInput]
}

input ProductInput {
name: String
price: Int
imageUrl: String
productAvailable: Boolean
}

type Product {
name: String
price: Int
productAvailable: Boolean
imageUrl: String
}

type UserObject {
Expand All @@ -30,6 +58,19 @@ const user_schema = `#graphql
message: String
}

type OrderData {
name: String
orderID: Int
singleProduct: Product
manyProducts: [Product]
}

type OrderResponse {
status: String
data: OrderData
message: String
}

type Response {
status: String
message: String
Expand Down
7 changes: 7 additions & 0 deletions app/graphql/resolvers/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const userResolvers = {
console.log(currentUser)
return userService.createMe(currentUser);
},

createOrder(_: any, { orderInput: args }, {}) {
const body = {
...args,
};
return userService.createOrder(body);
},
},
};

Expand Down
12 changes: 9 additions & 3 deletions app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export class UserService {
}
};

public createMe = async (
currentUser
) => {
public createMe = async (currentUser) => {
try {
if (!currentUser) throw new GraphQLError("not data returned!");
console.log(currentUser);
Expand All @@ -24,4 +22,12 @@ export class UserService {
return Helpers.error(error?.message);
}
};

public createOrder = async (createOrderData) => {
try {
return Helpers.success(createOrderData);
} catch (error) {
return Helpers.error(error?.message);
}
};
}