Skip to content

Instantly share code, notes, and snippets.

@aleclarson
Last active June 16, 2019 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleclarson/e95cc22a52f2ec4fb5bc689a17ea6d9c to your computer and use it in GitHub Desktop.
Save aleclarson/e95cc22a52f2ec4fb5bc689a17ea6d9c to your computer and use it in GitHub Desktop.
import * as React from 'react'
import { UserView } from './components/user'
import gql from 'vana/gql'
// Create a data store with vana.useGraphQL
const data = gql.create({
...options,
queries: {
users: gql`...`,
}
})
// Provide your data store to descendants.
const App = gql(data, () => (
<Child />
))
const Child = () => {
// The queries are observable!
const users = gql.useObserved(data, 'users')
return <>
{users.map(user => (
<UserView key={user.id} user={user} />
))}
</>
}
@aleclarson
Copy link
Author

aleclarson commented Jun 16, 2019

Features

  • Built on top of React Suspense
  • Reversible optimistic updates for free (thanks to Immer!)
  • No more handwritten queries (including mutations!)

@aleclarson
Copy link
Author

aleclarson commented Jun 16, 2019

Missing pieces

  • No request batching
    • Use HTTP/2 instead
  • How are queries generated?
  • How should caching work?
  • How should subscriptions work?
    • Local observables are updated in response to change events
    • An event is sent to the client to identify what caused the change

@aleclarson
Copy link
Author

Note to self: Figure out the new API here.

@aleclarson
Copy link
Author

@aleclarson
Copy link
Author

aleclarson commented Jun 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment