Skip to content

Commit

Permalink
feat: Add support for onLocalContext callback
Browse files Browse the repository at this point in the history
  • Loading branch information
aarne committed May 21, 2024
1 parent 017457b commit ab117d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/createMeshInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { getMesh } from "@graphql-mesh/runtime";
import { InMemoryStoreStorageAdapter, MeshStore } from "@graphql-mesh/store";
import { DefaultLogger, PubSub } from "@graphql-mesh/utils";
import { GraphQLSchema } from "graphql";
import type { YogaServerOptions } from "graphql-yoga";
import SupergraphHandler from "./SupergraphHandler.js";
import { OnRemoteRequestHeadersCallback } from "./index.js";

export interface CreateMeshInstanceOptions<T = unknown> {
supergraphSDL: string;
localSchema: GraphQLSchema;
onRemoteRequestHeaders?: OnRemoteRequestHeadersCallback<T>;
onLocalContext?: YogaServerOptions<{}, {}>["context"];
}

export async function createMeshInstance<T = unknown>(
Expand Down
4 changes: 3 additions & 1 deletion src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { FetchFn, buildHTTPExecutor } from "@graphql-tools/executor-http";
import type { Executor } from "@graphql-tools/utils";
import { readFile } from "fs/promises";
import { GraphQLResolveInfo, GraphQLSchema } from "graphql";
import { createYoga } from "graphql-yoga";
import { createYoga, type YogaServerOptions } from "graphql-yoga";
import { OnRemoteRequestHeadersCallback, SubgraphService } from "./index.js";

export interface CreateSupergraphOptions<T = unknown> {
localSchema: GraphQLSchema;
onRemoteRequestHeaders?: OnRemoteRequestHeadersCallback<T>;
onLocalContext?: YogaServerOptions<{}, {}>["context"];
}

/**
Expand Down Expand Up @@ -92,6 +93,7 @@ export function executorFactory(
const localFetch = createYoga({
schema: opts.localSchema,
batching: true,
context: opts.onLocalContext,
}).fetch;

function getFetch(subgraph: SubgraphService) {
Expand Down

0 comments on commit ab117d5

Please sign in to comment.