@graphql-hive/gateway-testing
Version:
57 lines (54 loc) • 2.87 kB
text/typescript
import { UnifiedGraphConfig, GatewayConfigSupergraph, GatewayConfigBase, GatewayRuntime } from '@graphql-hive/gateway-runtime';
import { MaybeAsyncIterable, ExecutionResult } from '@graphql-tools/utils';
import { GraphQLFieldResolver, GraphQLScalarType, GraphQLSchema } from 'graphql';
import { YogaServerOptions, YogaServerInstance } from 'graphql-yoga';
/** Thanks @apollo/subgraph for not re-exporting this! */
interface GraphQLResolverMap<TContext = {}> {
[typeName: string]: {
[fieldName: string]: GraphQLFieldResolver<any, TContext> | {
requires?: string;
resolve?: GraphQLFieldResolver<any, TContext>;
subscribe?: GraphQLFieldResolver<any, TContext>;
};
} | GraphQLScalarType | {
[enumValue: string]: string | number;
};
}
type GatewayTesterRemoteSchemaConfigYoga = Exclude<YogaServerOptions<any, any>, 'schema'> | ((schema: GraphQLSchema) => YogaServerInstance<any, any>);
interface GatewayTesterRemoteSchemaConfig {
/** The name of the remote schema / subgraph / proxied server. */
name: string;
/** The remote schema. */
schema: GraphQLSchema | {
typeDefs: string;
resolvers?: GraphQLResolverMap;
};
/** The hostname of the remote schema. URL will become `http://${host}${yoga.graphqlEndpoint}`. */
host?: string;
/** An optional GraphQL Yoga server instance that runs the {@link schema built schema}. */
yoga?: GatewayTesterRemoteSchemaConfigYoga;
}
type GatewayTesterConfig<TContext extends Record<string, any> = Record<string, any>> = ({
supergraph: UnifiedGraphConfig;
} & Omit<GatewayConfigSupergraph<TContext>, 'supergraph'>) | ({
subgraphs: GatewayTesterRemoteSchemaConfig[] | (() => GatewayTesterRemoteSchemaConfig[]);
} & Omit<GatewayConfigSupergraph<TContext>, 'supergraph'>) | ({
proxy: GatewayTesterRemoteSchemaConfig & {
/** Additional headers to be sent to the remote schema on every request. */
headers?: Record<string, string>;
};
} & GatewayConfigBase<TContext>);
interface GatewayTester<TContext extends Record<string, any> = Record<string, any>> extends AsyncDisposable {
runtime: GatewayRuntime<TContext>;
fetch: typeof fetch;
execute(args: {
query: string;
variables?: Record<string, unknown>;
operationName?: string;
extensions?: Record<string, unknown>;
headers?: Record<string, string>;
}): Promise<MaybeAsyncIterable<ExecutionResult<any>>>;
dispose(): Promise<void>;
}
declare function createGatewayTester<TContext extends Record<string, any> = Record<string, any>>(config: GatewayTesterConfig<TContext>): GatewayTester<TContext>;
export { type GatewayTester, type GatewayTesterConfig, type GatewayTesterRemoteSchemaConfig, type GatewayTesterRemoteSchemaConfigYoga, type GraphQLResolverMap, createGatewayTester };