Switch to @nuxtjs/apollo module-style integration
This commit is contained in:
25
server/api/graphql.post.ts
Normal file
25
server/api/graphql.post.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const config = useRuntimeConfig(event);
|
||||
const body = await readBody(event);
|
||||
|
||||
const cookie = getHeader(event, 'cookie');
|
||||
const userId = getHeader(event, 'x-user-id');
|
||||
|
||||
const response = await fetch(config.backendGraphqlUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
...(cookie ? { cookie } : {}),
|
||||
...(userId ? { 'x-user-id': userId } : {}),
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
setResponseStatus(event, response.status);
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (contentType) {
|
||||
setHeader(event, 'content-type', contentType);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
});
|
||||
Reference in New Issue
Block a user