Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
featureFlagSegments(
@Root() featureFlag: FeatureFlag,
@Ctx() ctx: BaseContext
): Promise {
return ctx.dataLoader.loaders.FeatureFlag.featureFlagSegments.load(featureFlag);
}
@FieldResolver(() => [FeatureFlagUser])
featureFlagUsers(
@Root() featureFlag: FeatureFlag,
@Ctx() ctx: BaseContext
): Promise {
return ctx.dataLoader.loaders.FeatureFlag.featureFlagUsers.load(featureFlag);
}
@Query(() => [FeatureFlag])
async featureFlags(@Args() { where, orderBy, limit, offset }: FeatureFlagWhereArgs): Promise<
FeatureFlag[]
> {
return this.service.find(where, orderBy, limit, offset);
}
// Custom resolver that has it's own InputType and calls into custom service method
@Query(() => [String])
async featureFlagsForUser(@Arg('where') where: FeatureFlagsForUserInput): Promise {
return this.service.flagsForUser(where);
}
@Query(() => FeatureFlag)
async featureFlag(@Arg('where') where: FeatureFlagWhereUniqueInput): Promise {
return this.service.findOne(where);
}
import "reflect-metadata";
import {Query, Resolver, buildSchema} from "type-graphql";
import express, {Application} from "express";
import {ApolloServer} from "apollo-server-express";
import {GraphQLSchema} from "graphql";
@Resolver()
class HelloResolver {
@Query(() => String) // eslint-disable-line require-await
async helloWorld(): Promise {
return "Hello World!";
}
}
export const createApolloServer = async (): Promise => {
const schema: GraphQLSchema = await buildSchema({resolvers: [HelloResolver]});
const apolloServer: ApolloServer = new ApolloServer({
schema,
playground: true,
});
return apolloServer;
};
import { ResetPasswordInput } from "./inputs/resetPassword.input"
import { cookieName } from "../../lib/config"
import { UserRepository } from "./user.repository"
import { CurrentUser } from "../shared/middleware/currentUser"
@Resolver(() => User)
export class UserResolver {
constructor(
private readonly userService: UserService,
private readonly userRepository: UserRepository,
private readonly userMailer: UserMailer,
) {}
// ME
@Authorized()
@Query(() => User, { nullable: true })
async me(@CurrentUser() currentUser: User): Promise {
return currentUser
}
// REGISTER
@Mutation(() => User)
async register(
@Arg("data") data: RegisterInput,
@Ctx() { req }: ResolverContext,
): Promise {
const user = await this.userService.create(data)
if (req.session) req.session.user = user
this.userMailer.sendWelcomeEmail(user)
return user
}
featureFlagUsers(
@Root() featureFlag: FeatureFlag,
@Ctx() ctx: BaseContext
): Promise {
return ctx.dataLoader.loaders.FeatureFlag.featureFlagUsers.load(featureFlag);
}
@Query(() => [FeatureFlag])
async featureFlags(@Args() { where, orderBy, limit, offset }: FeatureFlagWhereArgs): Promise<
FeatureFlag[]
> {
return this.service.find(where, orderBy, limit, offset);
}
// Custom resolver that has it's own InputType and calls into custom service method
@Query(() => [String])
async featureFlagsForUser(@Arg('where') where: FeatureFlagsForUserInput): Promise {
return this.service.flagsForUser(where);
}
@Query(() => FeatureFlag)
async featureFlag(@Arg('where') where: FeatureFlagWhereUniqueInput): Promise {
return this.service.findOne(where);
}
@Mutation(() => FeatureFlag)
async createFeatureFlag(
@Arg('data') data: FeatureFlagCreateInput,
@UserId() userId: string
): Promise {
return this.service.create(data, userId);
}
},
});
if (!value) {
value = await this.postRepo.save({
...input,
creatorId: req.session!.userId,
});
}
return {
codeReviewPost: value,
};
}
@Query(() => CodeReviewPost, {
nullable: true,
})
async getCodeReviewPostById(@Arg("id") id: string) {
return this.postRepo.findOne(id);
}
@FieldResolver()
numQuestions(@Root() root: CodeReviewPost) {
return this.questionRepo.count({ where: { postId: root.id } });
}
@Query(() => FindCodeReviewPostResponse)
async findCodeReviewPost(@Arg("input")
{
offset,
limit,
>,
to: ClassValueThunk,
through?: ClassValueThunk,
options?: RelayedQueryOptions,
isFieldResolver: boolean = false
): void {
const queryName = this.getQueryName(propertyKey, options)
const { Connection } = this.makeEdgeConnection(to, through)
this.registerArgs(target, propertyKey, options)
const middleware = RelayFromArrayCountFactory(target, propertyKey);
UseMiddleware(middleware)(target, propertyKey, descriptor)
if(isFieldResolver) {
FieldResolver(() => Connection, { ...options, name: queryName })(target, propertyKey, descriptor)
} else {
Query(() => Connection, { ...options, name: queryName })(target, propertyKey, descriptor)
}
}
constructor(@Inject('PostService') public readonly service: PostService) {}
@FieldResolver(() => User)
user(@Root() post: Post, @Ctx() ctx: BaseContext): Promise {
return ctx.dataLoader.loaders.Post.user.load(post);
}
@Query(() => [Post])
async posts(
@Args() { where, orderBy, limit, offset }: PostWhereArgs,
@Fields() fields: string[]
): Promise {
return this.service.find(where, orderBy, limit, offset, fields);
}
@Query(() => Post)
async post(@Arg('where') where: PostWhereUniqueInput): Promise {
return this.service.findOne(where);
}
@Mutation(() => Post)
async createPost(@Arg('data') data: PostCreateInput, @UserId() userId: string): Promise {
return this.service.create(data, userId);
}
@Mutation(() => Post)
async updatePost(
@Args() { data, where }: PostUpdateArgs,
@UserId() userId: string
): Promise {
return this.service.update(data, where, userId);
}
const data = await this.getSettings();
const settings = this.settingsRepository.create({
data: defaults(input, data),
});
await this.settingsRepository.save(settings);
return this.getSettings();
}
@Authorized()
@Query(returns => [PrimeField])
public allFields(): PrimeField[] {
return fields;
}
@Authorized()
@Query(returns => [PackageVersion], { nullable: true })
public system() {
return getPackagesVersion();
}
@Authorized()
@Mutation(returns => Boolean)
public async updateSystem(
@Arg('versions', type => [PackageVersionInput]) packagesVersion: PackageVersionInput[]
): Promise {
const allowedPackages = [
'@primecms/core',
'@primecms/ui',
...fields.map(({ packageName }) => packageName),
];
if (process.env.NODE_ENV !== 'production') {
@Resolver(of => Document)
export class DocumentResolver {
@InjectRepository(SchemaRepository)
private readonly schemaRepository: SchemaRepository;
@InjectRepository(SchemaFieldRepository)
private readonly schemaFieldRepository: SchemaFieldRepository;
@InjectRepository(DocumentRepository)
private readonly documentRepository: DocumentRepository;
private readonly documentTransformer: DocumentTransformer = new DocumentTransformer();
@Authorized()
@Query(returns => Document, { nullable: true })
public Document(
@Arg('id', type => ID, { description: 'Can be either uuid or documentId' }) id: string,
@Arg('locale', { nullable: true }) locale?: string,
@Arg('releaseId', type => ID, { nullable: true }) releaseId?: string
) {
const key = id.length === 36 ? 'id' : 'documentId';
return this.documentRepository.loadOneByDocumentId(id, key, {
releaseId,
locale,
});
}
@Authorized()
@Query(returns => DocumentConnection)
public allDocuments(
@Arg('sort', type => [DocumentSort], { defaultValue: 1, nullable: true }) sorts: string[],
import { User } from '../user/user.model';
import { Post } from './post.model';
import { PostService } from './post.service';
@Resolver(Post)
export class PostResolver {
constructor(@Inject('PostService') public readonly service: PostService) {}
@FieldResolver(() => User)
user(@Root() post: Post, @Ctx() ctx: BaseContext): Promise {
return ctx.dataLoader.loaders.Post.user.load(post);
}
@Query(() => [Post])
async posts(
@Args() { where, orderBy, limit, offset }: PostWhereArgs,
@Fields() fields: string[]
): Promise {
return this.service.find(where, orderBy, limit, offset, fields);
}
@Query(() => Post)
async post(@Arg('where') where: PostWhereUniqueInput): Promise {
return this.service.findOne(where);
}
@Mutation(() => Post)
async createPost(@Arg('data') data: PostCreateInput, @UserId() userId: string): Promise {
return this.service.create(data, userId);
}