npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@duestel/graphql-mock

v0.0.23

Published

GraphQL mocking utilities for NestJS with decorator-based mock data generation

Readme

@duestel/graphql-mock

Decorator-based GraphQL mocking for NestJS. Generate realistic mock data for your resolvers.

Installation

npm install @duestel/graphql-mock

Quick Start

1. Import the module

import { GqlMockModule } from "@duestel/graphql-mock";

@Module({
  imports: [GraphQLModule.forRoot({ ... }), GqlMockModule],
})
export class AppModule {}

2. Define models with @Mock

import { Mock, MockHelpers } from "@duestel/graphql-mock";
import { randPhrase, randParagraph } from "@ngneat/falso";

// Base post
@ObjectType()
export class Post {
  @Mock(() => randPhrase())
  @Field()
  title: string;

  @Mock(() => randParagraph())
  @Field()
  content: string;

  @Mock(MockHelpers.enum(PostType))
  @Field(() => PostType)
  type: PostType;
}

// Post subtypes for unions
@ObjectType()
export class MediaPost extends Post {
  @Mock(() => PostType.MEDIA)
  declare type: PostType.MEDIA;

  @Mock(MockHelpers.relationMany(() => Media, { count: 3 }))
  @Field(() => [Media])
  media: Media[];
}

@ObjectType()
export class TextPost extends Post {
  @Mock(() => PostType.TEXT)
  declare type: PostType.TEXT;
}

3. Add @MockQuery to resolvers

@Resolver(() => Post)
export class PostResolver {
  // Simple list
  @MockQuery(() => Post, { count: 10 })
  @Query(() => [Post])
  posts() { ... }

  // Union types - randomly picks MediaPost or TextPost
  @MockQuery(MockQueryHelpers.union(MediaPost, TextPost), { count: 10 })
  @Query(() => [PostUnion])
  feed() { ... }

  // By ID with consistent ID matching
  @MockQueryWithStore((store, { id }) => store.get("Post", id))
  @Query(() => Post)
  post(@Args("id") id: string) { ... }
}

4. Pagination

// === Offset-based pagination ===
@ObjectType()
export class PaginatedPosts extends createPaginatedType(Post) {}
// Returns: { docs, totalDocs, limit, page, totalPages, prevPage, nextPage, hasPrevPage, hasNextPage }

// For unions
@ObjectType()
export class PaginatedFeed extends createUnionPaginatedType(PostUnion, [MediaPost, TextPost]) {}

// Resolver
@MockQuery(MockQueryHelpers.paginated(PaginatedPosts, { totalDocs: 100 }))
@Query(() => PaginatedPosts)
posts(@Args("pagination") pagination: PaginatedInput) { ... }

// === Cursor-based pagination ===
@ObjectType()
export class CursorPaginatedPosts extends createCursorPaginatedType(Post) {}
// Returns: { docs: Post[], nextCursor: string | null }

// For unions
@ObjectType()
export class CursorPaginatedFeed extends createUnionCursorPaginatedType(PostUnion, [MediaPost, TextPost]) {}

// Resolver
@MockQuery(MockQueryHelpers.cursorPaginated(CursorPaginatedPosts, { maxCursorIterations: 10 }))
@Query(() => CursorPaginatedPosts)
feed(@Args("pagination") pagination: CursorPaginatedInput) { ... }

5. Run with mock environment

NODE_ENV=mock npm run start

Decorators

| Decorator | Purpose | | ----------------------------------- | ---------------------------------- | | @Mock(generator, opts?) | Define mock generator for a field | | @MockQuery(type, opts?) | Mock a Query resolver | | @MockMutation(type, opts?) | Mock a Mutation resolver | | @MockResolveField(type, opts?) | Mock a field resolver | | @MockQueryWithStore(fn, opts?) | Query with persistent MockStore | | @MockMutationWithStore(fn, opts?) | Mutation with persistent MockStore |

Options

{ count?: number, environments?: string[], debug?: boolean }

Default environments: ['mock', 'staging', 'test']

MockHelpers

MockHelpers.enum(EnumType); // Random enum value
MockHelpers.relation(() => Type); // Nested object
MockHelpers.relationMany(() => Type, { count }); // Nested array
MockHelpers.union(
  () => TypeA,
  () => TypeB
); // Random union type

MockQueryHelpers

// Union types - randomly picks one type per item
MockQueryHelpers.union(MediaPost, TextPost);

// Offset-based pagination
MockQueryHelpers.paginated(PaginatedPosts, { totalDocs: 100 });

// Cursor-based pagination
MockQueryHelpers.cursorPaginated(CursorPaginatedPosts, {
  maxCursorIterations: 10,
});

MockStore

For stateful mocking where mutations persist data:

@MockMutationWithStore((store, { input }) => {
  store.set("Post", input.id, { title: input.title });
  return store.get("Post", input.id);
})
@Mutation(() => Post)
createPost(@Args("input") input: CreatePostInput) { ... }

License

MIT — Built by Duestel