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

gql-tg

v1.1.1

Published

Automatically generate TS type definitions for the GQL resolvers.

Downloads

11

Readme

GQL-TG NPM npm version HitCount dependencies issues

An automatic TS type definitions generator for GraphQL operations' resolvers.

ChangeLog changelog

  • Fixed the schema file reading issue.
  • Added support for custom schema file path/name.
  • Added support for custom definitions file path/name.

Why?

Type defintions are awesome. Which is why we love Typescript. Our inclination towards GraphQL is never ending for the ease and scalability it brings to our application servers. Here's the pain though:

Custom writing the type defintions for arguments and return values of the GraphQL resolvers.

Ta-Da! Wait no more! gql-tg brings static typings into your TypeScript resolvers for the GraphQL operations.

How?

gql-tg reads the specified graphql schema file, going through all the root operations and non scalar types found in the schema file and generates the TypeScript type definitions for the GraphQL:

  • Operations' Arguments
  • Operations' Non scalar return values
  • Non scalar types [ Input Type, Object Type, Union Type, Interface Type, Enum Type ]
  • Fragments( Support coming soon!)

for use in the corresponding resolvers meant for the operations. The type generator is internally based on three high level components as per the specified design: design

  • Tokenizer: Reads the GraphQL definitions and identifies the constituent tokens.
  • Parser: Parses Tokenized Definitions into JS objects.
  • Transpiler: Writes the TS type definition from the parsed JS objects.

CLI

The CLI can be installed both:

  • Locally npm i --save-dev gql-tg
  • Globally npm i -g gql-tg

The installed CLI exposes the typegen command which generates the type definitions by synchronously writing to the specified definitions file.

OPTIONS

The CLI supports two options as of now:

  • Input schema file path/name. (Defaults to 'schema.graphql' file in the PWD)
  • Output definitions file path/name. (Defaults to 'definitions.ts' file in the PWD)

Since, the CLI options are processed via the Node's native PROCESS*(process.argv)* object, they must be specified as plain-text strings without any verbose option prefixes, exactly in the order:

$ typegen   path/to/schema/file.graphql   path/to/type/definitions/file.ts

Paths are resolved relative to the current working directory.

e.g. For the following project structure:

|-src
    |-schema.graphql
    |-js/
    |-types/
|-package.json
|-.gitignore

To generate the type definitions into the /src/js/, executing the command (installed globally) from the project root:

~/path/to/project-root$ typegen ./src/schema.graphql ./src/js/gqlTypeDefinitions.ts

Contribute contributions welcome

To get started:

  1. Clone the repo onto your local machine. git clone https://github.com/ai-zubair/gql-tg.git
  2. Install the dependencies(mainly developmental) npm i
  3. Build the project npm start
  4. The source files are read from src directory and the build files are written to the build directory, both in the project root. This can be changed in tsconfig.json.

The project stands in the intial phase for now. As such, suggestions, improvements, issues, features are openly welcome.