
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@hallettj/eslint-plugin-ts-graphql
Advanced tools
This ESLint plugin is intended to be used in combination with [ts-graphql-plugin][] which generates TypeScript interfaces to match GraphQL queries in TypeScript code. This plugin provides an autofix that applies type assertions those GraphQL queries. With
This ESLint plugin is intended to be used in combination with ts-graphql-plugin which generates TypeScript interfaces to match GraphQL queries in TypeScript code. This plugin provides an autofix that applies type assertions those GraphQL queries. With the type assertion queries can be passed to functions from, for example, Apollo Client, and result data types, and query variable types will propagate correctly.
The plugin also makes checks to enforce some properties that are required for smooth operation:
gql template tag must include exactly one GraphQL operation or
fragment.query, mutation, or subscription) must be
named.This plugin is based on code from @ts-gql/eslint-plugin.
Install:
$ yarn add --dev @hallettj/eslint-plugin-ts-graphql
Configure eslintrc.js:
module.exports = {
parserOptions: {
project: "./tsconfig.json",
},
env: {
node: true,
},
plugins: ["@hallettj/ts-graphql"],
rules: {
"@hallettj/ts-graphql/gql-type-assertion": "error",
},
};
Given a source file with content like this:
import { gql } from "@apollo/client";
export const getRecipesQuery = gql`
query getRecipes {
recipes {
id
title
description
}
}
`;
Running ESLint with the --fix option will update the file to look like this:
import { gql } from "@apollo/client";
export const getRecipesQuery = gql`
query getRecipes {
recipes {
id
title
description
}
}
` as import("@graphql-typed-document-node/core").TypedDocumentNode<
import("./__generated__/get-recipes").getRecipes,
import("./__generated__/get-recipes").getRecipesVariables
>;
FAQs
This ESLint plugin is intended to be used in combination with [ts-graphql-plugin][] which generates TypeScript interfaces to match GraphQL queries in TypeScript code. This plugin provides an autofix that applies type assertions those GraphQL queries. With
We found that @hallettj/eslint-plugin-ts-graphql 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
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.