Skip to content

Commit

Permalink
fix: opt in to import.meta.* properties
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 25, 2024
1 parent ec3c6bd commit 6cf099c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function useGqlHeaders (...args: any[]) {
if (respectDefaults && !Object.keys(headers).length) {
const defaultHeaders = (useRuntimeConfig()?.public?.['graphql-client'] as GqlConfig)?.clients?.[client || 'default']?.headers

const serverHeaders = (process.server && (typeof defaultHeaders?.serverOnly === 'object' && defaultHeaders?.serverOnly)) || undefined
const serverHeaders = (import.meta.server && (typeof defaultHeaders?.serverOnly === 'object' && defaultHeaders?.serverOnly)) || undefined

Check warning on line 84 in src/runtime/composables/index.ts

View check run for this annotation

Codecov / codecov/patch

src/runtime/composables/index.ts#L84

Added line #L84 was not covered by tests
if (defaultHeaders?.serverOnly) { delete defaultHeaders.serverOnly }

headers = { ...(defaultHeaders as Record<string, string>), ...serverHeaders }
Expand Down Expand Up @@ -150,7 +150,7 @@ export function useGqlToken (...args: any[]) {
cookie.value = token
}

if (process.client && tokenStorage.mode === 'localStorage') {
if (import.meta.client && tokenStorage.mode === 'localStorage') {

Check warning on line 153 in src/runtime/composables/index.ts

View check run for this annotation

Codecov / codecov/patch

src/runtime/composables/index.ts#L153

Added line #L153 was not covered by tests
if (token !== null) {
localStorage.setItem(tokenStorage.name!, token)
} else {
Expand Down Expand Up @@ -268,7 +268,7 @@ export function useGql () {
* */
export const useGqlError = (onError: OnGqlError) => {
// proactive measure to prevent context reliant calls
useGqlState().value.onError = process.client
useGqlState().value.onError = import.meta.client

Check warning on line 271 in src/runtime/composables/index.ts

View check run for this annotation

Codecov / codecov/patch

src/runtime/composables/index.ts#L271

Added line #L271 was not covered by tests
? onError
: (process.env.NODE_ENV !== 'production' && (e => console.error('[nuxt-graphql-client] [GraphQL error]', e))) || undefined

Expand Down
10 changes: 5 additions & 5 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export default defineNuxtPlugin((nuxtApp) => {
const proxyHeaders = Object.values(clients || {}).flatMap(v => v?.proxyHeaders).filter((v, i, a) => Boolean(v) && a.indexOf(v) === i) as string[]
if (!proxyHeaders.includes('cookie')) { proxyHeaders.push('cookie') }

const requestHeaders = ((process.server && useRequestHeaders(proxyHeaders)) as Record<string, string>) || undefined
const requestHeaders = ((import.meta.server && useRequestHeaders(proxyHeaders)) as Record<string, string>) || undefined

Check warning on line 21 in src/runtime/plugin.ts

View check run for this annotation

Codecov / codecov/patch

src/runtime/plugin.ts#L21

Added line #L21 was not covered by tests

for (const [name, v] of Object.entries(clients || {})) {
const host = (process.client && v?.clientHost) || v.host
const host = (import.meta.client && v?.clientHost) || v.host

Check warning on line 24 in src/runtime/plugin.ts

View check run for this annotation

Codecov / codecov/patch

src/runtime/plugin.ts#L24

Added line #L24 was not covered by tests

const proxyCookie = v?.proxyCookies && !!requestHeaders?.cookie

let headers = v?.headers as Record<string, string> | undefined
const serverHeaders = (process.server && (typeof headers?.serverOnly === 'object' && headers?.serverOnly)) || {}
const serverHeaders = (import.meta.server && (typeof headers?.serverOnly === 'object' && headers?.serverOnly)) || {}

Check warning on line 29 in src/runtime/plugin.ts

View check run for this annotation

Codecov / codecov/patch

src/runtime/plugin.ts#L29

Added line #L29 was not covered by tests

if (headers?.serverOnly) {
headers = { ...headers }
Expand Down Expand Up @@ -65,13 +65,13 @@ export default defineNuxtPlugin((nuxtApp) => {

if (token.value === undefined && typeof v.tokenStorage === 'object') {
if (v.tokenStorage?.mode === 'cookie') {
if (process.client) {
if (import.meta.client) {

Check warning on line 68 in src/runtime/plugin.ts

View check run for this annotation

Codecov / codecov/patch

src/runtime/plugin.ts#L68

Added line #L68 was not covered by tests
token.value = useCookie(v.tokenStorage.name!).value
} else if (requestHeaders?.cookie) {
const cookieName = `${v.tokenStorage.name}=`
token.value = requestHeaders?.cookie.split(';').find(c => c.trim().startsWith(cookieName))?.split('=')?.[1]
}
} else if (process.client && v.tokenStorage?.mode === 'localStorage') {
} else if (import.meta.client && v.tokenStorage?.mode === 'localStorage') {

Check warning on line 74 in src/runtime/plugin.ts

View check run for this annotation

Codecov / codecov/patch

src/runtime/plugin.ts#L74

Added line #L74 was not covered by tests
const storedToken = localStorage.getItem(v.tokenStorage.name!)

if (storedToken) { token.value = storedToken }
Expand Down

0 comments on commit 6cf099c

Please sign in to comment.