Coder Social home page Coder Social logo

nuxt-urql's People

Contributors

dependabot[bot] avatar gbicou avatar github-actions[bot] avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nuxt-urql's Issues

Feature Request: Allow access to client outside of Nuxt components

I have a use case where I want to abstract out some of my GraphQL logic and put them into separate Typescript files. In these files, I don't have access to setup or any of the Vue's lifecycle hook. If possible, I want a way to access the client that was created in the nuxt.config.ts file and use it outside of the Nuxt components.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • chore(deps): update dependency prettier to v3.1.1
  • chore(deps): update dependency semantic-release to v22.0.12
  • chore(deps): update dependency ts-node to v10.9.2
  • chore(deps): update dependency typescript to v5.3.3
  • chore(deps): update dependency vue to v3.3.11
  • fix(deps): update dependency @urql/core to v4.2.1
  • fix(deps): update nuxtjs monorepo to v3.8.2 (@nuxt/kit, @nuxt/schema, nuxt)
  • chore(deps): update dependency @types/node to v20.10.4
  • chore(deps): update dependency eslint to v8.55.0
  • chore(deps): update dependency eslint-config-prettier to v9.1.0
  • fix(deps): update dependency @urql/exchange-graphcache to v6.4.0

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • pnpm/action-setup v2
  • actions/setup-node v4
  • actions/checkout v4
  • pnpm/action-setup v2
  • actions/setup-node v4
  • github/codeql-action v2
  • actions/checkout v4
  • pnpm/action-setup v2
  • actions/setup-node v4
npm
docs/package.json
  • @nuxt-themes/docus ^1.15.0
  • nuxt ^3.8.1
  • vue ^3.3.8
  • vue-router ^4.2.5
package.json
  • @nuxt/kit ^3.8.1
  • @urql/core ^4.2.0
  • @urql/vue ^1.1.2
  • @bicou/countries-server-schema ^1.4.0
  • @bicou/semantic-release ^1.0.1
  • @graphql-eslint/eslint-plugin ^3.20.1
  • @nuxt/eslint-config ^0.2.0
  • @nuxt/module-builder ^0.5.4
  • @nuxt/schema ^3.8.1
  • @nuxt/test-utils ^3.8.1
  • @types/node ^20.9.2
  • @urql/exchange-execute ^2.2.2
  • defu ^6.1.3
  • eslint ^8.54.0
  • eslint-config-prettier ^9.0.0
  • eslint-plugin-jsdoc ^46.9.0
  • eslint-plugin-prettier ^5.0.1
  • graphql ^16.8.1
  • nuxt ^3.8.1
  • prettier ^3.1.0
  • semantic-release ^22.0.8
  • vitest ^0.34.6
  • defu ^6.1.2
  • graphql ^16.6.0
  • vue ^3.2.47
  • pnpm 8.12.0
playground/package.json
  • @urql/exchange-graphcache ^6.3.3
  • graphql ^16.8.1
  • @graphql-codegen/cli ^5.0.0
  • @graphql-codegen/near-operation-file-preset ^3.0.0
  • @graphql-codegen/schema-ast ^4.0.0
  • @graphql-codegen/typed-document-node ^5.0.1
  • @graphql-codegen/typescript ^4.0.1
  • @graphql-codegen/typescript-operations ^4.0.1
  • @graphql-codegen/typescript-urql ^4.0.0
  • @graphql-codegen/typescript-urql-graphcache ^3.0.0
  • @graphql-codegen/urql-introspection ^3.0.0
  • @graphql-typed-document-node/core ^3.2.0
  • @picocss/pico ^1.5.10
  • @types/node ^20.9.2
  • sass ^1.69.5
  • nuxt ^3.8.1
  • ts-node ^10.9.1
  • typescript ^5.3.2
  • vue ^3.3.8
  • vue-router ^4.2.5
nvm
.nvmrc
  • node 20.10.0

  • Check this box to trigger a request for Renovate to run again on this repository

Using the client directly?

How can I access the client directly? I want to do something like this:

client
  .query('{ test }', {
    /* vars */
  })
  .toPromise()
  .then(result => {
    console.log(result); // OperationResult
  });

In regular Urql, I would create a client, then export the client to be used outside of Vue components. How can I do this using Nuxt Urql? From my understanding is that Nuxt Urql already creates the client in the Nuxt config file, but is there a way to access that client somehow without defining a new one?

Question: invalidating cache in subscription handler?

Hi I have sucessfully setup urql in nuxt3 with a customized urql.config.ts like so:

import { fetchExchange, subscriptionExchange } from '@urql/core'
import { cacheExchange } from '@urql/exchange-graphcache'
import { defineUrqlClient } from '#urql/client'
import { createClient as createWSClient } from 'graphql-ws'

export default defineUrqlClient((ssrExchange) => {
  const setUpServer = () => {
    return [ssrExchange, fetchExchange]
  }

  const setUpClient = () => {
    const wsClient = createWSClient({
      url: `wss://${location.hostname}/api/graphql`
    })

    return [
      cacheExchange(),
      ssrExchange,
      fetchExchange,
      subscriptionExchange({
        forwardSubscription(request) {
          const input = { ...request, query: request.query || '' }
          return {
            subscribe(sink) {
              const unsubscribe = wsClient.subscribe(input, sink)
              return { unsubscribe }
            }
          }
        }
      })
    ]
  }

  const exchanges = process.server ? setUpServer() : setUpClient()
  const headers = useRequestHeaders(['cookie', 'authorization'])

  return {
    exchanges,
    fetchOptions: () => ({ headers })
  }
})

subscriptions ar working fine and I am change local state of users = ref([]) onDeleteAccount like so:

  await useSubscription(
    {
      query: gql`
        subscription onDeleteAccount {
          user: accountDeleted {
            id
          }
        }
      `
    },
    (_, { user }) => {
      users.value = users.value.filter((u) => u.id !== user.id)
    }
  )

now the record still exists in cache and reappears on client side navigation. So I added a handler directly in cacheExchange() like:

const cache = cacheExchange({
  updates: {
    Subscription: {
      accountDeleted: (result, args, cache, info) => {
        const { accountDeleted } = result;
        if (accountDeleted) {
          cache.invalidate({ __typename: 'Account', id: accountDeleted.id });
        }
      }
    }
  }
});

which perfectly removes that cache entry but now user in the local subscription handler is undefined.

Any hints or thoughts on that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.