This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use("/graphql", (req, res, next) => { | |
const startHrTime = process.hrtime(); | |
res.on("finish", () => { | |
if (req.body && req.body.operationName) { | |
const elapsedHrTime = process.hrtime(startHrTime); | |
const elapsedTimeInMs = | |
elapsedHrTime[0] * 1000 + elapsedHrTime[1] / 1e6; | |
logger.info({ | |
type: "timing", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"extends": "react-app", | |
"rules": { | |
"no-shadow": "warn" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
parser: "@typescript-eslint/parser", // Specifies the ESLint parser | |
extends: [ | |
"plugin:@typescript-eslint/recommended" // Uses the recommended rules from the @typescript-eslint/eslint-plugin | |
], | |
parserOptions: { | |
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features | |
sourceType: "module" // Allows for the use of imports | |
}, | |
rules: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE "posts" ( | |
"id" serial NOT NULL, | |
"title" character varying(255) NOT NULL UNIQUE, | |
"body" TEXT NOT NULL, | |
CONSTRAINT posts_pk PRIMARY KEY ("id") | |
) WITH ( | |
OIDS=FALSE | |
); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MiddlewareFn } from "type-graphql"; | |
import { redis } from "./redis"; | |
import { MyContext } from "./types/MyContext"; | |
const ONE_DAY = 60 * 60 * 24; | |
export const rateLimit: (limit?: number) => MiddlewareFn<MyContext> = ( | |
limit = 50 | |
) => async ({ context: { req }, info }, next) => { | |
const key = `rate-limit:${info.fieldName}:${req.ip}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MiddlewareFn } from "type-graphql"; | |
import { redis } from "./redis"; | |
import { MyContext } from "./types/MyContext"; | |
const ONE_DAY = 60 * 60 * 24; | |
export const rateLimit: (limit?: number) => MiddlewareFn<MyContext> = ( | |
limitForAnonUser = 50, | |
limitForUser = 100 | |
) => async ({ context: { req }, info }, next) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Sentry from "@sentry/node"; | |
import imagemin from "imagemin"; | |
import mozjpeg from "imagemin-mozjpeg"; | |
import sharp from "sharp"; | |
import isJpg from "is-jpg"; | |
import * as aws from "aws-sdk"; | |
import { Upload } from "../../types/graphqlUtils"; | |
import { generateFilename } from "./generateFilename"; | |
export const s3 = new aws.S3({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const someFunc = ({ context }: ResolverData) => { | |
(context as any).value2 = "another value"; | |
}; | |
const addToContext: MiddlewareFn = (data, next) => { | |
(data.context as any).value = "new value"; | |
someFunc(data); | |
return next(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@UseMiddleware(hasRole("admin")) | |
@Query(() => String) | |
async hello() { | |
return "Hello World!"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Place your snippets for typescript here. Each snippet is defined under a snippet name and has a prefix, body and | |
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
// same ids are connected. | |
// Example: | |
"Type GraphQL Resolver": { | |
"prefix": "resolver", | |
"body": [ | |
"import { Resolver } from \"type-graphql\";", |