Skip to content

Instantly share code, notes, and snippets.

@bmorrisondev
Created August 22, 2024 19:48
Show Gist options
  • Save bmorrisondev/9c3d27517ae3e8e9f12bf41eca29d375 to your computer and use it in GitHub Desktop.
Save bmorrisondev/9c3d27517ae3e8e9f12bf41eca29d375 to your computer and use it in GitHub Desktop.
VSCode snippets to quickly generate Convex queries and mutations
{
"Convex Query": {
"prefix": "cvq",
"scope": "typescript",
"body": [
"export const ${1} = query({",
"\targs: {",
"\t\t${2}",
"\t},",
"\thandler: async (ctx, args) => {",
"\t\t${0}",
"\t}",
"})"
],
"description": "Generate a Convex query"
},
"Convex Query with Auth": {
"prefix": "cvqa",
"scope": "typescript",
"body": [
"export const ${1} = query({",
"\targs: {",
"\t\t${2}",
"\t},",
"\thandler: async (ctx, args) => {",
"\t\tconst auth = await ctx.auth.getUserIdentity()",
"\t\tif(!auth) {",
"\t\t\t\tthrow new Error(\"Not authorized\")",
"\t\t}",
"\t\t${0}",
"\t}",
"})"
],
"description": "Generate a Convex query and adds a check for auth"
},
"Convex Mutation": {
"prefix": "cvm",
"scope": "typescript",
"body": [
"export const ${1} = mutation({",
"\targs: {",
"\t\t${2}",
"\t},",
"\thandler: async (ctx, args) => {",
"\t\t${0}",
"\t}",
"})"
],
"description": "Generate a Convex mutation"
},
"Convex Mutation with Auth": {
"prefix": "cvma",
"scope": "typescript",
"body": [
"export const ${1} = mutation({",
"\targs: {",
"\t\t${2}",
"\t},",
"\thandler: async (ctx, args) => {",
"\t\tconst auth = await ctx.auth.getUserIdentity()",
"\t\tif(!auth) {",
"\t\t\t\tthrow new Error(\"Not authorized\")",
"\t\t}",
"\t\t${0}",
"\t}",
"})"
],
"description": "Generate a Convex mutation and adds a check for Auth"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment