Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad5a196

Browse files
committedMay 12, 2022
clean next
1 parent 2aa6cc1 commit ad5a196

File tree

10 files changed

+244
-70
lines changed

10 files changed

+244
-70
lines changed
 

‎package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"postinstall": "node ./scripts/fix-apollo.js",
66
"prebuild": "yarn run clean:build",
77
"build": "turbo run build build:types",
8+
"//build:pkg": "# Builds only packages, useful when running starters in dev mode",
9+
"build:pkg": "yarn run build '--filter=./packages/*'",
810
"publish:local": "yarn workspaces run yalc push # then, use 'yalc link <package-name>' in your project",
911
"link-yarn-legacy": "yarn workspaces foreach yarn link && ./scripts/link-duplicates.sh # deprecated, symlink creates issue with React, Webpack...",
1012
"unlink-yarn-legacy": "yarn workspaces foreach yarn unlink",

‎packages/graphql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"peerDependencies": {
4545
"@apollo/client": "^3.5.5",
4646
"apollo-server": "^2.18.2",
47-
"graphql": "^15.5.0",
47+
"graphql": "^16.2.0",
4848
"react": "^17.0.1"
4949
},
5050
"repository": {

‎packages/react-ui-bootstrap/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@apollo/client": "^3.5.5",
3131
"@vulcanjs/react-ui": "*",
3232
"@vulcanjs/react-ui-lite": "*",
33+
"graphql": "^15.5.0",
3334
"react": "^17.0.1",
3435
"react-dom": "^17.0.1"
3536
},
@@ -41,8 +42,7 @@
4142
"@types/underscore": "^1.11.1",
4243
"@vulcanjs/graphql": "*",
4344
"@vulcanjs/model": "*",
44-
"@vulcanjs/schema": "*",
45-
"graphql": "^15.5.0"
45+
"@vulcanjs/schema": "*"
4646
},
4747
"gitHead": "ee0303a08e123a54d65af6c36410fa8929f9427f"
4848
}

‎packages/react-ui-material/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"peerDependencies": {
4848
"@apollo/client": "^3.5.5",
4949
"@vulcanjs/react-ui": "*",
50+
"graphql": "^15.5.0",
5051
"react": "^17.0.1",
5152
"react-dom": "^17.0.1"
5253
},
@@ -55,8 +56,7 @@
5556
},
5657
"devDependencies": {
5758
"@types/lodash": "^4.14.168",
58-
"@types/underscore": "^1.11.1",
59-
"graphql": "^15.5.0"
59+
"@types/underscore": "^1.11.1"
6060
},
6161
"gitHead": "ee0303a08e123a54d65af6c36410fa8929f9427f"
6262
}

‎packages/react-ui/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"peerDependencies": {
4646
"@apollo/client": "^3.5.5",
47+
"graphql": "^15.5.0",
4748
"react": "^17.0.1",
4849
"react-dom": "^17.0.1"
4950
},
@@ -52,8 +53,7 @@
5253
},
5354
"devDependencies": {
5455
"@types/lodash": "^4.14.168",
55-
"@types/underscore": "^1.11.1",
56-
"graphql": "^15.5.0"
56+
"@types/underscore": "^1.11.1"
5757
},
5858
"gitHead": "ee0303a08e123a54d65af6c36410fa8929f9427f"
5959
}

‎starters/next/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@
222222
},
223223
"resolutions": {
224224
"@types/react": "^17.0.16",
225-
"@types/react-dom": "^17.0.16"
225+
"@types/react-dom": "^17.0.16",
226+
"graphql": "^15.6.2"
226227
},
227228
"installConfig": {
228229
"hoistingLimits": "dependencies"

‎starters/next/src/models/sampleModel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ export const schema: VulcanGraphqlSchema = {
2626
relation: {
2727
fieldName: "user",
2828
kind: "hasOne",
29+
// Deprecated old syntax, prefer passing a "model" directly
30+
//typeName: "User",
2931
model: User,
30-
//typeName: "Contributor",
3132
},
3233
},
3334
/** Timestamps handled by the database (you could also define updatedAt) */
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import type { ActionFunction } from "@remix-run/node";
2+
import { json, redirect } from "@remix-run/node";
3+
import { Form, useActionData } from "@remix-run/react";
4+
import * as React from "react";
5+
6+
import { requireUserId } from "~/session.server";
7+
8+
import {
9+
// When using a local executable shema (avoids an HTTP roundtrip)
10+
//processRequestWithGraphQL,
11+
// When using a remote endpoint
12+
sendGraphQLRequest,
13+
} from "@vulcanjs/remix-graphql/index.server";
14+
15+
type ActionData = {
16+
errors?: {
17+
title?: string;
18+
body?: string;
19+
};
20+
};
21+
22+
const INSERT_USER_MUTATION = /* GraphQL */ `
23+
mutation Insert_users($objects: [users_insert_input!]!) {
24+
insert_users(objects: $objects) {
25+
returning {
26+
id
27+
name
28+
}
29+
}
30+
}
31+
`;
32+
33+
// The `processRequestWithGraphQL` function can be used for both loaders and
34+
// actions!
35+
export const action: ActionFunction = (args) =>
36+
sendGraphQLRequest({
37+
args,
38+
// Space X API is one of the few to allow mutations
39+
// @see https://studio.apollographql.com/public/SpaceX-pxxbxen/home?variant=current
40+
endpoint: "https://api.spacex.land/graphql/",
41+
variables: {
42+
"objects": [
43+
{ "name": "Eric Burel" }
44+
]
45+
},
46+
//schema,
47+
query: INSERT_USER_MUTATION
48+
});
49+
50+
export default function NewNotePage() {
51+
const actionData = useActionData() as ActionData;
52+
const titleRef = React.useRef<HTMLInputElement>(null);
53+
const bodyRef = React.useRef<HTMLTextAreaElement>(null);
54+
55+
React.useEffect(() => {
56+
if (actionData?.errors?.title) {
57+
titleRef.current?.focus();
58+
} else if (actionData?.errors?.body) {
59+
bodyRef.current?.focus();
60+
}
61+
}, [actionData]);
62+
63+
return (
64+
<Form
65+
method="post"
66+
style={{
67+
display: "flex",
68+
flexDirection: "column",
69+
gap: 8,
70+
width: "100%",
71+
}}
72+
>
73+
<div>
74+
<label className="flex w-full flex-col gap-1">
75+
<span>Title: </span>
76+
<input
77+
ref={titleRef}
78+
name="title"
79+
className="flex-1 rounded-md border-2 border-blue-500 px-3 text-lg leading-loose"
80+
aria-invalid={actionData?.errors?.title ? true : undefined}
81+
aria-errormessage={
82+
actionData?.errors?.title ? "title-error" : undefined
83+
}
84+
/>
85+
</label>
86+
{actionData?.errors?.title && (
87+
<div className="pt-1 text-red-700" id="title-error">
88+
{actionData.errors.title}
89+
</div>
90+
)}
91+
</div>
92+
93+
<div>
94+
<label className="flex w-full flex-col gap-1">
95+
<span>Body: </span>
96+
<textarea
97+
ref={bodyRef}
98+
name="body"
99+
rows={8}
100+
className="w-full flex-1 rounded-md border-2 border-blue-500 py-2 px-3 text-lg leading-6"
101+
aria-invalid={actionData?.errors?.body ? true : undefined}
102+
aria-errormessage={
103+
actionData?.errors?.body ? "body-error" : undefined
104+
}
105+
/>
106+
</label>
107+
{actionData?.errors?.body && (
108+
<div className="pt-1 text-red-700" id="body-error">
109+
{actionData.errors.body}
110+
</div>
111+
)}
112+
</div>
113+
114+
<div className="text-right">
115+
<button
116+
type="submit"
117+
className="rounded bg-blue-500 py-2 px-4 text-white hover:bg-blue-600 focus:bg-blue-400"
118+
>
119+
Save
120+
</button>
121+
</div>
122+
</Form>
123+
);
124+
}
125+
126+
127+
128+
129+
130+
export default function IndexRoute() {
131+
// TODO: it would be more interesting to demo loading users
132+
// + updating them
133+
// const { data } = useLoaderData<LoaderData>();
134+
// if (!data) {
135+
// return "Ooops, something went wrong :(";
136+
// }
137+
const data: any = { posts: [] }
138+
139+
return (
140+
<main>
141+
<h1>Blog Posts</h1>
142+
<ul>
143+
{data.posts.map((post: any) => (
144+
<li key={post.id}>
145+
{post.title} (by {post.author.name})
146+
<br />
147+
{post.likes} Likes
148+
<Form method="post">
149+
{/* `remix-graphql` will automatically transform all posted
150+
form data into variables of the same name for the GraphQL
151+
operation */}
152+
<input hidden name="id" value={post.id} />
153+
<button type="submit">Like</button>
154+
</Form>
155+
</li>
156+
))
157+
</ul>
158+
</main>
159+
);
160+
}

0 commit comments

Comments
 (0)