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

@homebound/graphql-typescript-resolver-scaffolding

Package Overview
Dependencies
Maintainers
34
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@homebound/graphql-typescript-resolver-scaffolding

  • 1.40.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
34
Created
Source

This is a graphql-code-generator plugin that generates scaffolding for resolvers.

The generated scaffolds are extremely simple, and really just placeholders for your business logic and tests.

I.e. given ./schema/schema.graphql:

type Mutations {
  createFoo(input: FooInput): FooResult
}

These two files will be generated:

  • src/resolvers/mutations/createFoo.ts
  • src/resolvers/mutations/createFoo.test.ts

With some minimal boilerplate included.

If you break up your mutations into multiple files, i.e. ./schema/foo.graphql :

extend type Mutations {
  createFoo(input: FooInput): FooResult
}

Then the two files will be located at:

  • src/resolvers/mutations/foo/createFoo.ts
  • src/resolvers/mutations/foo/createFoo.test.ts

File Placement

The generator works on a "create file if not already in place" approach, which means you can't really "turn off" certain files that the generator thinks you need, you need to have your existing resolver files already in the place it expects, and then it won't overwrite them.

The placement logic is:

  • For types defined in schema.graphql
    • Queries go in src/resolvers/queries/<field-name>.ts
    • Mutations go in src/resolvers/mutations/<field-name>.ts
    • Objects go in src/resolvers/objects/<type-name>.ts
  • For types defined in fileName.graphql
    • extend type Querys go in src/resolvers/queries/<file-name>/<field-name.ts>
    • extend type Mutations go in src/resolvers/mutations/<file-name>/<field-name.ts>
    • Objects go in src/resolvers/objects/<file-name>/<type-name>.ts

I.e. each query and mutation gets its own dedicated <field-name.ts> file, potentially in a sub-directory based on the file name it's declared in.

Field resolvers for a given object go in a <type-name.ts>, potentially in a sub-directory based on the file the object is declared in.

Todo: Think about where extend type OtherObject things go, when both in schema.graphql (seems uncommon) or fileName.graphql. ...in the same sub-directory as fileName?

Config

The plugin only generates scaffolds for objects that are mapped types.

  • scaffolding.ignoreObjectsPattern will ignore certain objects that are mapped types, but you don't want scaffolded

Assumptions

  • Your context type is named Context and in src/context
  • You have @src/... import alias setup
  • You have a src/mutations/testUtils module with a run method
  • You use the FooInput/FooResult pattern for mutations
  • Your graphql files are in ./schema/*.graphql files

FAQs

Package last updated on 02 Nov 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