P
Prismaā€¢6mo ago
aith

Setting up SafeQL for Prisma

I need help in setting up SafeQL for Prisma. I can't correctly configure my eslint.config and tsconfig. This is my eslint.config.mjs right now:
import tseslint from 'typescript-eslint';
import safeql from '@ts-safeql/eslint-plugin/config';

/** @type {import('eslint').Linter.Config} */
export default tseslint.config({
plugins: {
'@ts-safeql/eslint-plugin': safeql,
},
rules: {
'@ts-safeql/eslint-plugin': [
'error',
{
connections: [
{
// The migrations path:
migrationsDir: './prisma/migrations',
targets: [
// This makes `prisma.$queryRaw` and `prisma.$executeRaw` commands linted
{ tag: 'prisma.+($queryRaw|$executeRaw)', transform: '{type}[]' },
],
},
],
},
],
},
});
import tseslint from 'typescript-eslint';
import safeql from '@ts-safeql/eslint-plugin/config';

/** @type {import('eslint').Linter.Config} */
export default tseslint.config({
plugins: {
'@ts-safeql/eslint-plugin': safeql,
},
rules: {
'@ts-safeql/eslint-plugin': [
'error',
{
connections: [
{
// The migrations path:
migrationsDir: './prisma/migrations',
targets: [
// This makes `prisma.$queryRaw` and `prisma.$executeRaw` commands linted
{ tag: 'prisma.+($queryRaw|$executeRaw)', transform: '{type}[]' },
],
},
],
},
],
},
});
When I run npx eslint . I get the following:
Oops! Something went wrong! :(

ESLint: 9.4.0

TypeError: Key "rules": Key "@ts-safeql/eslint": Could not find plugin "@ts-safeql".
Oops! Something went wrong! :(

ESLint: 9.4.0

TypeError: Key "rules": Key "@ts-safeql/eslint": Could not find plugin "@ts-safeql".
4 Replies
RaphaelEtim
RaphaelEtimā€¢6mo ago
Hi @aith šŸ‘‹ Can you please confirm that you've correctly installed the dependency @ts-safeql/eslint-plugin? Also, have you taken a look at this section of the documentation
Configuration | SafeQL
Write SQL queries with confidence!
aith
aithOPā€¢6mo ago
Hi. Yes, I have that installed. I also downgraded ESLint from v9 to v8 cause v9 was causing a lot of problems.
"@ts-safeql/eslint-plugin": "^3.3.1",
"@ts-safeql/eslint-plugin": "^3.3.1",
And this is my eslintrc.js
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
plugins: [
"@typescript-eslint",
"import",
"prettier",
"@ts-safeql/eslint-plugin",
],
parserOptions: {
project: "./tsconfig.json",
},
extends: [
"airbnb-typescript/base",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.eslint.json",
},
rules: {
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-shadow": "off",
},
"@ts-safeql/check-sql": [
"error",
{
connections: [
{
connectionUrl: process.env.DATABASE_URL,
// The migrations path:
migrationsDir: "./prisma/migrations",
targets: [
// This makes `prisma.$queryRaw` and `prisma.$executeRaw` commands linted
{ tag: "prisma.+($queryRaw|$executeRaw)", transform: "{type}[]" },
],
},
],
},
],
};
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
plugins: [
"@typescript-eslint",
"import",
"prettier",
"@ts-safeql/eslint-plugin",
],
parserOptions: {
project: "./tsconfig.json",
},
extends: [
"airbnb-typescript/base",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.eslint.json",
},
rules: {
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-shadow": "off",
},
"@ts-safeql/check-sql": [
"error",
{
connections: [
{
connectionUrl: process.env.DATABASE_URL,
// The migrations path:
migrationsDir: "./prisma/migrations",
targets: [
// This makes `prisma.$queryRaw` and `prisma.$executeRaw` commands linted
{ tag: "prisma.+($queryRaw|$executeRaw)", transform: "{type}[]" },
],
},
],
},
],
};
When I run npx eslint . I get this:
Oops! Something went wrong! :(

ESLint: 8.57.0

Error: ESLint configuration in .eslintrc.js is invalid:
- Unexpected top-level property "@ts-safeql/check-sql".
Oops! Something went wrong! :(

ESLint: 8.57.0

Error: ESLint configuration in .eslintrc.js is invalid:
- Unexpected top-level property "@ts-safeql/check-sql".
Nevermind, I just realised what I was doing lol. I didn't put @ts-safeql/check-sql under the rules.
aith
aithOPā€¢6mo ago
Okay I got this to work. The error is showing up as well. However, is there a way to have it be that I get the errors displayed as I type (like how it is done in the example video of SafeQL)? Right now, I have to type the query and then run the command for it to show me the error.
aith
aithOPā€¢6mo ago
But I get the errors when I run the npx eslint . command:
18:9 error 'query' is assigned a value but never used @typescript-eslint/no-unused-vars
18:56 error Invalid Query: relation "userrss" does not exist @ts-safeql/check-sql

āœ– 2 problems (2 errors, 0 warnings)
18:9 error 'query' is assigned a value but never used @typescript-eslint/no-unused-vars
18:56 error Invalid Query: relation "userrss" does not exist @ts-safeql/check-sql

āœ– 2 problems (2 errors, 0 warnings)
Want results from more Discord servers?
Add your server