public TechEventInfoType(ITechEventRepository repository) { Field(x => x.EventId).Description("Event id."); Field(x => x.EventName).Description("Event name."); Field(x => x.Speaker).Description("Speaker name."); Field(x => x.EventDate).Description("Event date."); Field <ListGraphType <ParticipantType> >( "participants", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "eventId" }), resolve: context => repository.GetParticipantInfoByEventIdAsync(context.Source.EventId) ); }
public TechEventQuery(ITechEventRepository repository) { Name = "TechEventQuery"; Field <TechEventInfoType>( "event", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "eventId" }), resolve: context => repository.GetTechEventById(context.GetArgument <int>("eventId")) ); Field <ListGraphType <TechEventInfoType> >( "events", resolve: context => repository.GetTechEvents() ); }
public TechEventMutation(ITechEventRepository repository) { Name = "TechEventMutation"; Field <TechEventInfoType>( "addTechEvent", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <AddEventInputType> > { Name = "techEventInput" } ), resolve: context => { var techEventInput = context.GetArgument <NewTechEventRequest>("techEventInput"); return(repository.AddTechEvent(techEventInput)); }); }
public TechEventMutation(ITechEventRepository repository) { Name = "TechEventMutation"; FieldAsync <TechEventInfoType>( "createTechEvent", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <TechEventInputType> > { Name = "techEventInput" } ), resolve: async context => { var techEventInput = context.GetArgument <NewTechEventRequest>("techEventInput"); return(await repository.AddTechEventAsync(techEventInput)); }); FieldAsync <TechEventInfoType>( "updateTechEvent", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <TechEventInputType> > { Name = "techEventInput" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "techEventId" }), resolve: async context => { var techEventInput = context.GetArgument <TechEventInfo>("techEventInput"); var techEventId = context.GetArgument <int>("techEventId"); var eventInfoRetrived = await repository.GetTechEventByIdAsync(techEventId); if (eventInfoRetrived == null) { context.Errors.Add(new ExecutionError("Couldn't find Tech event info.")); return(null); } eventInfoRetrived.EventName = techEventInput.EventName; eventInfoRetrived.EventDate = techEventInput.EventDate; return(await repository.UpdateTechEventAsync(eventInfoRetrived)); } ); FieldAsync <StringGraphType>( "deleteTechEvent", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "techEventId" }), resolve: async context => { var techEventId = context.GetArgument <int>("techEventId"); var eventInfoRetrived = await repository.GetTechEventByIdAsync(techEventId); if (eventInfoRetrived == null) { context.Errors.Add(new ExecutionError("Couldn't find Tech event info.")); return(null); } await repository.DeleteTechEventAsync(eventInfoRetrived); return($"Tech Event ID {techEventId} with Name {eventInfoRetrived.EventName} has been deleted succesfully."); } ); }