Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix graphql token is async #86

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/graphql/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @baseapp-frontend/graphql

## 1.0.4

### Patch Changes

- 4ee7df9: fix graphql token is async

## 1.0.3

### Patch Changes
Expand Down
9 changes: 4 additions & 5 deletions packages/graphql/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import { createClient } from 'graphql-ws'
import WebSocket from 'isomorphic-ws'
import Cookies from 'js-cookie'
import {
CacheConfig,
Environment,
Expand All @@ -30,12 +29,12 @@
}
}

const getFetchOptions = (
const getFetchOptions = async (
request: RequestParameters,
variables: Variables,
uploadables?: UploadableMap | null,
) => {
const authToken = getToken()
const authToken = await getToken()
const requestVariables: RequestVariables = {
method: 'POST',
headers: {
Expand Down Expand Up @@ -75,7 +74,7 @@
cacheConfig?: CacheConfig,
uploadables?: UploadableMap | null,
): Promise<GraphQLResponse> {
const fetchOptions = getFetchOptions(request, variables, uploadables)
const fetchOptions = await getFetchOptions(request, variables, uploadables)

const response = await fetch(process.env.NEXT_PUBLIC_RELAY_ENDPOINT as string, fetchOptions)

Expand All @@ -98,7 +97,7 @@
const wsClient = createClient({
url: process.env.NEXT_PUBLIC_WS_RELAY_ENDPOINT as string,
connectionParams: async () => {
const Authorization = Cookies.get('Authorization')
const Authorization = await getToken()
if (!Authorization) return {}
return { Authorization }
},
Expand Down Expand Up @@ -180,7 +179,7 @@
}

export function useEnvironment() {
const env = useMemo(() => initEnvironment(), [relayEnvironment])

Check warning on line 182 in packages/graphql/config/environment.ts

View workflow job for this annotation

GitHub Actions / Lint

React Hook useMemo has an unnecessary dependency: 'relayEnvironment'. Either exclude it or remove the dependency array. Outer scope values like 'relayEnvironment' aren't valid dependencies because mutating them doesn't re-render the component
return env
}

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@baseapp-frontend/graphql",
"description": "GraphQL configurations and utilities",
"version": "1.0.3",
"version": "1.0.4",
"main": "./dist/index.ts",
"module": "./dist/index.mjs",
"scripts": {
Expand Down
Loading