Skip to content

Instantly share code, notes, and snippets.

View giovannibenussi's full-sized avatar

Giovanni giovannibenussi

View GitHub Profile
@giovannibenussi
giovannibenussi / index.tsx
Last active January 2, 2024 21:17
Turso with a Custom Fetch Function
import { createClient } from "@libsql/client";
import { fetch } from "@libsql/hrana-client";
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
export async function retryOnceOnError(fn: any) {
try {
return await fn();
const EXCHANGE_RATES = gql`
{
rates(currency: "USD") {
rate
name
}
}
`
// imports...
import faker from 'faker'
// const typeDefs = ...
const resolvers = {
ExchangeRate: {
name: () => faker.finance.currencyName()
}
}
import React from 'react'
import ApolloClient from 'apollo-boost'
import { ApolloProvider } from '@apollo/react-hooks'
import Rates from './Rates'
import gql from 'graphql-tag'
const typeDefs = gql`
extend type ExchangeRate {
name: String!
}
const client = new ApolloClient({
uri: 'https://48p1r2roz4.sse.codesandbox.io',
typeDefs,
resolvers
})
const resolvers = {
ExchangeRate: {
name: () => 'This is a custom name!'
}
}
const typeDefs = gql`
extend type ExchangeRate {
name: String!
}
`
const EXCHANGE_RATES = gql`
{
rates(currency: "USD") {
rate
name @client
}
}
`
return data.rates.map(({ name, rate }) => (
<ul key={name}>
<li>
<strong>{name}</strong>: {rate}
</li>
</ul>
))
const EXCHANGE_RATES = gql`
{
rates(currency: "USD") {
currency
rate
name @client
}
}
`