npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nuxt3/apollo-module

v0.1.1

Published

Nuxt3 module for Apollo client

Downloads

744

Readme

@nuxt3/apollo-module

Apollo module for nuxt3

Demo

nuxt3-apollo-starter

Installation

npm i -D @nuxt3/apollo-module

Configuration

// nuxt.config.js
import '@nuxt3/apollo-module' // import to remove config warning, not necessary
export default {
  buildModules: [
    '@nuxt3/apollo-module'
  ],
  apollo: {
    clientConfigs: {
      default: {
        // see https://www.apollographql.com/docs/react/api/core/ApolloClient/#ApolloClient.constructor
      },
      client1: {
        // another client
      },
      client2: {
        // authentication type
        authenticationType: 'Bearer', // default 'Bearer'
      }
    },
    // Cookie parameters used to store authentication token
    cookieAttributes: {
      /**
        * Define when the cookie will be removed. Value can be a Number
        * which will be interpreted as days from time of creation or a
        * Date instance. If omitted, the cookie becomes a session cookie.
        */
      expires: 7,

      /**
        * Define the path where the cookie is available. Defaults to '/'
        */
      path: '/',

      /**
        * Define the domain where the cookie is available. Defaults to
        * the domain of the page where the cookie was created.
        */
      domain: 'example.com',

      /**
        * A Boolean indicating if the cookie transmission requires a
        * secure protocol (https). Defaults to false.
        */
      secure: false,
    },
  }
}

Usage

Query code(You can use@nuxt3/graphql-codegen-module to generate code)

import gql from 'graphql-tag'
import * as VueApolloComposable from '@vue/apollo-composable'

export const HelloDocument = gql`
  query Hello {
    world
  }

`

export function useHelloQuery() {
  return VueApolloComposable.useQuery<any, any>(HelloDocument, {}, {
    // prefetch: false, // prefetch: false will fetch on client
  })
}

Fetch in setup

<script setup lang="ts">
import { useHelloQuery } from '@/api'

// default client
const { result, loading } = await useHelloQuery() 
// result: { "world": "Hello world!" }

// use client by id
const { result, loading } = await useHelloQuery({
  clientId: 'client1'
}) 
// result: { "world": "Hello world!" }

// client only 
const { result, loading } = await useHelloQuery({
  prefetch: false
}) 
// result: { "world": "Hello world!" } (check 'result && result.world' in template is necessary)
</script>

Authentication You have following methods for authentication available:

 // set your graphql-token
 $apolloHelpers.onLogin(token /* if not default you can pass in clientId as second argument, you can set custom cookies attributes object as the third argument, and you can skip reset store as the fourth argument */)
 // unset your graphql-token
 $apolloHelpers.onLogout(/* if not default you can pass in clientId as first argument, and you can skip reset store as the second argument */)
 // get your current token (we persist token in a cookie)
 $apolloHelpers.getToken(/* you can provide clientId */)

User login

import { useLoginMutation } from '@/generated/operations' // generated by @nuxt3/graphql-codegen-module
const { mutate: login, onDone } = useLoginMutation({
})
const { $apolloHelpers } = useNuxtApp()
onDone((res) => {
  const token = res.data.login.token // based on your resolver
  $apolloHelpers.onLogin(token)
})

User logout

// ~/components/my-component.js

const { $apolloHelpers } = useNuxtApp()
const logout = () => {
  $apolloHelpers.onLogout()
}

Dev

pnpm i
pnpm run build

License

MIT License © 2021-PRESENT Phil xu