apollo-server-express#UserInputError TypeScript Examples
The following examples show how to use
apollo-server-express#UserInputError.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: mutation.ts From backend with MIT License | 6 votes |
@Mutation(returns => Student)
@Authorized(Role.UNAUTHENTICATED, Role.ADMIN)
@RateLimit("RegisterStudent", 10 /* requests per */, 5 * 60 * 60 * 1000 /* 5 hours */)
async meRegisterStudent(@Ctx() context: GraphQLContext, @Arg("data") data: RegisterStudentInput) {
const byAdmin = context.user!.roles.includes(Role.ADMIN);
if (data.registrationSource === RegistrationSource.plus && !byAdmin) {
throw new UserInputError("Lern-Fair Plus pupils may only be registered by admins");
}
const student = await registerStudent(data);
const log = logInContext("Me", context);
log.info(`Student(${student.id}, firstname = ${student.firstname}, lastname = ${student.lastname}) registered`);
if (!byAdmin) {
await loginAsUser(userForStudent(student), context);
}
return student;
/* The student can now use the authToken passed to them via E-Mail to re authenticate the session and have their E-Mail verified
This session now also has the STUDENT role.
With this role, they can use the meBecomeTutor, meBecomeInstructor or meBecomeProjectCoach to enhance their user account.
With the STUDENT Role alone they can't do much (but at least deactivate their account and change their settings) */
}
Example #2
Source File: mutation.ts From backend with MIT License | 6 votes |
@Mutation(returns => Pupil)
@Authorized(Role.UNAUTHENTICATED, Role.ADMIN)
@RateLimit("RegisterPupil", 10 /* requests per */, 5 * 60 * 60 * 1000 /* 5 hours */)
async meRegisterPupil(@Ctx() context: GraphQLContext, @Arg("data") data: RegisterPupilInput) {
const byAdmin = context.user!.roles.includes(Role.ADMIN);
if (data.registrationSource === RegistrationSource.plus && !byAdmin) {
throw new UserInputError("Lern-Fair Plus pupils may only be registered by admins");
}
const pupil = await registerPupil(data);
const log = logInContext("Me", context);
log.info(`Pupil(${pupil.id}, firstname = ${pupil.firstname}, lastname = ${pupil.lastname}) registered`);
if (!byAdmin) {
await loginAsUser(userForPupil(pupil), context);
}
return pupil;
/* The pupil can now use the authToken passed to them via E-Mail to re authenticate the session.
This will mark them as verified, and grant them the PUPIL role.
With this role, they can use the meBecomeStatePupil, meBecomeTutee or meBecomeProjectCoachee to enhance their user account */
}
Example #3
Source File: apollo-server-resolver-adapter.ts From clean-ts-api with GNU General Public License v3.0 | 6 votes |
adaptResolver = async (controller: Controller, args?: any, context?: any): Promise<any> => {
const request = {
...(args || {}),
accountId: context?.req?.accountId
}
const httpResponse = await controller.handle(request)
switch (httpResponse.statusCode) {
case 200:
case 204: return httpResponse.body
case 400: throw new UserInputError(httpResponse.body.message)
case 401: throw new AuthenticationError(httpResponse.body.message)
case 403: throw new ForbiddenError(httpResponse.body.message)
default: throw new ApolloError(httpResponse.body.message)
}
}