@freshsqueezed/mammothgql
Advanced tools
Comparing version
@@ -0,1 +1,8 @@ | ||
## [1.0.11](https://github.com/freshsqueezed/mammothgql/compare/v1.0.10...v1.0.11) (2025-01-05) | ||
### Bug Fixes | ||
* **graphiql:** update graphiql to use cookies ([b94bb44](https://github.com/freshsqueezed/mammothgql/commit/b94bb447dbf98013083b92ff05c912d4fe83af11)) | ||
## [1.0.10](https://github.com/freshsqueezed/mammothgql/compare/v1.0.9...v1.0.10) (2024-12-18) | ||
@@ -2,0 +9,0 @@ |
@@ -14,4 +14,4 @@ import { NextFunction, Request, Response } from 'express'; | ||
export declare function mammothGraphql<TContext>(options: MammothOptions<TContext>): (req: Request, res: Response, next: NextFunction) => Promise<void>; | ||
export declare function graphiqlHtml(req: Request, res: Response): void; | ||
export declare function graphiqlHtml(req: Request, res: Response, cookies: string): void; | ||
export {}; | ||
//# sourceMappingURL=mammoth.d.ts.map |
@@ -16,5 +16,6 @@ "use strict"; | ||
const { query, variables, operationName } = req.body; | ||
const cookies = req.headers.cookie || ''; | ||
if (!query) { | ||
if (showGraphiQL && req.method === 'GET') { | ||
graphiqlHtml(req, res); | ||
graphiqlHtml(req, res, cookies); | ||
return; | ||
@@ -100,3 +101,3 @@ } | ||
}); | ||
function graphiqlHtml(req, res) { | ||
function graphiqlHtml(req, res, cookies) { | ||
const protocol = req.protocol; | ||
@@ -167,2 +168,13 @@ const host = req.get('host'); | ||
}), | ||
fetch: (url, options) => { | ||
options = { | ||
...options, | ||
credentials: 'same-origin', // Ensure cookies are included for same-origin requests | ||
headers: { | ||
...options.headers, | ||
'Cookie': '${cookies}', // Send cookies to the server with the request | ||
}, | ||
}; | ||
return fetch(url, options); | ||
}, | ||
}); | ||
@@ -169,0 +181,0 @@ const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin(); |
@@ -6,3 +6,3 @@ { | ||
"types": "lib/index.d.ts", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"author": "Matt Gordon <matt@lemonade.tech>", | ||
@@ -9,0 +9,0 @@ "license": "MIT", |
@@ -21,5 +21,5 @@ [](https://github.com/freshsqueezed/mammothgql/actions/workflows/release-package.yml) | ||
import express, { json } from 'express'; | ||
import cors from 'cors'; | ||
import mammoth from '@freshsqueezed/mammothgql'; | ||
import { makeExecutableSchema } from '@graphql-tools/schema'; | ||
import cors, { CorsRequest } from 'cors'; | ||
import { mammothGraphql } from '@freshsqueezed/mammothgql'; | ||
import schema from './graphql'; | ||
import { ServerContext } from './types'; | ||
@@ -42,8 +42,10 @@ | ||
app.use(cors()); | ||
app.use(cors<CorsRequest>()); | ||
app.use(json()); | ||
app.use( | ||
'/graphql', | ||
mammoth<ServerContext>({ | ||
mammothGraphql<ServerContext>({ | ||
schema, | ||
graphiql: true, | ||
context: ({ req }) => ({ | ||
@@ -79,2 +81,2 @@ user: req.user || null, | ||
Open the URL it prints in a web browser. It will show GraphiQL, a web-based tool for running GraphQL operations. Try running the operation `query { hello }`! | ||
Open the URL it prints in a web browser. It will show GraphiQL, a web-based tool for running GraphQL operations. Try running the operation `query { hello(s: "world!") }`! |
@@ -52,5 +52,7 @@ import { NextFunction, Request, Response } from 'express'; | ||
const cookies = req.headers.cookie || ''; | ||
if (!query) { | ||
if (showGraphiQL && req.method === 'GET') { | ||
graphiqlHtml(req, res); | ||
graphiqlHtml(req, res, cookies); | ||
return; | ||
@@ -166,3 +168,3 @@ } | ||
export function graphiqlHtml(req: Request, res: Response) { | ||
export function graphiqlHtml(req: Request, res: Response, cookies: string) { | ||
const protocol = req.protocol; | ||
@@ -234,2 +236,13 @@ const host = req.get('host'); | ||
}), | ||
fetch: (url, options) => { | ||
options = { | ||
...options, | ||
credentials: 'same-origin', // Ensure cookies are included for same-origin requests | ||
headers: { | ||
...options.headers, | ||
'Cookie': '${cookies}', // Send cookies to the server with the request | ||
}, | ||
}; | ||
return fetch(url, options); | ||
}, | ||
}); | ||
@@ -236,0 +249,0 @@ const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39144
3.68%694
3.58%80
2.56%