@freshsqueezed/mammothgql
Advanced tools
Comparing version 1.0.15 to 1.0.16
import request from 'supertest'; | ||
import express, { json } from 'express'; | ||
import { makeExecutableSchema } from '@graphql-tools/schema'; | ||
import { mammothGraphql } from '../src'; | ||
import { MammothBaseContext, mammothGraphql } from '../src'; | ||
@@ -25,8 +25,13 @@ const testSchema = makeExecutableSchema({ | ||
app.use(json()); | ||
interface ServerContext extends MammothBaseContext { | ||
user?: any; | ||
} | ||
app.use( | ||
'/graphql', | ||
mammothGraphql({ | ||
mammothGraphql<ServerContext>({ | ||
schema: testSchema, | ||
graphiql: true, | ||
context: ({ req, res }) => ({ req, res }), | ||
context: () => ({}), | ||
}), | ||
@@ -33,0 +38,0 @@ ); |
@@ -0,1 +1,8 @@ | ||
## [1.0.16](https://github.com/freshsqueezed/mammothgql/compare/v1.0.15...v1.0.16) (2025-01-07) | ||
### Bug Fixes | ||
* **pipeline:** fix pipeline context issues ([0ec8b96](https://github.com/freshsqueezed/mammothgql/commit/0ec8b968df6cc75e4be432f32eb407872787f342)) | ||
## [1.0.15](https://github.com/freshsqueezed/mammothgql/compare/v1.0.14...v1.0.15) (2025-01-07) | ||
@@ -2,0 +9,0 @@ |
import { Request, Response } from 'express'; | ||
import type { GraphQLSchema, ValidationRule } from 'graphql'; | ||
interface MammothBaseContext { | ||
export interface MammothBaseContext { | ||
req: Request; | ||
@@ -9,3 +9,3 @@ res: Response; | ||
schema: GraphQLSchema; | ||
context?: (args: MammothBaseContext) => Partial<ServerContext>; | ||
context: (args: MammothBaseContext) => Partial<ServerContext>; | ||
pretty?: boolean; | ||
@@ -15,5 +15,5 @@ graphiql?: boolean; | ||
} | ||
export declare function mammothGraphql<ServerContext extends MammothBaseContext>(options: MammothOptions<ServerContext>): (req: Request, res: Response) => Promise<void>; | ||
export declare function mammothGraphql<ServerContext extends MammothBaseContext = MammothBaseContext>(options: MammothOptions<ServerContext>): (req: Request, res: Response) => Promise<void>; | ||
export declare function graphiqlHtml(req: Request, res: Response, cookies: string): void; | ||
export {}; | ||
//# sourceMappingURL=mammoth.d.ts.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
function mammothGraphql(options) { | ||
const { schema, pretty = false, graphiql: showGraphiQL = false, validationRules = [], context = () => ({}), } = options; | ||
const { schema, pretty = false, graphiql: showGraphiQL = false, validationRules = [], } = options; | ||
return async (req, res) => { | ||
@@ -72,3 +72,3 @@ if (req.method !== 'GET' && req.method !== 'POST') { | ||
res, | ||
...context({ req, res }), | ||
...options.context({ req, res }), | ||
}; | ||
@@ -75,0 +75,0 @@ const result = await (0, graphql_1.execute)({ |
@@ -6,3 +6,3 @@ { | ||
"types": "lib/index.d.ts", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"author": "Matt Gordon <matt@lemonade.tech>", | ||
@@ -9,0 +9,0 @@ "license": "MIT", |
@@ -20,3 +20,3 @@ import { Request, Response } from 'express'; | ||
interface MammothBaseContext { | ||
export interface MammothBaseContext { | ||
req: Request; | ||
@@ -26,6 +26,5 @@ res: Response; | ||
// MammothOptions is now generic, expecting a ServerContext that extends MammothBaseContext | ||
interface MammothOptions<ServerContext extends MammothBaseContext> { | ||
schema: GraphQLSchema; | ||
context?: (args: MammothBaseContext) => Partial<ServerContext>; | ||
context: (args: MammothBaseContext) => Partial<ServerContext>; | ||
pretty?: boolean; | ||
@@ -36,5 +35,5 @@ graphiql?: boolean; | ||
export function mammothGraphql<ServerContext extends MammothBaseContext>( | ||
options: MammothOptions<ServerContext>, | ||
) { | ||
export function mammothGraphql< | ||
ServerContext extends MammothBaseContext = MammothBaseContext, | ||
>(options: MammothOptions<ServerContext>) { | ||
const { | ||
@@ -45,3 +44,2 @@ schema, | ||
validationRules = [], | ||
context = () => ({}), | ||
} = options; | ||
@@ -127,6 +125,6 @@ | ||
try { | ||
const contextValue: ServerContext = { | ||
const contextValue = { | ||
req, | ||
res, | ||
...context({ req, res }), | ||
...options.context({ req, res }), | ||
} as ServerContext; | ||
@@ -133,0 +131,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
40820
712