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 🙏

© 2024 – Pkg Stats / Ryan Hefner

typegraphql-description-loader

v1.1.0

Published

Webpack loader that takes @typegraphql JSDoc comments and inserts the contents into the decorator.

Downloads

2

Readme

TypeGraphQL Description Loader

npm version

Webpack loader that takes @typegraphql JSDoc comments and inserts the contents into the decorator (description property in options). TypeGraphQL then takes this comment and applies it to the schema it generates. This functionality will possibly be included in the TypeGraphQL reflection plugin, however there is no ETA for this.

This package allows you to comment your code and your GraphQL schema all in one, without duplicating code or missing either out. It is also eye-friendly, in comparison to multi-line strings in Javascript which would require escaping the newline characters. Particularly helpful in resolvers that have lots of methods & require (relatively) long descriptions, which can quickly get messy.

When you use the @typegraphql tag in a JSDoc comment, this package will assume that the decorator associated with the comment actually supports the TypeGraphQL AdvancedOptions argument. This means custom decorators are supported, as long as the arguments follow the layout of the official decorators.

Turn this:

import { Field, ID, Mutation, Arg, Resolver } from 'type-graphql';

@Resolver(of => Person)
class PersonResolver {

	/** ID of the person, sort of like a breathing barcode. */
	@Field(type => ID, { description: 'ID of the person, sort of like a breathing barcode.' })
	id: string;

	/** Name of the person, label used to identify them by humans. */
	@Field(type => String, { description: 'Name of the person, label used to identify them by humans.' })
	name: string;

	/** Update the person's name, usually an expensive legal process,
	 *  but here we use GraphQL mutations to do it quickly, and for no
	 *  expense.
	 */
	@Mutation(returns => Person, { complexity: 9, description: '\
Update the person\'s name, usually an expensive legal process, \
but here we use GraphQL mutations to do it quickly, and for no \
expense.'})
	updateName(@Arg('name') name: string): Person {
		const person = Persons.findByName(name);
		person.name = name;
		return person;
	}

}

Into this:

import { Field, ID, Mutation, Arg, Resolver } from 'type-graphql';

@Resolver(of => Person)
class PersonResolver {

	/** @typegraphql ID of the person, sort of like a breathing barcode. */
	@Field(type => ID)
	id: string;

	/** @typegraphql Name of the person, label used to identify them by humans. */
	@Field(type => String)
	name: string;

	/** @typegraphql Update the person's name, usually an expensive legal process,
	 *  but here we use GraphQL mutations to do it quickly, and for no
	 *  expense.
	 */
	@Mutation(returns => Person, { complexity: 9 })
	updateName(@Arg('name') name: string): Person {
		const person = Persons.findByName(name);
		person.name = name;
		return person;
	}

}

Installation

First setup the Webpack with the TypeScript and TypeGraphQL project you are working on. Then install this package:

$> npm install typegraphql-description-loader --save-dev

Next, use the loader in your Webpack configuration file. TypeGraphQL Description Loader needs to be loaded first, before ts-loader (loaders are used in reverse order).

module.exports = {
  ...
  module: {
      rules: [
          {
              test: /\.ts$/,
              use: ['ts-loader', 'typegraphql-description-loader'],
              exclude: /node_modules/,
          }
      ]
  },
  ...
};

To Do:

Currently only class property/method decorators are supported by this package, such as Field, Query, and Mutation. I will add support for class declarations themselves soon.

Please know that this package was put together quickly for use by me, the code is beyond messy.