
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
relay-modern-typescript-transformer
Advanced tools
A transformer for Typescript that transforms GraphQL queries to require functions.
A Typescript transformer that transforms GraphQL queries to require functions.
$ yarn add relay-modern-typescript-transformer
$ yarn add relay-compiler
relay-compiler
is used to compile the queries into optimized .graphql files.
Read the Relay Modern docs for more info.
For fuse-box
, just add:
const { transformer } = require('relay-modern-typescript-transformer');
And then:
fuse = FuseBox.init(
{
...
transformers: {
before: [
transformer,
],
},
});
./node_modules/.bin/relay-compiler --src ./src --schema ./src/data/schema.json --extensions tsx
relay-compiler
is designed for Javascript sources, but work somewhat well on TS sources as well.
If it doesn't work for some reason, extract your query into a separate, smaller source file.
node fuse.js
Or whatever way you boot your project.
You can now use Relay Modern with Typescript!
const query = graphql`
query WelcomeScreenQuery {
pokemon(name: "Pikachu") {
name
weight {
minimum
maximum
}
}
}
`;
export class WelcomeScreen extends React.Component {
render() {
return (
<QueryRenderer
environment={environment}
query={query}
variables={{}}
render={({ error, props }) => {
if (error) {
return <div>{error.message}</div>;
} else if (props) {
return <WelcomePane />;
}
return <div>Loading</div>;
}}
/>
);
}
}
This code is placed in:
src/WelcomeScreen.tsx
When running the compiler, you will get this:
src/__generated__/WelcomeScreenQuery.graphql.js
The transformer will compile
const query = graphql...
into
const query = function () { return require('./__generated__/WelcomeScreenQuery.graphql.js')`.
Remember to name your query according to constraints.
It's not working?
First, make sure that relay-compiler
has created the graphql-files.
They should be placed along side your source files in a folder name __generated__/
.
graphql: Unexpected invocation at runtime. Either the Babel transform was not set up, or it failed to identify this call site.
If you get this error, then the transformer is missing. Make sure you have added it correctly to your config used by the Typescript compiler.
FAQs
A transformer for Typescript that transforms GraphQL queries to require functions.
The npm package relay-modern-typescript-transformer receives a total of 1 weekly downloads. As such, relay-modern-typescript-transformer popularity was classified as not popular.
We found that relay-modern-typescript-transformer 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
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.