How to use the @nestjs/graphql.ResolveProperty 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 / user.resolver.ts View on Github external
// 	return user
	// }

	@Subscription(() => Object, {
		filter: (payload: any, variables: any) => {
			// console.log('payload', payload)
			// console.log('variables', variables)
			// return payload.menuPublishByOrder.currentsite === variables.currentsite
			return true
		}
	})
	async newUser(@Context('pubsub') pubsub: any): Promise {
		return pubsub.asyncIterator(USER_SUBSCRIPTION)
	}

	@ResolveProperty()
	async fullName(@Parent() user: User): Promise {
		const { firstName, lastName } = user
		return `${firstName} ${lastName}`
	}

	// @ResolveProperty()
	// async local(@Parent() user: User): Promise {
	// 	const { local } = user
	// 	local.password = ''
	// 	return local
	// }

	@Mutation()
	async validateUser(
		@Args('text') text: string,
		@Args('input') input: CreateUserInput
github SolidZORO / leaa / packages / leaa-api / src / modules / user / user.resolver.ts View on Github external
} from '@leaa/common/src/dtos/user';
import { UserService } from '@leaa/api/src/modules/user/user.service';
import { UserProperty } from '@leaa/api/src/modules/user/user.property';
import { CurrentUser, Permissions } from '@leaa/api/src/decorators';
import { PermissionsGuard } from '@leaa/api/src/guards';

@Resolver(() => User)
export class UserResolver {
  constructor(private readonly userService: UserService, private readonly userProperty: UserProperty) {}

  @ResolveProperty(() => [String])
  async flatPermissions(@Parent() user: User | undefined): Promise {
    return this.userProperty.flatPermissions(user);
  }

  @ResolveProperty(() => [String])
  async permissions(@Parent() user: User | undefined): Promise {
    return this.userProperty.permissions(user);
  }

  //

  // fot Test GraphQL
  @Query(() => Float)
  async ram(): Promise {
    return Math.random();
  }

  @UseGuards(PermissionsGuard)
  @Permissions('user.list-read')
  @Query(() => UsersWithPaginationObject)
  async users(@Args() args: UsersArgs, @CurrentUser() user?: User): Promise {
github vendure-ecommerce / vendure / packages / elasticsearch-plugin / src / elasticsearch-resolver.ts View on Github external
export class AdminElasticSearchResolver implements SearchResolver {
    constructor(private elasticsearchService: ElasticsearchService) {}

    @Query()
    @Allow(Permission.ReadCatalog)
    async search(
        @Ctx() ctx: RequestContext,
        @Args() args: QuerySearchArgs,
    ): Promise> {
        const result = await this.elasticsearchService.search(ctx, args.input, false);
        // ensure the facetValues property resolver has access to the input args
        (result as any).input = args.input;
        return result;
    }

    @ResolveProperty()
    async facetValues(
        @Ctx() ctx: RequestContext,
        @Parent() parent: { input: SearchInput },
    ): Promise> {
        return this.elasticsearchService.facetValues(ctx, parent.input, false);
    }

    @Mutation()
    @Allow(Permission.UpdateCatalog)
    async reindex(@Ctx() ctx: RequestContext): Promise {
        return this.elasticsearchService.reindex(ctx);
    }
}
github TimurRK / nestjs-example / src / core / user / user.resolver.ts View on Github external
@Mutation(() => User)
  public async userAddPermission(
    @Args({ name: 'userId', type: () => ID }) userId: string,
    @Args({ name: 'permissionId', type: () => ID }) permissionId: number
  ) {
    const user = await this.userService.findOne(userId, { relations: ['permissions'] });
    const permission = await this.permissionService.findOne(permissionId);

    user.permissions.push(permission);

    return await this.userService.save(user);
  }

  @Loader(PermissionLoader)
  @ResolveProperty()
  public async permissions(
    @Parent() user: User,
    @Context('PermissionLoader') permissionLoader: DataLoader
  ) {
    return await permissionLoader.load(user.id);
  }
}
// tslint:enable: no-unsafe-any
github vendure-ecommerce / vendure / packages / core / src / api / resolvers / admin / global-settings.resolver.ts View on Github external
import { Allow } from '../../decorators/allow.decorator';

@Resolver('GlobalSettings')
export class GlobalSettingsResolver {
    constructor(private configService: ConfigService, private globalSettingsService: GlobalSettingsService) {}

    @Query()
    @Allow(Permission.Authenticated)
    async globalSettings() {
        return this.globalSettingsService.getSettings();
    }

    /**
     * Exposes a subset of the VendureConfig which may be of use to clients.
     */
    @ResolveProperty()
    serverConfig() {
        return {
            customFieldConfig: this.configService.customFields,
        };
    }

    @Mutation()
    @Allow(Permission.UpdateSettings)
    async updateGlobalSettings(@Args() args: MutationUpdateGlobalSettingsArgs) {
        return this.globalSettingsService.updateSettings(args.input);
    }
}
github neoteric-eu / nestjs-auth / src / app / message / resolvers / message.resolver.ts View on Github external
messageUpdated() {
		return {
			subscribe: withFilter(() => this.pubSub.asyncIterator('messageUpdated'),
				(payload, variables, context) => this.subscriptionsService.messageUpdated(payload, variables, context))
		};
	}

	@Subscription('messageDeleted')
	messageDeleted() {
		return {
			subscribe: withFilter(() => this.pubSub.asyncIterator('messageDeleted'),
				(payload, variables, context) => this.subscriptionsService.messageDeleted(payload, variables, context))
		};
	}

	@ResolveProperty('author')
	async getAuthor(@Parent() message: MessageEntity): Promise {
		try {
			return this.userService.findOneById(message.authorId);
		} catch (e) {
			return this.userService.create({});
		}
	}

	@Subscription('newMessage')
	newMessage() {
		return {
			subscribe: withFilter(() => this.pubSub.asyncIterator('newMessage'),
				(payload, variables, context) => this.subscriptionsService.newMessage(payload, variables, context))
		};
	}
github feater-dev / feater / server / src / api / resolver / instance-service-resolver.component.ts View on Github external
export class InstanceServiceResolver {
    constructor(
        private readonly containerStatusChecker: ContainerStateCheckerComponent,
        private readonly ipAddressChecker: IpAddressCheckerComponent,
    ) {}

    @ResolveProperty('containerState')
    async getState(
        @Parent() instanceService: InstanceServiceTypeInterface,
    ): Promise {
        return this.containerStatusChecker.check(
            instanceService.containerNamePrefix,
        );
    }

    @ResolveProperty('ipAddress')
    async getIpAddress(
        @Parent() instanceService: InstanceServiceTypeInterface,
    ): Promise {
        return this.ipAddressChecker.check(instanceService.containerNamePrefix);
    }
}
github vendure-ecommerce / vendure / packages / core / src / api / resolvers / entity / payment-entity.resolver.ts View on Github external
import { Parent, ResolveProperty, Resolver } from '@nestjs/graphql';

import { Payment } from '../../../entity/payment/payment.entity';
import { Refund } from '../../../entity/refund/refund.entity';
import { OrderService } from '../../../service/services/order.service';
import { RequestContext } from '../../common/request-context';
import { Ctx } from '../../decorators/request-context.decorator';

@Resolver('Payment')
export class PaymentEntityResolver {
    constructor(private orderService: OrderService) {}

    @ResolveProperty()
    async refunds(@Ctx() ctx: RequestContext, @Parent() payment: Payment): Promise {
        if (payment.refunds) {
            return payment.refunds;
        } else {
            return this.orderService.getPaymentRefunds(payment.id);
        }
    }
}
github chnirt / nestjs-graphql-best-practice / src / resolvers / dashboard / dashboard.resolver.ts View on Github external
}

	@Mutation(() => Dashboard)
	async createDashboard(
		@Args('data') data: GraphQLJSON,
		@Context('currentUser') currentUser: User
	): Promise {
		const dashboard = new Dashboard()

		dashboard.userId = currentUser._id
		dashboard.data = JSON.stringify(data)

		return await this.dashboardRepository.save(dashboard)
	}

	@ResolveProperty(() => GraphQLJSON)
	async data(@Parent() dashboard: Dashboard): Promise {
		const { data } = dashboard
		return await JSON.parse(data)
	}
}