Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated fauna fql v10 #56185

Merged
merged 23 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bcbbd5a
updated fauna fql v10
Shadid12 Sep 28, 2023
c437175
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Sep 28, 2023
daeee1d
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Sep 29, 2023
70b79ca
updated api to app routes
Shadid12 Sep 29, 2023
6b6c6e4
move out from pages routes
Shadid12 Sep 29, 2023
23eb1f4
using app routes and refactor
Shadid12 Sep 29, 2023
1fc320e
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Sep 29, 2023
97bdf20
using server action refactor
Shadid12 Oct 2, 2023
d09c3d0
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Oct 2, 2023
4b7fb8d
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Oct 2, 2023
f006d06
ran prettier updated readme v2
Shadid12 Oct 2, 2023
7b425d5
refactor tailwind
Shadid12 Oct 2, 2023
5bce54a
refactor tailwind and fix lint
Shadid12 Oct 2, 2023
39a0ce3
refactored to typescript
Shadid12 Oct 3, 2023
6f5dc6b
added types
Shadid12 Oct 3, 2023
f5abbf1
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Oct 3, 2023
6d4d34b
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Oct 3, 2023
30a188b
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Oct 4, 2023
f099cb1
updated prettier
Shadid12 Oct 4, 2023
47f18d4
Merge branch 'feat/update-fauna-fql-10' of https://github.com/fauna-l…
Shadid12 Oct 4, 2023
d4b2d0b
update action to typescript and run prettier
Shadid12 Oct 4, 2023
b98372e
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Oct 4, 2023
2fb4b78
Merge branch 'canary' into feat/update-fauna-fql-10
Shadid12 Oct 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions examples/with-fauna/lib/constants.js

This file was deleted.

49 changes: 0 additions & 49 deletions examples/with-fauna/lib/fauna.js

This file was deleted.

8 changes: 3 additions & 5 deletions examples/with-fauna/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"dependencies": {
"classnames": "2.3.1",
"date-fns": "2.28.0",
"faunadb": "4.5.4",
"graphql": "16.8.1",
"graphql-request": "4.3.0",
"fauna": "^1.2.0",
"next": "latest",
"react": "18.1.0",
Shadid12 marked this conversation as resolved.
Show resolved Hide resolved
"react-dom": "18.1.0",
Expand All @@ -20,8 +18,8 @@
"devDependencies": {
"autoprefixer": "^10.4.7",
"postcss": "^8.4.14",
"request": "^2.88.2",
"stream-to-promise": "3.0.0",
"tailwindcss": "^3.1.2",
"request": "^2.88.2"
"tailwindcss": "^3.1.2"
}
}
45 changes: 34 additions & 11 deletions examples/with-fauna/pages/api/entries/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
import { listGuestbookEntries, createGuestbookEntry } from '@/lib/fauna'
import { Client, fql } from 'fauna'

const client = new Client({
Shadid12 marked this conversation as resolved.
Show resolved Hide resolved
secret: process.env.FAUNA_CLIENT_SECRET,
})

export default async function handler(req, res) {
const handlers = {
// Get all entries from Fauna
GET: async () => {
const entries = await listGuestbookEntries()

res.json(entries)
try {
const dbresponse = await client.query(fql`
Entry.all()
`)
res.json(dbresponse.data.data)
} catch (error) {
res.status(403).json({
error: error.message,
})
}
},

// Create a new entry in Fauna
POST: async () => {
const {
body: { name, message },
} = req
const created = await createGuestbookEntry({
name,
message,
createdAt: new Date(),
})
res.json({})

try {
const dbresponse = await client.query(fql`
Entry.create({
name: ${name},
message: ${message},
createdAt: Time.now(),
})
`)
res.json(dbresponse.data.data)
} catch (error) {
res.status(403).json({
error: error.message,
})
}

res.json(created)
},
}

Expand All @@ -27,4 +50,4 @@ export default async function handler(req, res) {
}

await handlers[req.method]()
}
}
13 changes: 10 additions & 3 deletions examples/with-fauna/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cn from 'classnames'
import formatDate from 'date-fns/format'
import useSWR, { mutate, SWRConfig } from 'swr'
Shadid12 marked this conversation as resolved.
Show resolved Hide resolved
import 'tailwindcss/tailwind.css'
import { listGuestbookEntries } from '@/lib/fauna'
import SuccessMessage from '@/components/SuccessMessage'
import ErrorMessage from '@/components/ErrorMessage'
import LoadingSpinner from '@/components/LoadingSpinner'
Expand Down Expand Up @@ -50,7 +49,7 @@ const EntryItem = ({ entry }) => (
<p className="text-sm text-gray-500">{entry.name}</p>
<span className="text-gray-200 dark:text-gray-800">/</span>
<p className="text-sm text-gray-400 dark:text-gray-600">
{formatDate(new Date(entry.createdAt), "d MMM yyyy 'at' h:mm bb")}
{formatDate(new Date(entry.createdAt.isoString), "d MMM yyyy 'at' h:mm bb")}
</p>
</div>
</div>
Expand Down Expand Up @@ -168,11 +167,19 @@ const Guestbook = ({ fallback }) => {
}

export async function getStaticProps() {
const entries = await listGuestbookEntries()
let entries = []
let error = null
try {
entries = await fetch('/api/entries')
console.log('--->', entries)
} catch (error) {
error = error
}
return {
props: {
fallback: {
entries,
error,
},
},
}
Expand Down
14 changes: 0 additions & 14 deletions examples/with-fauna/schema.gql

This file was deleted.

193 changes: 0 additions & 193 deletions examples/with-fauna/scripts/setup.js

This file was deleted.