Akryum / Akryum/vue-cli-plugin-apollo

Ws request needs to refresh the token to take effect

Đang mở
#186 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
question
Ngôn ngữ chính
JavaScript
Star
477
Fork
109
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

```typescript
// server
context: ({ req, connection }) =>
connection ? { req: connection.context } : { req },
playground: true,
debug: true,
autoSchemaFile: 'schema.graphql',
installSubscriptionHandlers: true,
subscriptions: {
onConnect: (connectionParams: any) => {
return { headers: { authorization: connectionParams.authorization } };
},
},
```

```typescript
// client
import Vue from 'vue'
import VueApollo from 'vue-apollo'
import { createApolloClient } from 'vue-cli-plugin-apollo/graphql-client'
import router from '@/router'

Vue.use(VueApollo)

const httpEndpoint =
process.env.VUE_APP_GRAPHQL_HTTP || 'http://localhost:4000/graphql'

const defaultOptions = {
tokenName: 'token',
wsEndpoint: `ws://localhost:3333/graphql`,
httpEndpoint,
persisting: false,
ssr: false
}
export function createProvider(options = {}) {
const { apolloClient, wsClient } = createApolloClient({
...defaultOptions,
...options
})
apolloClient.wsClient = wsClient
const apolloProvider = new VueApollo({
defaultClient: apolloClient,
defaultOptions: {
$query: {
// fetchPolicy: 'cache-and-network'
}
},
errorHandler(error: any) {
// tslint:disable-next-line:no-console
console.log(
'%cError',
'background: red; color: white; padding: 2px 4px; border-radius: 3px; font-weight: bold;',
JSON.stringify(error)
)
if (Number(error.gqlError.message.statusCode) === 401) {
router.replace({
path: '/login',
query: {
redirect: router.currentRoute.fullPath
}
})
}
}
})
return apolloProvider
}

```

- When the first WS request `payload` is empty, I need to manually refresh to get the `authorization` parameter. What is the reason?

Token:
![image](https://user-images.githubusercontent.com/25023667/61573360-07b1cd80-aae0-11e9-965c-d283a449bb01.png)
First WS request:
![image](https://user-images.githubusercontent.com/25023667/61573363-16988000-aae0-11e9-89b3-374e28f81466.png)
Request after refresh:
![image](https://user-images.githubusercontent.com/25023667/61573372-38920280-aae0-11e9-8b49-f67471a01b82.png)

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.