UNPKG

2.86 kBSource Map (JSON)View Raw
1{"version":3,"file":"bundle.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { ApolloLink, Operation, FetchResult, Observable } from 'apollo-link';\nimport { execute } from 'graphql/execution/execute';\nimport { GraphQLSchema } from 'graphql';\n\nexport namespace SchemaLink {\n export type ResolverContextFunction = (\n operation: Operation,\n ) => Record<string, any>;\n\n export interface Options {\n /**\n * The schema to generate responses from.\n */\n schema: GraphQLSchema;\n\n /**\n * The root value to use when generating responses.\n */\n rootValue?: any;\n\n /**\n * A context to provide to resolvers declared within the schema.\n */\n context?: ResolverContextFunction | Record<string, any>;\n }\n}\n\nexport class SchemaLink extends ApolloLink {\n public schema: GraphQLSchema;\n public rootValue: any;\n public context: SchemaLink.ResolverContextFunction | any;\n\n constructor({ schema, rootValue, context }: SchemaLink.Options) {\n super();\n\n this.schema = schema;\n this.rootValue = rootValue;\n this.context = context;\n }\n\n public request(operation: Operation): Observable<FetchResult> | null {\n return new Observable<FetchResult>(observer => {\n Promise.resolve(\n execute(\n this.schema,\n operation.query,\n this.rootValue,\n typeof this.context === 'function'\n ? this.context(operation)\n : this.context,\n operation.variables,\n operation.operationName,\n ),\n )\n .then(data => {\n if (!observer.closed) {\n observer.next(data);\n observer.complete();\n }\n })\n .catch(error => {\n if (!observer.closed) {\n observer.error(error);\n }\n });\n });\n }\n}\n\nexport default SchemaLink;\n"],"names":["tslib_1.__extends","Observable","execute","ApolloLink"],"mappings":";;;;;;;MA2BgCA,sCAAU;MAKxC,oBAAY,EAAkD;cAAhD,kBAAM,EAAE,wBAAS,EAAE,oBAAO;UAAxC,YACE,iBAAO,SAKR;UAHC,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;UACrB,KAAI,CAAC,SAAS,GAAG,SAAS,CAAC;UAC3B,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;;OACxB;MAEM,4BAAO,GAAd,UAAe,SAAoB;UAAnC,iBA0BC;UAzBC,OAAO,IAAIC,qBAAU,CAAc,UAAA,QAAQ;cACzC,OAAO,CAAC,OAAO,CACbC,eAAO,CACL,KAAI,CAAC,MAAM,EACX,SAAS,CAAC,KAAK,EACf,KAAI,CAAC,SAAS,EACd,OAAO,KAAI,CAAC,OAAO,KAAK,UAAU;oBAC9B,KAAI,CAAC,OAAO,CAAC,SAAS,CAAC;oBACvB,KAAI,CAAC,OAAO,EAChB,SAAS,CAAC,SAAS,EACnB,SAAS,CAAC,aAAa,CACxB,CACF;mBACE,IAAI,CAAC,UAAA,IAAI;kBACR,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;sBACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;sBACpB,QAAQ,CAAC,QAAQ,EAAE,CAAC;mBACrB;eACF,CAAC;mBACD,KAAK,CAAC,UAAA,KAAK;kBACV,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;sBACpB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;mBACvB;eACF,CAAC,CAAC;WACN,CAAC,CAAC;OACJ;MACH,iBAAC;EAAD,CAxCA,CAAgCC,qBAAU;;;;;;;;;;;;;"}
\No newline at end of file