Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit07052c4

Browse files
committed
fix: Vue CLI UI graphql subscription server error
Fixes#7221`subscriptions-transport-ws` is also deprecated, we need to move to`graphql-ws` one day.But better deprecatedthan broken.
1 parenta5a893e commit07052c4

File tree

3 files changed

+297
-215
lines changed

3 files changed

+297
-215
lines changed

‎packages/@vue/cli-ui/graphql-server.js

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const { ApolloServer, gql } = require('apollo-server-express')
88
const{ PubSub}=require('graphql-subscriptions')
99
constmerge=require('deepmerge')
1010

11+
const{ SubscriptionServer}=require('subscriptions-transport-ws')
12+
const{ makeExecutableSchema}=require('@graphql-tools/schema')
13+
const{ execute, subscribe}=require('graphql')
14+
1115
functiondefaultValue(provided,value){
1216
returnprovided==null ?value :provided
1317
}
@@ -27,6 +31,7 @@ module.exports = async (options, cb = null) => {
2731

2832
// Express app
2933
constapp=express()
34+
consthttpServer=http.createServer(app)
3035

3136
// Customize those files
3237
lettypeDefs=load(options.paths.typeDefs)
@@ -64,12 +69,16 @@ module.exports = async (options, cb = null) => {
6469

6570
typeDefs=processSchema(typeDefs)
6671

72+
// eslint-disable-next-line prefer-const
73+
letsubscriptionServer
74+
6775
letapolloServerOptions={
6876
typeDefs,
6977
resolvers,
7078
schemaDirectives,
7179
dataSources,
7280
tracing:true,
81+
cache:'bounded',
7382
cacheControl:true,
7483
engine:!options.integratedEngine,
7584
// Resolvers context from POST
@@ -89,23 +98,15 @@ module.exports = async (options, cb = null) => {
8998
returncontextData
9099
},
91100
// Resolvers context from WebSocket
92-
subscriptions:{
93-
path:options.subscriptionsPath,
94-
onConnect:async(connection,websocket)=>{
95-
letcontextData={}
96-
try{
97-
contextData=awaitautoCall(context,{
98-
connection,
99-
websocket
100-
})
101-
contextData=Object.assign({},contextData,{ pubsub})
102-
}catch(e){
103-
console.error(e)
104-
throwe
101+
plugins:[{
102+
asyncserverWillStart(){
103+
return{
104+
asyncdrainServer(){
105+
subscriptionServer.close()
106+
}
105107
}
106-
returncontextData
107108
}
108-
}
109+
}]
109110
}
110111

111112
// Automatic mocking
@@ -146,6 +147,36 @@ module.exports = async (options, cb = null) => {
146147

147148
// Apollo Server
148149
constserver=newApolloServer(apolloServerOptions)
150+
151+
constschema=makeExecutableSchema({
152+
typeDefs:apolloServerOptions.typeDefs,
153+
resolvers:apolloServerOptions.resolvers,
154+
schemaDirectives:apolloServerOptions.schemaDirectives
155+
})
156+
157+
subscriptionServer=SubscriptionServer.create({
158+
schema,
159+
execute,
160+
subscribe,
161+
onConnect:async(connection,websocket)=>{
162+
letcontextData={}
163+
try{
164+
contextData=awaitautoCall(context,{
165+
connection,
166+
websocket
167+
})
168+
contextData=Object.assign({},contextData,{ pubsub})
169+
}catch(e){
170+
console.error(e)
171+
throwe
172+
}
173+
returncontextData
174+
}
175+
},{
176+
server:httpServer,
177+
path:options.subscriptionsPath
178+
})
179+
149180
awaitserver.start()
150181

151182
// Express middleware
@@ -160,9 +191,7 @@ module.exports = async (options, cb = null) => {
160191
})
161192

162193
// Start server
163-
consthttpServer=http.createServer(app)
164194
httpServer.setTimeout(options.timeout)
165-
server.installSubscriptionHandlers(httpServer)
166195

167196
httpServer.listen({
168197
host:options.host||'localhost',

‎packages/@vue/cli-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"dependencies": {
3737
"@achrinza/node-ipc":"^9.2.5",
3838
"@akryum/winattr":"^3.0.0",
39+
"@graphql-tools/schema":"^8.5.0",
3940
"@vue/cli-shared-utils":"^5.0.7",
4041
"apollo-server-express":"^3.9.0",
4142
"clone":"^2.1.1",
@@ -60,6 +61,7 @@
6061
"prismjs":"^1.23.0",
6162
"rss-parser":"^3.11.0",
6263
"shortid":"^2.2.15",
64+
"subscriptions-transport-ws":"^0.11.0",
6365
"typescript":"~4.5.5"
6466
},
6567
"devDependencies": {
@@ -91,7 +93,6 @@
9193
"start-server-and-test":"^1.12.0",
9294
"stylus":"^0.55.0",
9395
"stylus-loader":"^6.1.0",
94-
"subscriptions-transport-ws":"^0.9.18",
9596
"validate-npm-package-name":"^3.0.0",
9697
"vue":"^2.6.14",
9798
"vue-apollo":"^3.0.7",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp