Skip to content

updated fauna fql v10 #56185

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

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
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",
"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({
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'
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.