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

graphql-server-types

v0.2.3

Published

Base project for creating a console application in Typescript

Downloads

9

Readme

master master

graphql-server-types

Generate intergalactic-quality server-side Typescript types from GraphQL schemas.

CLI Usage

The generator is available using the generate-server-types command.

Input file

Use -i, --input to supply the input file path:

generate-server-types --input path/to/your/schema.graphql

Or pipe contents in via stdio:

cat path/to/your/schema.graphql | generate-server-types

Output file

Use -o, --output to supply the output file path:

generate-server-types --output path/to/your/types.d.ts

If an output file path is not supplied, then the output is written to stdout:

generate-server-types > path/to/your/types.d.ts

Formatting

The generated output will be formatted with Prettier. The path to a config file may be supplied; otherwise, the local config or default settings will be used.

Use -p, --prettierConfig specify the file path to your Prettier config:

generate-server-types --prettierConfig path/to/your/.prettierrc

Context and Info

The generated output will import Context and Info types from a sibling ./context.ts file. These allow you to specify the type of context and info objects that the GraphQL server will pass to your resolvers. This generator does not generate the file for you; however, it is required. At minimum, create a file named context.ts next to your generated types file with the following content.

Use -c, --contextLocation override the import path to your context types file:

generate-server-types --contextLocation ./import/path/to/your/context.ts

Custom Scalars

The generated output will import types for custom scalars from a sibling ./scalars.ts file. This generator does not generate the file for you; however, it is required. At minimum, create a file named scalars.ts next to your generated types file and export (or re-export) a type for each custom scalar.

export type MyCustomScalar = string;

Use -s, --scalarsLocation override the import path to your custom scalar types file:

generate-server-types --scalarsLocation ./import/path/to/your/scalars.ts

Watch mode

Use -w, --watch to run in watch mode. In watch mode, both --input and --output must be specified (you can't leverage stdio/stdout). Running in watch mode will immediately generate output file and then update the output file on each subsequent change to the input file.

generate-server-types --input schema.graphql --output types.g.ts --watch

Programatic Usage

The generator is available by importing the generateServerTypes function.

import { readFileSync } from 'fs';
import { generateServerTypes } from 'graphql-server-types';

const schema = readFileSync('path/to/your/schema.graphql').toString('utf8');

const serverTypes = generateServerTypes(schema);

The second options parameter allows for custom formatting options and other tweaks.

const serverTypes = generateServerTypes(schema, {
  prettierOptions: { singleQuote: true },
  contextLocation: './import/path/to/your/context.ts',
  scalarsLocation: './import/path/to/your/scalars.ts',
});

Watch mode is not available during programmatic usage.

For Contributors:

Build this project

  1. Build the code: npm run build

Create and run tests

  1. Add tests by creating files with the .tests.ts suffix
  2. Run the tests: npm t
  3. Test coverage can be viewed at /coverage/lcov-report/index.html

Generated with generator-ts-console