@jokio/graphql
Version:
High level, pre-configured, GraphQL Server
62 lines (61 loc) • 2.09 kB
TypeScript
/// <reference types="express" />
import { IResolvers } from "graphql-yoga/dist/src/types";
import { EngineConfig } from "apollo-engine";
import { PubSub, Options } from "graphql-yoga";
import { RestAPI } from "./api";
import { Request } from "express";
import { ConnectionContext } from "subscriptions-transport-ws";
export interface RunProps {
port?: number | string;
endpoint?: string;
localSchemas?: Module[];
remoteSchemaUrls?: string[];
apiUrls?: {
[key: string]: string;
};
engineConfig?: EngineConfig;
subscriptionEndpoint?: string;
disabledScalars?: boolean;
disableCoreModule?: boolean;
websocketConnectionParams?: {
[key: string]: string;
};
tokenName?: string;
getHttpToken?: (request: Request, tokenName: string) => string;
getWsToken?: (connection: ConnectionContext, tokenName: string) => string;
contextObject?: any;
yogaOptions?: Options;
enableAuthentication?: boolean;
getUserId?: (token: string, apis: {
[key: string]: RestAPI;
}) => Promise<string>;
}
export interface Module {
typeDefs: string;
resolvers: IResolvers;
}
export interface Resolvers<ContextType> {
[key: string]: Resolver<ContextType> | SubscriptionResolver<ContextType>;
}
export interface Resolver<ContextType> {
[key: string]: (obj, props, context: ContextType, info: any) => any;
}
export interface SubscriptionResolver<ContextType> {
[key: string]: {
subscribe: (obj, props, context: ContextType, info: any) => any;
};
}
export interface Context {
token: string;
userId: string;
pubsub: PubSub;
}
export declare type SubscriptionEventFilter<ContextType> = (result, props, context: ContextType) => boolean;
export declare type SubscriptionEventProps<ContextType> = {
eventName: string;
filter?: SubscriptionEventFilter<ContextType>;
map?: (result: any) => any;
};
export declare type SubscriptionEvent<ContextType> = (props: SubscriptionEventProps<ContextType>) => {
subscribe: (obj, props, context: ContextType, info: any) => any;
};