Skip to content

Commit 3c7b230

Browse files
committed
mess around with graphql and convex
0 parents  commit 3c7b230

30 files changed

+8820
-0
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_CONVEX_URL="https://helpful-jaguar-142.convex.cloud"

.eslintrc.cjs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
env: { browser: true, es2020: true },
3+
extends: [
4+
'eslint:recommended',
5+
'plugin:@typescript-eslint/recommended',
6+
'plugin:react-hooks/recommended',
7+
],
8+
parser: '@typescript-eslint/parser',
9+
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
10+
plugins: ['react-refresh'],
11+
rules: {
12+
'react-refresh/only-export-components': 'warn',
13+
},
14+
}

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

convex.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"project": "graphql",
3+
"team": "sshader",
4+
"prodUrl": "https://helpful-jaguar-142.convex.cloud",
5+
"functions": "convex/",
6+
"authInfo": []
7+
}

convex/README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Welcome to your Convex functions directory!
2+
3+
Write your Convex functions here. See
4+
https://docs.convex.dev/using/writing-convex-functions for more.
5+
6+
A query function that takes two arguments looks like:
7+
8+
```javascript
9+
// myQueryFunction.js
10+
import { query } from "./_generated/server";
11+
12+
export default query(async ({ db }, { first, second }) => {
13+
// Validate arguments here.
14+
if (typeof first !== "number" || first < 0) {
15+
throw new Error("First argument is not a non-negative number.");
16+
}
17+
if (typeof second !== "string" || second.length > 1000) {
18+
throw new Error("Second argument is not a string of length 1000 or less.");
19+
}
20+
21+
// Query the database as many times as you need here.
22+
// See https://docs.convex.dev/using/database-queries to learn how to write queries.
23+
const documents = await db.query("tablename").collect();
24+
25+
// Write arbitrary JavaScript here: filter, aggregate, build derived data,
26+
// remove non-public properties, or create new objects.
27+
return documents;
28+
});
29+
```
30+
31+
Using this query function in a React component looks like:
32+
33+
```javascript
34+
const data = useQuery("myQueryFunction", { first: 10, second: "hello" });
35+
```
36+
37+
A mutation function looks like:
38+
39+
```javascript
40+
// myMutationFunction.js
41+
import { mutation } from "./_generated/server";
42+
43+
export default mutation(async ({ db }, { first, second }) => {
44+
// Validate arguments here.
45+
if (typeof first !== "string" || typeof second !== "string") {
46+
throw new Error("Both arguments must be strings");
47+
}
48+
49+
// Insert or modify documents in the database here.
50+
// Mutations can also read from the database like queries.
51+
const message = { body: first, author: second };
52+
const id = await db.insert("messages", message);
53+
54+
// Optionally, return a value from your mutation.
55+
return await db.get(id);
56+
});
57+
```
58+
59+
Using this mutation function in a React component looks like:
60+
61+
```javascript
62+
const mutation = useMutation("myMutationFunction");
63+
function handleButtonPress() {
64+
// fire and forget, the most common way to use mutations
65+
mutation({ first: "Hello!", second: "me" });
66+
// OR
67+
// use the result once the mutation has completed
68+
mutation({ first: "Hello!", second: "me" }).then((result) =>
69+
console.log(result)
70+
);
71+
}
72+
```
73+
74+
The Convex CLI is your friend. See everything it can do by running
75+
`npx convex -h` in your project root directory. To learn more, launch the docs
76+
with `npx convex docs`.

convex/_generated/api.d.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated API.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* Generated by [email protected].
8+
* To regenerate, run `npx convex dev`.
9+
* @module
10+
*/
11+
12+
import type { ApiFromModules } from "convex/api";
13+
import type * as initializeData from "../initializeData";
14+
import type * as xcxc from "../xcxc";
15+
16+
/**
17+
* A type describing your app's public Convex API.
18+
*
19+
* This `API` type includes information about the arguments and return
20+
* types of your app's query and mutation functions.
21+
*
22+
* This type should be used with type-parameterized classes like
23+
* `ConvexReactClient` to create app-specific types.
24+
*/
25+
export type API = ApiFromModules<{
26+
initializeData: typeof initializeData;
27+
xcxc: typeof xcxc;
28+
}>;

convex/_generated/dataModel.d.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated data model types.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* Generated by [email protected].
8+
* To regenerate, run `npx convex dev`.
9+
* @module
10+
*/
11+
12+
import type { DataModelFromSchemaDefinition } from "convex/schema";
13+
import type { DocumentByName, TableNamesInDataModel } from "convex/server";
14+
import { GenericId, GenericIdConstructor } from "convex/values";
15+
import schema from "../schema";
16+
17+
/**
18+
* The names of all of your Convex tables.
19+
*/
20+
export type TableNames = TableNamesInDataModel<DataModel>;
21+
22+
/**
23+
* The type of a document stored in Convex.
24+
*
25+
* @typeParam TableName - A string literal type of the table name (like "users").
26+
*/
27+
export type Doc<TableName extends TableNames> = DocumentByName<
28+
DataModel,
29+
TableName
30+
>;
31+
32+
/**
33+
* An identifier for a document in Convex.
34+
*
35+
* Convex documents are uniquely identified by their `Id`, which is accessible
36+
* on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
37+
*
38+
* Documents can be loaded using `db.get(id)` in query and mutation functions.
39+
*
40+
* **Important**: Use `myId.equals(otherId)` to check for equality.
41+
* Using `===` will not work because two different instances of `Id` can refer
42+
* to the same document.
43+
*
44+
* @typeParam TableName - A string literal type of the table name (like "users").
45+
*/
46+
export type Id<TableName extends TableNames> = GenericId<TableName>;
47+
48+
/**
49+
* An identifier for a document in Convex.
50+
*
51+
* Convex documents are uniquely identified by their `Id`, which is accessible
52+
* on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
53+
*
54+
* Documents can be loaded using `db.get(id)` in query and mutation functions.
55+
*
56+
* **Important**: Use `myId.equals(otherId)` to check for equality.
57+
* Using `===` will not work because two different instances of `Id` can refer
58+
* to the same document.
59+
*/
60+
export declare const Id: GenericIdConstructor<TableNames>;
61+
62+
/**
63+
* A type describing your Convex data model.
64+
*
65+
* This type includes information about what tables you have, the type of
66+
* documents stored in those tables, and the indexes defined on them.
67+
*
68+
* This type is used to parameterize methods like `queryGeneric` and
69+
* `mutationGeneric` to make them type-safe.
70+
*/
71+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;

convex/_generated/dataModel.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated data model types.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* Generated by [email protected].
8+
* To regenerate, run `npx convex dev`.
9+
* @module
10+
*/
11+
12+
import { GenericId } from "convex/values";
13+
14+
/**
15+
* An identifier for a document in Convex.
16+
*
17+
* Convex documents are uniquely identified by their `Id`, which is accessible
18+
* on the `_id` field. To learn more, see [Data Modeling](https://docs.convex.dev/using/data-modeling).
19+
*
20+
* Documents can be loaded using `db.get(id)` in query and mutation functions.
21+
*
22+
* **Important**: Use `myId.equals(otherId)` to check for equality.
23+
* Using `===` will not work because two different instances of `Id` can refer
24+
* to the same document.
25+
*/
26+
export const Id = GenericId;

0 commit comments

Comments
 (0)