How to use the @nestjs/graphql.Mutation function in @nestjs/graphql

To help you get started, we’ve selected a few @nestjs/graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chnirt / nestjs-graphql-best-practice / src / resolvers / auth.resolver.ts View on Github external
return await tradeToken(user)
		}

		if (info) {
			// console.log(info)
			const { code } = info
			switch (code) {
				case 'ETIMEDOUT':
					throw new ApolloError('Failed to reach Google: Try Again')
				default:
					throw new ApolloError('Something went wrong')
			}
		}
	}

	@Mutation()
	async oauthGoogle(
		@Args('accessToken') accessToken: string,
		@Context() context: any
	): Promise {
		const { req, res } = context

		req.body = {
			...req.body,
			access_token: accessToken,
		}

		const { data, info } = await authenticateGoogle(req, res)

		if (data) {
			console.log(data.profile)
github jkchao / blog-service / src / module / heros / heros.resolvers.ts View on Github external
public getHeros(@Args() args: QueryHerosDto, @Context('request') request: Request) {
    const token = request.headers.authorization;
    if (!token) {
      args.state = 1;
    }
    return this.herosService.searchHero(args);
  }

  @Mutation()
  @Permissions()
  public async deleteHero(@Args('_id') _id: string) {
    await this.herosService.deleteHero(_id);
    return { message: 'success' };
  }

  @Mutation()
  @Permissions()
  public async createHero(@Args('heroInfo') info: HerosInfoDto, @Context('request') request: Request) {
    // 获取ip地址以及物理地理地址
    const ip = ((request.headers['x-forwarded-for'] ||
      request.headers['x-real-ip'] ||
      request.connection.remoteAddress ||
      request.socket.remoteAddress ||
      request.ip ||
      request.ips[0]) as string).replace('::ffff:', '');

    info.ip = ip;
    info.agent = request.headers['user-agent'] || info.agent;

    const result = await this.herosService.createHero({ ...info, ip });

    this.emailService.sendEmail({
github juicycleff / ultimate-backend / apps / service-auth / src / roles / roles.resolver.ts View on Github external
@Resolver(() => Role)
export class RolesResolver {
  constructor(private readonly casbinService: NestCasbinService) {}

  @Query(() => [Role])
  async roles() {
    throw new NotImplementedError('Not implemented');
  }

  @Query(() => Role)
  async role(@Args('id') id: string) {
    throw new NotImplementedError('Not implemented');
  }

  @Mutation(() => Role, { name: 'role'})
  async roleMutation(@Args() cmds: RoleMutationArgs) {
   //  const actions = this.casbinService.addPolicy('juicycleff', 'tenantx', 'project/001', 'read');
    throw new NotImplementedError('Not implemented');
  }
}
github SolidZORO / leaa / packages / leaa-api / src / modules / category / category.resolver.ts View on Github external
}

  // @UseGuards(PermissionsGuard)
  // @Permissions('category.item-read')
  // DO NOT CHECK PERMISSIONS
  @Query(() => Category)
  async category(
    @Args({ name: 'id', type: () => Int }) id: number,
    @Args() args?: CategoryArgs,
  ): Promise {
    return this.categoryService.category(id, args);
  }

  @UseGuards(PermissionsGuard)
  @Permissions('category.item-create')
  @Mutation(() => Category)
  async createCategory(@Args('category') args: CreateCategoryInput): Promise {
    return this.categoryService.createCategory(args);
  }

  @UseGuards(PermissionsGuard)
  @Permissions('category.item-update')
  @Mutation(() => Category)
  async updateCategory(
    @Args({ name: 'id', type: () => Int }) id: number,
    @Args('category') args: UpdateCategoryInput,
  ): Promise {
    return this.categoryService.updateCategory(id, args);
  }

  @UseGuards(PermissionsGuard)
  @Permissions('category.item-delete')
github webnoob / quasar-ts-jest-nestjs-apollojs-prisma2 / api / src / book / book.resolver.ts View on Github external
@UseGuards(GqlAuthGuard)
export class BookResolver {
  constructor (
    private readonly bookService: BookService
  ) {}

  @Query(returns => [Book])
  @UseGuards(new RoleAuthGuard(AppRolePermissions.ReadBooks))
  books (
    @CurrentUser() user: User,
    @Args() args: BookArgs
  ): Promise {
    return this.bookService.findAll(args)
  }

  @Mutation(returns => Book)
  @UseGuards(new RoleAuthGuard(AppRolePermissions.CreateBooks))
  create (@Args() newBookData: BookCrudDto): Promise {
    return this.bookService.create(newBookData)
  }

  @Mutation(returns => Book)
  @UseGuards(new RoleAuthGuard(AppRolePermissions.DeleteBooks))
  delete (@Args('id') id: string): Promise {
    return this.bookService.delete(id)
  }
}
github mythal / boluo / server / src / channels / channels.resolver.ts View on Github external
@Mutation(() => Channel)
  @UseGuards(GqlAuthGuard)
  async createChannel(
    @CurrentUser() user: TokenUserInfo,
    @Args({ name: 'name', type: () => String }) name: string,
    @Args({ name: 'isGame', type: () => Boolean, defaultValue: false }) isGame: boolean,
    @Args({ name: 'isPublic', type: () => Boolean, defaultValue: true }) isPublic: boolean,
    @Args({ name: 'description', type: () => String, defaultValue: '' }) description: string,
    @Args({ name: 'parentId', type: () => ID, nullable: true }) parentId?: string
  ) {
    const create = this.channelService.create(name, user.id, user.nickname, isGame, isPublic, description, parentId);
    return throwApolloError(await create);
  }

  @Mutation(() => Member, { nullable: true })
  @UseGuards(GqlAuthGuard)
  async addChannelMember(
    @CurrentUser() user: TokenUserInfo,
    @Args({ name: 'channelId', type: () => ID }) channelId: string,
    @Args({ name: 'userId', type: () => ID, nullable: true }) userId?: string
  ) {
    userId = userId || user.id;
    const addMember = this.channelService.addMember(channelId, user.id, user.nickname, userId);
    return throwApolloError(await addMember);
  }

  @Mutation(() => Boolean)
  @UseGuards(GqlAuthGuard)
  async leaveChannel(
    @CurrentUser() user: TokenUserInfo,
    @Args({ name: 'channelId', type: () => ID }) channelId: string
github notadd / nt-module-user / package / resolvers / info-item.resolver.js View on Github external
__decorate([
    graphql_1.Mutation('createInfoItem'),
    decorators_1.Permission({ name: 'create_info_item', identify: 'infoItem:createInfoItem', action: 'create' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], InfoItemResolver.prototype, "createInfoItem", null);
__decorate([
    graphql_1.Mutation('deleteInfoItem'),
    decorators_1.Permission({ name: 'delete_info_item', identify: 'infoItem:deleteInfoItem', action: 'delete' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], InfoItemResolver.prototype, "deleteInfoItem", null);
__decorate([
    graphql_1.Mutation('updateInfoItem'),
    decorators_1.Permission({ name: 'update_info_item', identify: 'infoItem:updateInfoItem', action: 'update' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], InfoItemResolver.prototype, "updateInfoItem", null);
__decorate([
    graphql_1.Query('findAllInfoItem'),
    decorators_1.Permission({ name: 'find_all_info_item', identify: 'infoItem:findAllInfoItem', action: 'find' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], InfoItemResolver.prototype, "findAllInfoItem", null);
InfoItemResolver = __decorate([
    graphql_1.Resolver(),
    decorators_1.Resource({ name: 'info_item_manage', identify: 'infoItem:manage' }),
    __param(0, common_1.Inject(info_item_service_1.InfoItemService)),
github mythal / boluo / server / src / channels / channels.resolver.ts View on Github external
) {
    const userId = user ? user.id : undefined;
    return throwApolloError(await this.channelService.getMessages(channel, userId, after, limit));
  }

  @Query(() => [Channel], { description: 'Get all channels.' })
  async channels() {
    return await this.channelService.findAll();
  }

  @Query(() => Channel, { nullable: true })
  async getChannelById(@Args({ name: 'id', type: () => ID }) id: string) {
    return throwApolloError(await this.channelService.findById(id));
  }

  @Mutation(() => Channel)
  @UseGuards(GqlAuthGuard)
  async createChannel(
    @CurrentUser() user: TokenUserInfo,
    @Args({ name: 'name', type: () => String }) name: string,
    @Args({ name: 'isGame', type: () => Boolean, defaultValue: false }) isGame: boolean,
    @Args({ name: 'isPublic', type: () => Boolean, defaultValue: true }) isPublic: boolean,
    @Args({ name: 'description', type: () => String, defaultValue: '' }) description: string,
    @Args({ name: 'parentId', type: () => ID, nullable: true }) parentId?: string
  ) {
    const create = this.channelService.create(name, user.id, user.nickname, isGame, isPublic, description, parentId);
    return throwApolloError(await create);
  }

  @Mutation(() => Member, { nullable: true })
  @UseGuards(GqlAuthGuard)
  async addChannelMember(