| @@ -316,16 +316,6 @@ | |||
| "enumValues": null, | |||
| "possibleTypes": null | |||
| }, | |||
| { | |||
| "kind": "SCALAR", | |||
| "name": "Boolean", | |||
| "description": "The `Boolean` scalar type represents `true` or `false`.", | |||
| "fields": null, | |||
| "inputFields": null, | |||
| "interfaces": null, | |||
| "enumValues": null, | |||
| "possibleTypes": null | |||
| }, | |||
| { | |||
| "kind": "INPUT_OBJECT", | |||
| "name": "ChangePizzaDto", | |||
| @@ -542,6 +532,68 @@ | |||
| }, | |||
| "isDeprecated": false, | |||
| "deprecationReason": null | |||
| }, | |||
| { | |||
| "name": "deleteTopping", | |||
| "description": null, | |||
| "args": [ | |||
| { | |||
| "name": "toppingId", | |||
| "description": null, | |||
| "type": { | |||
| "kind": "NON_NULL", | |||
| "name": null, | |||
| "ofType": { | |||
| "kind": "SCALAR", | |||
| "name": "ID", | |||
| "ofType": null | |||
| } | |||
| }, | |||
| "defaultValue": null | |||
| } | |||
| ], | |||
| "type": { | |||
| "kind": "NON_NULL", | |||
| "name": null, | |||
| "ofType": { | |||
| "kind": "OBJECT", | |||
| "name": "Topping", | |||
| "ofType": null | |||
| } | |||
| }, | |||
| "isDeprecated": false, | |||
| "deprecationReason": null | |||
| }, | |||
| { | |||
| "name": "deletePizza", | |||
| "description": null, | |||
| "args": [ | |||
| { | |||
| "name": "pizzaId", | |||
| "description": null, | |||
| "type": { | |||
| "kind": "NON_NULL", | |||
| "name": null, | |||
| "ofType": { | |||
| "kind": "SCALAR", | |||
| "name": "ID", | |||
| "ofType": null | |||
| } | |||
| }, | |||
| "defaultValue": null | |||
| } | |||
| ], | |||
| "type": { | |||
| "kind": "NON_NULL", | |||
| "name": null, | |||
| "ofType": { | |||
| "kind": "OBJECT", | |||
| "name": "Pizza", | |||
| "ofType": null | |||
| } | |||
| }, | |||
| "isDeprecated": false, | |||
| "deprecationReason": null | |||
| } | |||
| ], | |||
| "inputFields": null, | |||
| @@ -600,6 +652,16 @@ | |||
| "enumValues": null, | |||
| "possibleTypes": null | |||
| }, | |||
| { | |||
| "kind": "SCALAR", | |||
| "name": "Boolean", | |||
| "description": "The `Boolean` scalar type represents `true` or `false`.", | |||
| "fields": null, | |||
| "inputFields": null, | |||
| "interfaces": null, | |||
| "enumValues": null, | |||
| "possibleTypes": null | |||
| }, | |||
| { | |||
| "kind": "OBJECT", | |||
| "name": "__Schema", | |||
| @@ -72,6 +72,8 @@ export type Mutation = { | |||
| updatePizza: Pizza; | |||
| createTopping: Topping; | |||
| updateTopping: Topping; | |||
| deleteTopping: Topping; | |||
| deletePizza: Pizza; | |||
| }; | |||
| @@ -96,6 +98,16 @@ export type MutationUpdateToppingArgs = { | |||
| updatedToppingDto: ChangeToppingDto; | |||
| }; | |||
| export type MutationDeleteToppingArgs = { | |||
| toppingId: Scalars['ID']; | |||
| }; | |||
| export type MutationDeletePizzaArgs = { | |||
| pizzaId: Scalars['ID']; | |||
| }; | |||
| export type Subscription = { | |||
| __typename?: 'Subscription'; | |||
| pizzasChanged: Array<Maybe<Pizza>>; | |||
| @@ -185,11 +197,11 @@ export type ResolversTypes = { | |||
| String: ResolverTypeWrapper<Scalars['String']>; | |||
| Topping: ResolverTypeWrapper<Topping>; | |||
| Query: ResolverTypeWrapper<{}>; | |||
| Boolean: ResolverTypeWrapper<Scalars['Boolean']>; | |||
| ChangePizzaDto: ChangePizzaDto; | |||
| ChangeToppingDto: ChangeToppingDto; | |||
| Mutation: ResolverTypeWrapper<{}>; | |||
| Subscription: ResolverTypeWrapper<{}>; | |||
| Boolean: ResolverTypeWrapper<Scalars['Boolean']>; | |||
| }; | |||
| /** Mapping between all available schema types and the resolvers parents */ | |||
| @@ -199,11 +211,11 @@ export type ResolversParentTypes = { | |||
| String: Scalars['String']; | |||
| Topping: Topping; | |||
| Query: {}; | |||
| Boolean: Scalars['Boolean']; | |||
| ChangePizzaDto: ChangePizzaDto; | |||
| ChangeToppingDto: ChangeToppingDto; | |||
| Mutation: {}; | |||
| Subscription: {}; | |||
| Boolean: Scalars['Boolean']; | |||
| }; | |||
| export type PizzaResolvers<ContextType = any, ParentType extends ResolversParentTypes['Pizza'] = ResolversParentTypes['Pizza']> = { | |||
| @@ -233,6 +245,8 @@ export type MutationResolvers<ContextType = any, ParentType extends ResolversPar | |||
| updatePizza?: Resolver<ResolversTypes['Pizza'], ParentType, ContextType, RequireFields<MutationUpdatePizzaArgs, 'pizzaId' | 'updatedPizzaDto'>>; | |||
| createTopping?: Resolver<ResolversTypes['Topping'], ParentType, ContextType, RequireFields<MutationCreateToppingArgs, never>>; | |||
| updateTopping?: Resolver<ResolversTypes['Topping'], ParentType, ContextType, RequireFields<MutationUpdateToppingArgs, 'toppingId' | 'updatedToppingDto'>>; | |||
| deleteTopping?: Resolver<ResolversTypes['Topping'], ParentType, ContextType, RequireFields<MutationDeleteToppingArgs, 'toppingId'>>; | |||
| deletePizza?: Resolver<ResolversTypes['Pizza'], ParentType, ContextType, RequireFields<MutationDeletePizzaArgs, 'pizzaId'>>; | |||
| }; | |||
| export type SubscriptionResolvers<ContextType = any, ParentType extends ResolversParentTypes['Subscription'] = ResolversParentTypes['Subscription']> = { | |||
| @@ -6,57 +6,63 @@ import { ToppingResolver } from "./resolver/topping-resolver"; | |||
| const resolvers: Resolvers = { | |||
| Topping: { | |||
| id: (root, args, context) => { | |||
| id: (root, _args, _context) => { | |||
| return root.id | |||
| }, | |||
| name: (root, args, context) => { | |||
| name: (root, _args, _context) => { | |||
| return root.name | |||
| }, | |||
| }, | |||
| Pizza: { | |||
| id: (root, args, context) => { | |||
| id: (root, _args, _context) => { | |||
| return root.id | |||
| }, | |||
| name: (root, args, context) => { | |||
| name: (root, _args, _context) => { | |||
| return root.name | |||
| }, | |||
| toppings: (root, args, context) => { | |||
| toppings: (root, _args, _context) => { | |||
| return root.toppings | |||
| }, | |||
| }, | |||
| Query: { | |||
| getPizzaById: (root, args, context) => { | |||
| getPizzaById: (_root, args, _context) => { | |||
| return PizzaResolver.getById(args.pizzaId); | |||
| }, | |||
| getPizzaByName: (root, args, context) => { | |||
| getPizzaByName: (_root, args, _context) => { | |||
| return PizzaResolver.getByName(args.pizzaName); | |||
| }, | |||
| listPizza: (root, args, context) => { | |||
| listPizza: (_root, _args, _context) => { | |||
| return PizzaResolver.list(); | |||
| }, | |||
| getToppingById: (root, args, context) => { | |||
| getToppingById: (_root, args, _context) => { | |||
| return ToppingResolver.getById(args.toppingId); | |||
| }, | |||
| getToppingByName: (root, args, context) => { | |||
| getToppingByName: (_root, args, _context) => { | |||
| return ToppingResolver.getByName(args.toppingName); | |||
| }, | |||
| listTopping: (root, args, context) => { | |||
| listTopping: (_root, _args, _context) => { | |||
| return ToppingResolver.list(); | |||
| }, | |||
| }, | |||
| Mutation: { | |||
| createPizza: (root, args, context) => { | |||
| createPizza: (_root, args, _context) => { | |||
| return PizzaResolver.create(args.createPizzaDto as ChangePizzaDto); | |||
| }, | |||
| updatePizza: (root, args, context) => { | |||
| updatePizza: (_root, args, _context) => { | |||
| return PizzaResolver.update(args.pizzaId, args.updatedPizzaDto as ChangePizzaDto); | |||
| }, | |||
| createTopping: (root, args, context) => { | |||
| deletePizza: (_root, args, _context: any) => { | |||
| return PizzaResolver.delete(args.pizzaId); | |||
| }, | |||
| createTopping: (_root, args, _context) => { | |||
| return ToppingResolver.create(args.createToppingDto as ChangeToppingDto); | |||
| }, | |||
| updateTopping: (root, args, context) => { | |||
| updateTopping: (_root, args, _context) => { | |||
| return ToppingResolver.update(args.toppingId, args.updatedToppingDto as ChangeToppingDto); | |||
| }, | |||
| deleteTopping: (_root, args, _context: any) => { | |||
| return ToppingResolver.delete(args.toppingId); | |||
| }, | |||
| }, | |||
| Subscription: { | |||
| pizzasChanged: { | |||
| @@ -15,6 +15,15 @@ export class PizzaResolver { | |||
| return PizzaList.filter(pizza => pizza.id === id)[0]; | |||
| }; | |||
| static delete = (id: string): Pizza => { | |||
| const index = PizzaList.indexOf(PizzaResolver.getById(id)); | |||
| if ( index ) { | |||
| PizzaList.splice(index, 1) | |||
| } | |||
| return PizzaResolver.getById(id) | |||
| }; | |||
| static list = (): Pizza[] => { | |||
| return PizzaList; | |||
| }; | |||
| @@ -24,6 +24,14 @@ export class ToppingResolver { | |||
| return ToppingList; | |||
| }; | |||
| static delete = (id: string): Topping => { | |||
| const index = ToppingList.indexOf(ToppingResolver.getById(id)); | |||
| if ( index ) { | |||
| ToppingList.splice(index, 1) | |||
| } | |||
| return ToppingResolver.getById(id) | |||
| }; | |||
| static create = (toppingCreateDto: ChangeToppingDto): Topping => { | |||
| const topping: Topping = { | |||
| id: uuidv4(), | |||
| @@ -36,6 +36,8 @@ export const pizzaSchema = gql` | |||
| updatePizza(pizzaId: ID!, updatedPizzaDto: ChangePizzaDto!): Pizza! | |||
| createTopping(createToppingDto: ChangeToppingDto): Topping! | |||
| updateTopping(toppingId: ID!, updatedToppingDto: ChangeToppingDto!): Topping! | |||
| deleteTopping(toppingId: ID!): Topping! | |||
| deletePizza(pizzaId: ID!): Pizza! | |||
| } | |||
| type Subscription { | |||
| @@ -74,6 +74,8 @@ export type Mutation = { | |||
| updatePizza: Pizza; | |||
| createTopping: Topping; | |||
| updateTopping: Topping; | |||
| deleteTopping: Topping; | |||
| deletePizza: Pizza; | |||
| }; | |||
| @@ -98,6 +100,16 @@ export type MutationUpdateToppingArgs = { | |||
| updatedToppingDto: ChangeToppingDto; | |||
| }; | |||
| export type MutationDeleteToppingArgs = { | |||
| toppingId: Scalars['ID']; | |||
| }; | |||
| export type MutationDeletePizzaArgs = { | |||
| pizzaId: Scalars['ID']; | |||
| }; | |||
| export type Subscription = { | |||
| __typename?: 'Subscription'; | |||
| pizzasChanged: Array<Maybe<Pizza>>; | |||