Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nuxt-backend-helper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王曜嵚 Wang Yaoqin
nuxt-backend-helper
Commits
132bcf2b
Commit
132bcf2b
authored
Jul 19, 2024
by
王曜嵚 Wang Yaoqin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apollo: demo
parent
e8dd0641
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
13 deletions
+24
-13
ProjectV2.vue
components/ProjectV2.vue
+13
-1
apollo.server.ts
server/plugins/apollo.server.ts
+11
-12
No files found.
components/ProjectV2.vue
View file @
132bcf2b
...
...
@@ -144,7 +144,19 @@ async function handleInstall() {
execute
()
}
async
function
handleTest
()
{
await
$fetch
(
'/graphql'
)
await
$fetch
(
'/graphql'
,
{
method
:
'post'
,
body
:
{
query
:
`{
v2(username: "wyq"){
username,
tenants {
id
}
}
}`
,
}
})
}
function
getTip
(
status
:
string
)
{
...
...
server/plugins/apollo.server.ts
View file @
132bcf2b
import
type
{
NitroApp
}
from
"nitropack"
;
import
{
ApolloServer
,
HeaderMap
}
from
'@apollo/server'
import
{
ApolloServer
,
ContextFunction
,
HeaderMap
}
from
'@apollo/server'
import
{
startStandaloneServer
}
from
"@apollo/server/standalone"
;
import
Resolvers
from
'../../public/apollo/resolvers/query'
import
fs
from
'fs'
...
...
@@ -23,13 +23,14 @@ export default defineNitroPlugin((nitroApp: NitroApp) => {
`
const
server
=
new
ApolloServer
({
typeDefs
,
resolvers
resolvers
,
csrfPrevention
:
false
})
startStandaloneServer
(
server
).
then
(()
=>
{
console
.
log
(
'apollo started'
)
})
nitroApp
.
router
.
use
(
'/graphql'
,
defineEventHandler
({
handler
(
event
)
{
async
handler
(
event
)
{
console
.
log
(
'in graphql'
)
const
headers
=
new
HeaderMap
();
for
(
const
[
key
,
value
]
of
Object
.
entries
(
event
.
headers
))
{
...
...
@@ -37,23 +38,21 @@ export default defineNitroPlugin((nitroApp: NitroApp) => {
headers
.
set
(
key
,
Array
.
isArray
(
value
)
?
value
.
join
(
', '
)
:
value
);
}
}
const
body
=
await
readBody
(
event
)
return
server
.
executeHTTPGraphQLRequest
({
httpGraphQLRequest
:
{
method
:
'get'
,
method
:
event
.
method
.
toUpperCase
()
,
headers
,
search
:
`query{
user
}`
,
body
:
{
username
:
'wyq'
}
search
:
''
,
body
},
context
:
()
=>
{
return
Promise
.
resolve
({})
}
}).
then
((
value
)
=>
{
console
.
log
(
'success'
,
value
)
return
value
setResponseHeader
(
event
,
'Content-Type'
,
'application/json'
)
if
(
value
.
body
.
kind
===
'complete'
)
return
value
.
body
.
string
return
value
.
body
}).
catch
(
err
=>
{
console
.
log
(
'err'
,
err
)
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment