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

@2fd/graphtype

v1.0.2

Published

"Generator of TypeScripts definitions for GraphQL"

Downloads

25

Readme

graphtype

Build Status

Generator of TypeScripts definitions for GraphQL

Install

    npm install -g @2fd/graphtype

Use

Generate definitions from live endpoint

    > graphtype -e http://localhost:8080/graphql -o ./doc/schema.d.ts

Generate definitions from json file

    > graphtype -s ./schema.json -o ./doc/schema.d.ts

./schema.json contains the result of GraphQL introspection query

Add scalars that must be represented as numbers

    > graphtype -e http://localhost:8080/graphql -n "UnsignedInt"
    /**
     * Represents `true` or `false` values.
     */
    export type UnsignedInt = number;

Add scalars that must be represented as numbers

    > graphtype -e http://localhost:8080/graphql -n "UnsignedInt"
    // ...
    export type UnsignedInt = number;
    // ...

Add scalars that must be represented as alias of other types

    > graphtype -e http://localhost:8080/graphql -s "NumberOrString=number | string"
    // ...
    export type NumberOrString = number | string;
    // ...

Help


    > graphtype -h

    Generator of TypeScripts definitions for GraphQL v1.0.0

    Usage: graphtype [OPTIONS]

     [OPTIONS]:
    -e, --endpoint        Graphql http endpoint ["https://domain.com/graphql"].
    -x, --header          HTTP header for request (use with --endpoint). ["Authorization: Token cb8795e7"].
    -q, --query           HTTP querystring for request (use with --endpoint) ["token=cb8795e7"].
    -s, --schema          Graphql Schema file ["./schema.json"].
    -o, --output          Output file (otherwise write on stdout).
    -n, --number-alias    Scalars that must be represented as numbers ["UnsignedInt"].
    -a, --alias           Scalars that must be represented as alias of other types ["NumberOrString=number | string"].
    -V, --version         Show graphtype version.
    -h, --help            Print this help

Translations

TypeScripts definitions (.d.ts)

Scalars

    # schema definitions

    scalar Boolean;
    scalar Int;
    scalar String;
    // typescript output

    /**
     * Represents `true` or `false` values.
     */
    export type Boolean = boolean;

    /**
     * Represents non-fractional signed whole numeric values. Int can represent values
     * between -(2^31) and 2^31 - 1.
     */
    export type Int = number;

    /**
     * Represents textual data as UTF-8 character sequences. This type is most often
     * used by GraphQL to represent free-form human-readable text.
     */
    export type String = string;

Autocomplete Scalars on Typescript

Enums

    # schema definitions

    enum __TypeKind {
        SCALAR
        OBJECT
        INTERFACE
        UNION
        ENUM
        INPUT_OBJECT
        LIST
        NON_NULL
    }
    // typescript output

    /**
     * An enum describing what kind of type a given `__Type` is.
     */
    export type __TypeKind = (

        /**
         * Indicates this type is a scalar.
         */
        "SCALAR" |

        /**
         * Indicates this type is an object. `fields` and `interfaces` are valid fields.
         */
        "OBJECT" |

        /**
         * Indicates this type is an interface. `fields` and `possibleTypes` are valid
         * fields.
         */
        "INTERFACE" |

        /**
         * Indicates this type is a union. `possibleTypes` is a valid field.
         */
        "UNION" |

        /**
         * Indicates this type is an enum. `enumValues` is a valid field.
         */
        "ENUM" |

        /**
         * Indicates this type is an input object. `inputFields` is a valid field.
         */
        "INPUT_OBJECT" |

        /**
         * Indicates this type is a list. `ofType` is a valid field.
         */
        "LIST" |

        /**
         * Indicates this type is a non-null. `ofType` is a valid field.
         */
        "NON_NULL"
    );

Autocomplete Enums on Typescript

Unions

    # schema definitions

    union ProjectCardItem = Issue | PullRequest;
    // typescript output

    /**
     * Types that can be inside Project Cards.
     */
    export type ProjectCardItem = Issue | PullRequest;

Autocomplete Enums on Typescript

Interfaces

    # schema definitions

    interface Node {
        id: ID!
    }
    // typescript output

    /**
     * An application user.
     */
    export interface Node {

        /**
         * .ID of the node.
         */
        id: NonNull<ID>;
    }

Autocomplete Enums on Typescript

Types

    # schema definitions

    type User implements Node {
        id: ID!
        email: String!
        name: String
        lastName: String
        friends: [ID!]!
    }
    // typescript output

    /**
     * An application user.
     */
    export interface User extends Node {

        /**
         * ID of the user.
         */
        id: NonNull<ID>;

        /**
         * contact email of the user.
         */
        email: NonNull<String>;

        /**
         * name of the user.
         */
        name?: Optional<String>;

        /**
         * last name of the user.
         */
        lastName?: Optional<String>;

        /**
         * list of friend´s ID of the user.
         */
        friends: NonNull<List<NonNull<ID>>>;
    }

Autocomplete Objects on Typescript

Inputs

    # schema definitions

    input NewUser {
        email: String!
        name: String
        lastName: String
        friends: [ID!] = []
    }
    // typescript output

    /**
     * An application user.
     */
    export interface NewUser {

        /**
         * contact email of the user.
         */
        email: NonNull<String>;

        /**
         * name of the user.
         */
        name?: Optional<String>;

        /**
         * last name of the user.
         */
        lastName?: Optional<String>;

        /**
         * @default []
         *
         * list of friend´s ID of the user.
         */
        friends?: Optional<List<NonNull<ID>>>;
    }

Autocomplete Inputs on Typescript