INNER CODE UNIT · TypeScript

useGqlState

Diizzayy/nuxt-graphql-client · src/runtime/composables/index.ts:18

const useGqlState = (): Ref<GqlState> => {
  const nuxtApp = useNuxtApp() as Partial<{ _gqlState: Ref<GqlState> }>

  if (!nuxtApp._gqlState) { throw new Error('GQL State is not available.') }

  return nuxtApp?._gqlState
}

/**
 *
 * @param {object} options Changes to be made to gqlState
 * @param {GqlClients} options.client The name of your GraphQL client.
 * @param {object} options.patch Changes to be made to the client's state.
 *
 */
// The decision was made to avert using `GraphQLClient's` `setHeader(s)` helper in favor of reactivity and more granular control.
const setGqlState = ({ client, patch }: { client?: GqlClients, patch: GqlStateOpts['options'] }) => {
  const state = useGqlState()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…