@@ -6,8 +6,10 @@ import {
66 Operation ,
77} from "@apollo/client" ;
88import { Request , Response } from "express" ;
9- import { execute , getOperationAST } from "graphql" ;
10- import { HttpRequestHandler } from "postgraphile" ;
9+ import { execute , hookArgs , isAsyncIterable } from "grafast" ;
10+ import type { } from "grafserv/express/v4" ;
11+ import { getOperationAST } from "graphql" ;
12+ import type { PostGraphileInstance } from "postgraphile" ;
1113
1214export interface GraphileApolloLinkInterface {
1315 /** The request object. */
@@ -17,10 +19,7 @@ export interface GraphileApolloLinkInterface {
1719 res : Response ;
1820
1921 /** The instance of the express middleware returned by calling `postgraphile()` */
20- postgraphileMiddleware : HttpRequestHandler < Request , Response > ;
21-
22- /** An optional rootValue to use inside resolvers. */
23- rootValue ?: any ;
22+ pgl : PostGraphileInstance ;
2423}
2524
2625/**
@@ -36,7 +35,7 @@ export class GraphileApolloLink extends ApolloLink {
3635 operation : Operation ,
3736 _forward ?: NextLink
3837 ) : Observable < FetchResult > | null {
39- const { postgraphileMiddleware , req, res, rootValue } = this . options ;
38+ const { pgl , req, res } = this . options ;
4039 return new Observable ( ( observer ) => {
4140 ( async ( ) => {
4241 try {
@@ -53,22 +52,28 @@ export class GraphileApolloLink extends ApolloLink {
5352 }
5453 return ;
5554 }
56- const schema = await postgraphileMiddleware . getGraphQLSchema ( ) ;
57- const data =
58- await postgraphileMiddleware . withPostGraphileContextFromReqRes (
55+ const schema = await pgl . getSchema ( ) ;
56+ const args = {
57+ schema,
58+ document,
59+ variableValues,
60+ operationName,
61+ } ;
62+ await hookArgs ( args , pgl . getResolvedPreset ( ) , {
63+ node : {
5964 req,
6065 res,
61- { } ,
62- ( context ) =>
63- execute (
64- schema ,
65- document ,
66- rootValue || { } ,
67- context ,
68- variableValues ,
69- operationName
70- )
71- ) ;
66+ } ,
67+ expressv4 : {
68+ req ,
69+ res ,
70+ } ,
71+ } ) ;
72+ const data = await execute ( args ) ;
73+ if ( isAsyncIterable ( data ) ) {
74+ data . return ?. ( ) ;
75+ throw new Error ( "Iterable not supported by GraphileApolloLink" ) ;
76+ }
7277 if ( ! observer . closed ) {
7378 observer . next ( data ) ;
7479 observer . complete ( ) ;
0 commit comments