-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.0.9 - Add graphql + nextjs demo/recipe (#2)
- Loading branch information
Arthur Buldauskas
authored
Jan 8, 2023
1 parent
388d6d4
commit 83ff6e7
Showing
41 changed files
with
756 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
.jambox/*.json | ||
.jambox/*.log |
Binary file added
BIN
+4.66 KB
recipes/nextjs-graphql-example/.yarn/cache/@next-env-npm-12.3.4-262e30cb7e-daa3fc11ef.zip
Binary file not shown.
Binary file added
BIN
+15.1 MB
...es/nextjs-graphql-example/.yarn/cache/@next-swc-linux-x64-gnu-npm-12.3.4-97054948a9-8.zip
Binary file not shown.
Binary file added
BIN
+86.4 KB
recipes/nextjs-graphql-example/.yarn/cache/@swc-helpers-npm-0.4.11-d20747f9c8-736857d524.zip
Binary file not shown.
Binary file added
BIN
+724 KB
...extjs-graphql-example/.yarn/cache/caniuse-lite-npm-1.0.30001441-c0558ca2f0-0f5aa8f7ea.zip
Binary file not shown.
Binary file added
BIN
+7.5 KB
recipes/nextjs-graphql-example/.yarn/cache/js-tokens-npm-4.0.0-0ac852e9e2-8a95213a5a.zip
Binary file not shown.
Binary file added
BIN
+4.25 KB
recipes/nextjs-graphql-example/.yarn/cache/loose-envify-npm-1.4.0-6307b72ccf-6517e24e0c.zip
Binary file not shown.
Binary file added
BIN
+13.8 KB
recipes/nextjs-graphql-example/.yarn/cache/nanoid-npm-3.3.4-3d250377d6-2fddd6dee9.zip
Binary file not shown.
Binary file added
BIN
+6.9 MB
recipes/nextjs-graphql-example/.yarn/cache/next-npm-12.3.4-cdaf2db0a7-d96fc4f5bc.zip
Binary file not shown.
Binary file added
BIN
+3.65 KB
recipes/nextjs-graphql-example/.yarn/cache/picocolors-npm-1.0.0-d81e0b1927-a2e8092dd8.zip
Binary file not shown.
Binary file added
BIN
+61.6 KB
recipes/nextjs-graphql-example/.yarn/cache/postcss-npm-8.4.14-c0d448b728-fe58766ff3.zip
Binary file not shown.
Binary file added
BIN
+1.07 MB
recipes/nextjs-graphql-example/.yarn/cache/react-dom-npm-18.2.0-dd675bca1c-7d323310be.zip
Binary file not shown.
Binary file added
BIN
+93.1 KB
recipes/nextjs-graphql-example/.yarn/cache/react-npm-18.2.0-1eae08fee2-88e38092da.zip
Binary file not shown.
Binary file added
BIN
+29 KB
recipes/nextjs-graphql-example/.yarn/cache/scheduler-npm-0.23.0-a379a6bc3b-d79192eeaa.zip
Binary file not shown.
Binary file added
BIN
+44.6 KB
recipes/nextjs-graphql-example/.yarn/cache/source-map-js-npm-1.0.2-ee4f9f9b30-c049a7fc4d.zip
Binary file not shown.
Binary file added
BIN
+154 KB
recipes/nextjs-graphql-example/.yarn/cache/styled-jsx-npm-5.0.7-d47abf001f-6195999391.zip
Binary file not shown.
Binary file added
BIN
+17.2 KB
recipes/nextjs-graphql-example/.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip
Binary file not shown.
Binary file added
BIN
+19.8 KB
...s-graphql-example/.yarn/cache/use-sync-external-store-npm-1.2.0-44f75d2564-5c639e0f8d.zip
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
## NextJS + GraphQL Jambox Demo | ||
|
||
## Install | ||
|
||
Make sure to run `yarn` and `yarn build` at the root of this repo. | ||
|
||
``` | ||
yarn | ||
``` | ||
|
||
Set a `browser` option in `jambox.config.js` to either `chrome` or `chromium` based on | ||
what you have installed on your system. The default is `chromium`. | ||
|
||
## Run | ||
|
||
``` | ||
❯ yarn dev | ||
yarn dev | ||
📻 Jambox 📻 | ||
Process launched | ||
ready - started server on 0.0.0.0:3000, url: http://localhost:3000 | ||
event - compiled client and server successfully in 2.1s (167 modules) | ||
wait - compiling /_error (client and server)... | ||
wait - compiling / (client and server)... | ||
event - compiled client and server successfully in 608 ms (171 modules) | ||
warn - Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works | ||
``` | ||
|
||
## Visit the page | ||
|
||
``` | ||
❯ yarn visit | ||
📻 Jambox 📻 | ||
http://jambox-demo-graphql.vercel.app parsed as a URI. Launching a browser instance | ||
chromium launched with 17172 | ||
Browser launched | ||
``` | ||
|
||
A page should load at `http://jambox-demo-graphql.vercel.app` | ||
|
||
![](./initial.png) | ||
|
||
Note that this URL is simply proxied to your local NextJS app at `localhost:3000` | ||
|
||
Search for a couple of Pokemon, like "Picachu" | ||
|
||
![](./pikachu.png) | ||
|
||
And "Slowpoke" | ||
|
||
![](./slowpoke.png) | ||
|
||
The GraphQL requests to `https://graphql-pokemon2.vercel.app` should work fine, | ||
you can search for more images. Now we can turn off network requests in `jambox.config.js` | ||
|
||
``` | ||
{ | ||
blockNetworkRequests: false | ||
} | ||
``` | ||
|
||
Now try searching for additional Pokemon and notice how the requests fail. However the initial | ||
requests should still work as they are cached in the `.jambox/` folder. | ||
|
||
You may clear the `.jambox` folder to start fresh. | ||
|
||
## Cleanup | ||
|
||
To shutdown the server: | ||
|
||
`curl localhost:9000/shutdown` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
browser: 'chromium', | ||
blockNetworkRequests: false, | ||
forward: { | ||
'http://jambox-demo-graphql.vercel.app': { | ||
target: 'http://localhost:3000', | ||
paths: ['**'], | ||
// websocket: true will ensure NextJS can make a WS connection + HMR | ||
websocket: true, | ||
}, | ||
}, | ||
cache: { | ||
write: 'auto', | ||
// GraphQL request | ||
stage: ['graphql-pokemon2.vercel.app/'], | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"next": "^12", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"scripts": { | ||
"dev": "../../jam.mjs next", | ||
"build": "next build", | ||
"start": "next start", | ||
"visit": "../../jam.mjs http://jambox-demo-graphql.vercel.app", | ||
"clear-cache": "rm -rf .jambox/*.json" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function App({ Component, pageProps }) { | ||
return <Component {...pageProps} />; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
const query = `query Pokemon($name: String) { | ||
pokemon(name: $name) { | ||
name | ||
image | ||
} | ||
}`; | ||
|
||
export default function IndexPage() { | ||
const [name, setName] = useState('Pikachu'); | ||
const [data, setData] = useState(null); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const handleSearch = (e) => { | ||
e.preventDefault(); | ||
setLoading(true); | ||
fetch('https://graphql-pokemon2.vercel.app', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query, | ||
variables: { | ||
name, | ||
}, | ||
}), | ||
}) | ||
.then((res) => res.json()) | ||
.then(({ data }) => { | ||
setLoading(false); | ||
setData(data); | ||
}); | ||
}; | ||
|
||
const handleInput = (e) => { | ||
e.preventDefault(); | ||
setName(e.target.value); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<input value={name} onChange={handleInput}></input> | ||
<button onClick={handleSearch}>Search</button> | ||
</div> | ||
<div> | ||
{data ? ( | ||
<img src={data.pokemon.image} alt={data.pokemon.name} /> | ||
) : loading ? ( | ||
<p>Loading…</p> | ||
) : ( | ||
<p>Search for an image</p> | ||
)} | ||
</div> | ||
</> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.