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 🙏

© 2025 – Pkg Stats / Ryan Hefner

relay2ts

v0.2.0

Published

Generates TypeScript interfaces for Relay fragments in source files.

Downloads

681

Readme

██████╗ ███████╗██╗      █████╗ ██╗   ██╗██████╗ ████████╗███████╗
██╔══██╗██╔════╝██║     ██╔══██╗╚██╗ ██╔╝╚════██╗╚══██╔══╝██╔════╝
██████╔╝█████╗  ██║     ███████║ ╚████╔╝  █████╔╝   ██║   ███████╗
██╔══██╗██╔══╝  ██║     ██╔══██║  ╚██╔╝  ██╔═══╝    ██║   ╚════██║
██║  ██║███████╗███████╗██║  ██║   ██║   ███████╗   ██║   ███████║
╚═╝  ╚═╝╚══════╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝   ╚═╝   ╚══════╝

This CLI tool takes the GraphQL query fragments of your Relay container and generates a TypeScript interface for them.

It sacrifices DRYness in favour of exactness, by adding these interfaces into the files that contain the queries. If you prefer a single file that describes your full GraphQL schema with an interface per type, take a look at gql2ts.

Installation

$ npm install -g relay2ts
$ relay2ts --help

Configuration

In addition to the pure CLI options, you can also configure the GraphQL schema location via these methods, and the interface name can be configured in your package.json with:

{
  …
  "dependencies": { … },
  "graphql": {
    "file": "data/schema.json",
    "tsInterfaceName": "RelayProps"
  }
}

Example

  1. Given a source file that contains a query like the following:

    export default Relay.createContainer(ArtworkGrid, {
      fragments: {
        artworks: () => Relay.QL`
          fragment on Artwork @relay(plural: true) {
            id
            aliased_title: title
            artists {
              name
            }
            image {
              aspect_ratio
            }
            ${Artwork.getFragment("artwork")}
          }
        `,
      },
    })
  2. And a GraphQL schema that contains:

    type Artwork {
      id: String!
      title: String!
      artists: [Artist]
      image: Image
    }
    
    type Artist {
      name: String!
    }
    
    type Image {
      aspect_ratio: Float
    }
  3. Presto, the following TypeScript interface gets generated:

    interface IRelayProps {
      artworks: Array<{
        id: string,
        aliased_title: string,
        artists: Array<{
          name: string,
        } | null> | null,
        image: {
          aspect_ratio: number | null,
        } | null,
      }>,
    }

It is important to note that, because Relay only exposes the exact fields that this component requested, the interface also only contains these fields and not also those of the Artwork component.

Usage

Initially the interface will get appended to the file. However, afterwards you are free to move it around in the file, subsequent updates will replace the interface where ever it’s located.

You shouldn’t try to use it as your main props interface, unless your component really only has Relay props, rather do:

interface Props extends IRelayProps {
  onClick: () => void
}

class ArtworkGrid extends React.Component<Props, null> {
  …
}

License

MIT

Copyright 2017 Artsy, Eloy Duran [email protected]