![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
graphql-code-generator-plugin-typescript-typename-typeguards
Advanced tools
A plugin for graphql code generator that generate user defined type guards with __typename
This is a plugin for GraphQL Code Generator.
Generate user defined type guard functions from user defined type of schema.
What is a user defined type guard function? https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
npm install -D graphql-code-generator-plugin-typescript-typename-typeguards
import type { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
generates: {
"src/generated/graphql.ts": {
plugins: [
"typescript",
"graphql-code-generator-plugin-typescript-typename-typeguards",
],
},
},
};
export default config;
For GraphQL Code Generator v2
generates:
src/generated/graphql.ts:
plugins:
- typescript
- graphql-code-generator-plugin-typescript-typename-typeguards
type User {
id: ID!
name: String!
age: Int!
email: String!
address: Address!
friends: [User!]!
}
type Address {
country: String!
prefecture: String!
city: String!
street: String!
}
export const isUser = (field: { __typename?: string }): field is User =>
field.__typename === "User";
export const isAddress = (field: { __typename?: string }): field is Address =>
field.__typename === "Address";
If true, the type guard function's args will be generated as a string literal union.
const config: CodegenConfig = {
generates: {
"src/generated/graphql.ts": {
plugins: [
"typescript",
"graphql-code-generator-plugin-typescript-typename-typeguards",
],
config: {
argsAsStringLiteralUnion: true,
},
},
},
};
export const isUser = (field: {
__typename?: "User" | "Address";
}): field is User => field.__typename === "User";
export const isAddress = (field: {
__typename?: "User" | "Address";
}): field is Address => field.__typename === "Address";
See LICENSE
FAQs
A plugin for graphql code generator that generate user defined type guards with __typename
The npm package graphql-code-generator-plugin-typescript-typename-typeguards receives a total of 3 weekly downloads. As such, graphql-code-generator-plugin-typescript-typename-typeguards popularity was classified as not popular.
We found that graphql-code-generator-plugin-typescript-typename-typeguards 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.