
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
βββββββ βββββββββββ ββββββ βββ ββββββββββ βββββββββββββββββ
βββββββββββββββββββ ββββββββββββ βββββββββββββββββββββββββββββ
ββββββββββββββ βββ ββββββββ βββββββ βββββββ βββ ββββββββ
ββββββββββββββ βββ ββββββββ βββββ βββββββ βββ ββββββββ
βββ ββββββββββββββββββββββ βββ βββ ββββββββ βββ ββββββββ
βββ ββββββββββββββββββββββ βββ βββ ββββββββ βββ ββββββββ
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.
$ npm install -g relay2ts
$ relay2ts --help
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"
}
}
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")}
}
`,
},
})
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
}
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.
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> {
β¦
}
Copyright 2017 Artsy, Eloy Duran eloy.de.enige@gmail.com
FAQs
Generates TypeScript interfaces for Relay fragments in source files.
The npm package relay2ts receives a total of 6 weekly downloads. As such, relay2ts popularity was classified as not popular.
We found that relay2ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Γ faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.