UNPKG

2.81 kBSource Map (JSON)View Raw
1{"version":3,"file":"bundle.umd.js","sources":["../src/schemaLink.ts"],"sourcesContent":["import { ApolloLink, Operation, FetchResult, Observable } from 'apollo-link';\nimport { execute, 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":["Observable","execute","ApolloLink"],"mappings":";;;;;;;;;;;;;;;;AAAA;QA0BgC,8BAAU;QAKxC,oBAAY,EAAkD;gBAAhD,kBAAM,EAAE,wBAAS,EAAE,oBAAO;YAAxC,YACE,iBAAO,SAKR;YAHC,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,KAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC3B,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;;SACxB;QAEM,4BAAO,GAAd,UAAe,SAAoB;YAAnC,iBA0BC;YAzBC,OAAO,IAAIA,qBAAU,CAAc,UAAA,QAAQ;gBACzC,OAAO,CAAC,OAAO,CACbC,eAAO,CACL,KAAI,CAAC,MAAM,EACX,SAAS,CAAC,KAAK,EACf,KAAI,CAAC,SAAS,EACd,OAAO,KAAI,CAAC,OAAO,KAAK,UAAU;sBAC9B,KAAI,CAAC,OAAO,CAAC,SAAS,CAAC;sBACvB,KAAI,CAAC,OAAO,EAChB,SAAS,CAAC,SAAS,EACnB,SAAS,CAAC,aAAa,CACxB,CACF;qBACE,IAAI,CAAC,UAAA,IAAI;oBACR,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;wBACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBACpB,QAAQ,CAAC,QAAQ,EAAE,CAAC;qBACrB;iBACF,CAAC;qBACD,KAAK,CAAC,UAAA,KAAK;oBACV,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;wBACpB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;qBACvB;iBACF,CAAC,CAAC;aACN,CAAC,CAAC;SACJ;QACH,iBAAC;IAAD,CAAC,CAxC+BC,qBAAU;;;;;;;;;;;;"}
\No newline at end of file