UNPKG

@jokio/graphql

Version:

High level, pre-configured, GraphQL Server

71 lines (54 loc) 1.93 kB
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"; import { withFilter } from "graphql-subscriptions"; 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 type SubscriptionEventFilter<ContextType> = (result, props, context: ContextType) => boolean; export type SubscriptionEventProps<ContextType> = { eventName: string filter?: SubscriptionEventFilter<ContextType> map?: (result: any) => any }; export type SubscriptionEvent<ContextType> = (props: SubscriptionEventProps<ContextType>) => { subscribe: (obj, props, context: ContextType, info: any) => any }