Skip to content

Instantly share code, notes, and snippets.

@Zeko369
Created November 24, 2021 15:53
Show Gist options
  • Save Zeko369/ea9b47f18a243fc7ea1f5a01fa47b57b to your computer and use it in GitHub Desktop.
Save Zeko369/ea9b47f18a243fc7ea1f5a01fa47b57b to your computer and use it in GitHub Desktop.
Blitz snipptets
{
"ResolverImport": {
"prefix": "ri",
"body": "import { resolver } from 'blitz'"
},
"Resolver pipe": {
"prefix": "rp",
"body": "resolver.pipe(resolver.zod(schema$1), resolver.authorize([Role.Admin, Role.User$2]), "
},
"Blitz guard": {
"prefix": "bg",
"body": "import { pipeAuthorize } from 'app/guard'"
},
"Blitz query": {
"prefix": "bq",
"description": "Blitz query",
"body": [
"import { resolver } from \"blitz\";",
"import { z } from \"zod\";",
"",
"import db from \"db\";",
"",
"const $1 = resolver.pipe(resolver.zod(z.void()), resolver.authorize(), async () => {",
" return [];",
"});",
"",
"export default $1;"
]
},
"Blitz mutation": {
"prefix": "bm",
"description": "Blitz mutation",
"body": [
"import { resolver } from \"blitz\";",
"import { z } from \"zod\";",
"",
"import db from \"db\";",
"",
"const $1Fn = resolver.pipe(resolver.zod(z.void()), resolver.authorize(), async () => {",
" return [];",
"});",
"",
"export default $1Fn;"
]
},
"Prisma get by ID": {
"prefix": "pg",
"description": "Prisma get by ID",
"body": [
"const $1 = await db.$1.findUnique({where: {id: ${id:id}}});",
"if (!$1) {",
" throw new NotFoundError('$1 not found');",
"}"
]
},
"Prisma get many": {
"prefix": "pm",
"description": "Prisma get many",
"body": [
"const $1s = await db.$1.findMany({orderBy: {createdAt: 'desc'}});"
]
}
}
{
"Blitz page": {
"prefix": "bp",
"description": "Blitz page",
"body": [
"import React, { Suspense } from \"react\";",
"import { BlitzPage } from \"blitz\";",
"import { Spinner } from \"@chakra-ui/react\";",
"",
"import { Layout } from \"app/core/layouts/Layout\";",
"",
"const $1: React.FC = () => {",
" return <h1>Hello from $1</h1>;",
"}",
"",
"const $1Page: BlitzPage = () => {",
" return (",
" <Suspense fallback={<Spinner/>}>",
" <$1/>",
" </Suspense>",
" );",
"}",
"",
"$1Page.getLayout = (page) => <Layout title=\"$1\">{page}</Layout>;",
"",
"export default $1Page;"
]
},
"Next page": {
"prefix": "np",
"description": "Next page",
"body": [
"import React from \"react\";",
"import { NextPage } from \"next\";",
"",
"const $1Page: NextPage = () => {",
" return <h1>Hello from $1</h1>;",
"}",
"",
"export default $1Page;"
]
},
"React component": {
"prefix": "rc",
"description": "React component",
"body": [
"import React from \"react\";",
"",
"interface $1Props {}",
"",
"export const $1: React.FC<$1Props> = () => {",
" return <h1>$1</h1>;",
"};"
]
},
"React component small": {
"prefix": "rcs",
"description": "React component",
"body": [
"export const $1: React.FC<{}> = () => {",
" return <h1>$1</h1>;",
"};"
]
}
}

bg - guard import { pipeAuthorize } from 'app/guard'

bgc - guard typed import { typedCan } from 'app/guard'

bm - blitz mutation

import { resolver } from "blitz";
import { z } from "zod";

import db from "db";

const $name$Fn = resolver.pipe(resolver.zod(z.void()), resolver.authorize(), async () => {
  return [];
})

export default $name$Fn;

bp - blitz page

import React, { Suspense } from "react";
import { BlitzPage } from "blitz";
import { Spinner } from "@chakra-ui/react";

import { Layout } from 'app/core/layouts/Layout';

const $name$: React.FC = () => {
  return <h1>Hello from $name$</h1>;
};

const $name$Page: BlitzPage = () => {
  return (
    <Suspense fallback={<Spinner />}>
      <$name$ />
    </Suspense>
  );
};

$name$Page.getLayout = (page) => <Layout title="$name$">{page}</Layout>;

export default $name$Page;

bq - blitz query

import { resolver } from "blitz";
import { z } from "zod";

import db from "db";

const $name$ = resolver.pipe(resolver.zod(z.void()), resolver.authorize(), async () => {
  return [];
})

export default $name$;

np - next page

import React from "react";
import { NextPage } from "next";

const $name$Page: NextPage = () => {
  return (
    <h1>$name$</h1>
  );
};

export default $name$Page;

rc - react component with types

interface $name$Props {}

export const $name$: React.FC<$name$Props> = (props) => {
  return (
    <h1>$name$</h1>
  );
};

rci - import + react component with types

import React from "react";

interface $name$Props {}

export const $name$: React.FC<$name$Props> = (props) => {
  return (
    <h1>$name$</h1>
  );
};

rcis - import + react component simple

import React from "react";

export const $name$: React.FC<{}> = (props) => {
  return (
    <h1>$name$</h1>
  );
};

rcs - react component

export const $name$: React.FC<{}> = (props) => {
  return (
    <h1>$name$</h1>
  );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment