@nestjs/graphql#Mutation TypeScript Examples

The following examples show how to use @nestjs/graphql#Mutation. 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: user.resolver.ts    From nestjs-mercurius with MIT License 6 votes vote down vote up
@Mutation(() => UserType)
  createUser(
    @Args({ name: 'input', type: () => CreateUserInput }) data: CreateUserInput,
    @Context() ctx: MercuriusContext,
  ) {
    const user = this.userService.create(data);

    return user;
  }
Example #2
Source File: account.resolver.ts    From amplication with Apache License 2.0 6 votes vote down vote up
@Mutation(() => Account)
  async updateAccount(
    @UserEntity() user: User,
    @Args('data') newAccountData: UpdateAccountInput
  ): Promise<Account> {
    return this.accountService.updateAccount({
      where: { id: user.account.id },
      data: newAccountData
    });
  }
Example #3
Source File: post.resolver.ts    From nest-casl with MIT License 6 votes vote down vote up
@Mutation(() => Post)
  @UseGuards(AccessGuard)
  @UseAbility<Post>(Actions.update, Post, [
    PostService,
    (service: PostService, { params }) => service.findById(params.input.id),
  ])
  async updatePostTupleHook(@Args('input') input: UpdatePostInput) {
    return this.postService.update(input);
  }
Example #4
Source File: dbms-plugins.resolver.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
@Mutation(() => UninstallDbmsPluginReturn, {nullable: true})
    async [PUBLIC_GRAPHQL_METHODS.UNINSTALL_DBMS_PLUGIN](
        @Context('environment') environment: Environment,
        @Args() {dbmsIds}: DbmssArgs,
        @Args() {pluginName}: PluginNameArgs,
    ): Promise<UninstallDbmsPluginReturn> {
        await environment.dbmsPlugins.uninstall(dbmsIds, pluginName);
        return {
            dbmsIds,
            pluginName,
        };
    }
Example #5
Source File: auth.login.mutation.ts    From api with GNU Affero General Public License v3.0 6 votes vote down vote up
@Mutation(() => AuthJwtModel)
  async authLogin(
    @Args({ name: 'username', type: () => String }) username: string,
    @Args({ name: 'password', type: () => String }) password: string,
  ): Promise<AuthJwtModel> {
    const user = await this.auth.validateUser(username, password)

    if (!user) {
      throw new Error('invalid user / password')
    }

    return this.auth.login(user)
  }
Example #6
Source File: chat.resolver.ts    From NextJS-NestJS-GraphQL-Starter with MIT License 6 votes vote down vote up
@Mutation(() => Message)
  async sendMessage(@Args('input') input: SendMessageInput) {
    const message = {
      sent: new Date(),
      ...input,
    };

    await pubsub.publish(newMessage, { [newMessage]: message });

    return message;
  }
Example #7
Source File: dummy.resolver.ts    From prisma-nestjs-graphql with MIT License 6 votes vote down vote up
@Mutation(() => Dummy)
  createDummy(@Args('data') data: DummyCreateInput) {
    const dummy = new Dummy();

    Object.assign(dummy, { id: '1', date: new Date() }, data);
    if (data.decimals) {
      // @ts-ignore
      dummy.decimals = data.decimals.set;
    }

    dummy.id = `decimal_ctor_${
      (dummy.decimal as any)?.['constructor']?.name
      // @ts-ignore
    }, decimals: ${data.decimals?.set?.map(d => d.constructor.name)}`;

    return dummy;
  }
Example #8
Source File: cats.resolvers.ts    From nestjs-mercurius with MIT License 5 votes vote down vote up
@Mutation('createCat')
  async create(@Args() args: Cat): Promise<Cat> {
    const createdCat = await this.catsService.create(args);
    return createdCat;
  }
Example #9
Source File: create-user.graphql-resolver.ts    From domain-driven-hexagon with MIT License 5 votes vote down vote up
@Mutation(() => IdResponse)
  async create(@Args('input') input: CreateUserRequest): Promise<IdResponse> {
    const command = new CreateUserCommand(input);

    const id = await this.commandBus.execute(command);

    return new IdResponse(id.unwrap().value);
  }
Example #10
Source File: tag.resolver.ts    From whispr with MIT License 5 votes vote down vote up
/**
   * Mutations
   */

  @Mutation(() => Tag)
  async createTag(@Args('tag') tag: TagInputType): Promise<ITag> {
    return this.tagService.create(tag);
  }
Example #11
Source File: auth.resolver.ts    From amplication with Apache License 2.0 5 votes vote down vote up
@Mutation(() => UserInfo)
  async login(@Args() args: LoginArgs): Promise<UserInfo> {
    return this.authService.login(args.credentials);
  }
Example #12
Source File: app.resolver.ts    From nestjs-jaeger-tracing with MIT License 5 votes vote down vote up
@Mutation('echoMessage')
  replyMessage(
    @Tracing() tracing: TracingData,
    @Args('message') message: string,
  ): Observable<string> {
    Logger.log({ echoMessage: tracing });
    return this.appService.echoMessage(message);
  }
Example #13
Source File: post.resolver.ts    From nest-casl with MIT License 5 votes vote down vote up
@Mutation(() => Post)
  @UseGuards(AccessGuard)
  @UseAbility(Actions.create, Post)
  async createPost(@Args('input') input: CreatePostInput) {
    return this.postService.create(input);
  }