Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-codegen-factories

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-codegen-factories

graphql-codegen plugin to generate factories

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
574
increased by28.7%
Maintainers
1
Weekly downloads
 
Created
Source

graphql-codegen-factories

graphql-codegen-factories is a plugin for GraphQL Code Generator that generates factories from a GraphQL schema and operations. The factories can then be used to mock data, e.g for testing or seeding a database.

For example, given this GraphQL schema:

type User {
  id: ID!
  username: String!
}

The following factory will be generated:

export type User = /* generated by @graphql-codegen/typescript */;

export function createUserMock(props: Partial<User> = {}): User {
  return {
    __typename: "User",
    id: "",
    username: "",
    ...props,
  };
}

It is also possible to generate factories from an operation, for example:

query GetUser {
  user {
    id
    username
  }
}

Will result in the following factories:

export type GetUserQuery = /* generated by @graphql-codegen/typescript-operations */;

export function createGetUserQueryMock(props: Partial<GetUserQuery> = {}): GetUserQuery {
  return {
    __typename: "Query",
    user: createGetUserQueryMock_user({}),
    ...props,
  };
}

export function createGetUserQueryMock_user(props: Partial<GetUserQuery["user"]> = {}): GetUserQuery["user"] {
  return {
    __typename: "User",
    id: "",
    username: "",
    ...props,
  };
}

You can also use a fake data generator to generate realistic factories such as:

import { faker } from "@faker-js/faker";

export function createUserMock(props: Partial<User> = {}): User {
  return {
    __typename: "User",
    id: faker.random.alphaNumeric(16),
    username: faker.lorem.word(),
    ...props,
  };
}

Showcase

Are you using this plugin? Let us know!

Contributors

Keywords

FAQs

Package last updated on 06 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc