![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
graphql-codegen-typescript-react-apollo-named
Advanced tools
This is a modified version of the original graphql-codegen-react-apollo plugin.
This is a modified version of the original graphql-codegen-react-apollo plugin.
Basic changes:
import * as React from "react";
import {compose} from "react-apollo";
import {MyCustomQuery} from "./types.g";
interface Props {
bar: any
}
class MyComponentClass extends React.Component<Props & MyCustomQuery.Props> {
public async componentDidMount() {
const res = await this.props.myCustomQuery({variables: {
input: {
foo: 5,
}
}})
if (res.data && res.data.myCustomQuery) {
this.setState({
bar: res.data.myCustomQuery.bar
});
} else {
// handle error
};
}
public render(): React.ReactNode {
return <div>{{this.props.bar}}</div>
}
}
export const MyComponent = compose([
MyCustomQuery.HOC(),
])(MyComponentClass) as React.Component<Props>;
It would be great if we could use decorators. Skipping the whole compose()
-step and manual return type mapping.
Currently this isn't perfectly possible to due a https://github.com/Microsoft/TypeScript/issues/27883 in typescript which limits the customizing of return types. Specifically filtering out react props which have been set via injection.
Another minor persistent issue is the decorator's incapability of changing the decorated classes type, which blocks adding additional properties purely via the decorator thus forcing us to merge the properties in manually
Once this is fixed we hopefully can do something like this:
import * as React from "react";
import {compose} from "react-apollo";
import {MyCustomQuery} from "./types.g";
interface Props {
bar: any
}
@MyCustomQuery.HOC()
export default class MyComponent extends React.Component<Props> {
public async componentDidMount() {
const res = await this.props.myCustomQuery({variables: {
input: {
foo: 5,
}
}});
// ...
}
public render(): React.ReactNode {
// ...
}
}
Note that we just use the exported class directly without merging our custom query props into the react components props at all.
Luckily this issue is plagueing several other cool tools such as react-router
and react-intl
as well, so chances are good for this to be fixed.
FAQs
This is a modified version of the original graphql-codegen-react-apollo plugin.
The npm package graphql-codegen-typescript-react-apollo-named receives a total of 1 weekly downloads. As such, graphql-codegen-typescript-react-apollo-named popularity was classified as not popular.
We found that graphql-codegen-typescript-react-apollo-named 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.