How to use graphql-hooks - 10 common examples

To help you get started, weโ€™ve selected a few graphql-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ShadOoW / web-starter-kit / src / lib / init-graphql.js View on Github external
function create(initialState = {}) {
  return new GraphQLClient({
    ssrMode: isServer,
    url: 'https://rickandmortyapi.com/graphql',
    cache: memCache({ initialState }),
    fetch: typeof window !== 'undefined' ? fetch.bind() : unfetch, // eslint-disable-line
  });
}
github zeit / next.js / examples / with-graphql-hooks / lib / init-graphql.js View on Github external
function create(initialState = {}) {
  return new GraphQLClient({
    ssrMode: typeof window === 'undefined',
    url: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn',
    cache: memCache({ initialState }),
    fetch: typeof window !== 'undefined' ? fetch.bind() : unfetch, // eslint-disable-line
  })
}
github datenguide / datenguide / src / lib / graphql-init.js View on Github external
function create(initialState = {}) {
  return new GraphQLClient({
    ssrMode: typeof window === 'undefined',
    url: process.env.DATENGUIDE_API,
    cache: memCache({ initialState }),
    fetch: typeof window !== 'undefined' ? fetch.bind() : unfetch // eslint-disable-line
  })
}
github zeit / next.js / examples / with-graphql-hooks / components / post-upvoter.js View on Github external
export default function PostUpvoter({ votes, id, onUpdate }) {
  const [updatePost] = useMutation(UPDATE_POST)

  return (
    <button> {
        try {
          const result = await updatePost({
            variables: {
              id,
              votes: votes + 1,
            },
          })

          onUpdate &amp;&amp; onUpdate(result)
        } catch (e) {
          console.error('error upvoting post', e)
        }</button>
github zeit / next.js / examples / with-graphql-hooks / components / submit.js View on Github external
export default function Submit({ onSubmission }) {
  const [createPost, state] = useMutation(CREATE_POST)

  return (
    <form> handleSubmit(event, onSubmission, createPost)}&gt;
      <h1>Submit</h1>
      <input required="" type="text" placeholder="title">
      <input required="" type="url" name="url" placeholder="url">
      <button type="submit">{state.loading ? 'Loading...' : 'Submit'}</button>
      <style>{`
        form {
          border-bottom: 1px solid #ececec;
          padding-bottom: 20px;
          margin-bottom: 20px;
        }
        h1 {
          font-size: 20px;
        }</style></form>
github nearform / graphql-hooks / examples / typescript / src / App.tsx View on Github external
function AddPost({ onSuccess }: { onSuccess: () =&gt; void }) {
  const [title, setTitle] = useState('')
  const [url, setUrl] = useState('')
  const [createPost, { loading, error }] = useMutation(createPostMutation)

  async function handleSubmit(e: any) {
    e.preventDefault()
    await createPost({ variables: { title, url } })
    onSuccess &amp;&amp; onSuccess()
  }

  return (
    <form>
      <label>Title:</label>
      <input required="" value="{title}"> setTitle(e.currentTarget.value)}
      /&gt;</form>
github nearform / graphql-hooks / examples / create-react-app / src / components / CreatePost.js View on Github external
export default function CreatePost({ onSuccess }) {
  const [createPost, { loading, error }] = useMutation(createPostMutation)

  async function handleSubmit({ title, url }) {
    await createPost({ variables: { title, url } })
    onSuccess &amp;&amp; onSuccess()
  }

  return (
    
  )
}
github nearform / graphql-hooks / examples / typescript / src / App.tsx View on Github external
function Post() {
  const [id, setId] = useState('')
  const [getPosts, { error, data }] = useManualQuery(postQuery)

  async function handleSubmit(e: any) {
    e.preventDefault()
    await getPosts({ variables: { id } })
  }

  return (
    &lt;&gt;
      <h2>Search by ID</h2>
      <form>
        <label>ID:</label>
        <input required="" value="{id}"> setId(e.currentTarget.value)}</form>
github datenguide / datenguide / src / pages / statistics / useSearchManager.js View on Github external
const useSearchManager = (initialMeasures, initialRegions) => {
  const [fetchSchema] = useManualQuery(SCHEMA_QUERY)
  const [fetchRegion] = useManualQuery(REGION_QUERY)

  const asyncActions = useMemo(
    () => ({
      syncUrl: () => async (dispatch, getState) => {
        Router.push({
          pathname: '/statistics',
          query: stateToQueryArgs(getState())
        })
      },
      loadMeasure: id => async dispatch => {
        const [statisticId, measureId] = id.split(':')
        dispatch(actions.setLoading())
        const schema = await fetchSchema({
          variables: {
            measures: [{ statisticId, measureId }]
github datenguide / datenguide / src / pages / statistics / useSearchManager.js View on Github external
const useSearchManager = (initialMeasures, initialRegions) => {
  const [fetchSchema] = useManualQuery(SCHEMA_QUERY)
  const [fetchRegion] = useManualQuery(REGION_QUERY)

  const asyncActions = useMemo(
    () => ({
      syncUrl: () => async (dispatch, getState) => {
        Router.push({
          pathname: '/statistics',
          query: stateToQueryArgs(getState())
        })
      },
      loadMeasure: id => async dispatch => {
        const [statisticId, measureId] = id.split(':')
        dispatch(actions.setLoading())
        const schema = await fetchSchema({
          variables: {
            measures: [{ statisticId, measureId }]
          }

graphql-hooks

Graphql Hooks

Apache-2.0
Latest version published 5 months ago

Package Health Score

79 / 100
Full package analysis