@teambit/graphql 0.0.633 → 0.0.637
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{__preview-1643219209460.js → __preview-1643599267183.js} +0 -0
- package/dist/graphql.main.runtime.js +0 -2
- package/dist/graphql.main.runtime.js.map +1 -1
- package/dist/graphql.ui.runtime.d.ts +2 -2
- package/dist/graphql.ui.runtime.js +1 -1
- package/dist/graphql.ui.runtime.js.map +1 -1
- package/dist/render-lifecycle.d.ts +2 -2
- package/dist/render-lifecycle.js +3 -3
- package/dist/render-lifecycle.js.map +1 -1
- package/graphql.ui.runtime.tsx +2 -2
- package/package-tar/teambit-graphql-0.0.637.tgz +0 -0
- package/package.json +4 -4
- package/render-lifecycle.tsx +2 -2
- package/package-tar/teambit-graphql-0.0.633.tgz +0 -0
|
File without changes
|
|
@@ -366,10 +366,8 @@ class GraphqlMain {
|
|
|
366
366
|
const proxServer = _httpProxy().default.createProxyServer();
|
|
367
367
|
|
|
368
368
|
const subscriptionsPath = this.config.subscriptionsPath;
|
|
369
|
-
const logger = this.logger;
|
|
370
369
|
server.on('upgrade', function (req, socket, head) {
|
|
371
370
|
if (req.url === subscriptionsPath) {
|
|
372
|
-
logger.debug(`proxy from ${req.url} to ${port}`);
|
|
373
371
|
proxServer.ws(req, socket, head, {
|
|
374
372
|
target: {
|
|
375
373
|
host: 'localhost',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["graphql.main.runtime.ts"],"names":["Verb","GraphqlMain","constructor","config","moduleSlot","context","logger","graphQLServerSlot","pubSubSlot","Map","pubsub","pubSubSlots","values","length","PubSub","createServer","options","graphiql","localSchema","createRootModule","schemaSlot","remoteSchemas","schemas","schema","concat","filter","x","app","use","origin","callback","credentials","request","res","params","customFormatErrorFn","err","error","Object","assign","ERR_CODE","originalError","errors","name","HTTP_CODE","code","rootValue","server","subscriptionsPort","subscriptionsPortRange","subscriptionServerPort","getPort","port","createSubscription","proxySubscription","registerServer","register","registerPubSub","toArray","Error","listen","serverPort","subServer","info","subscriptionsPath","range","from","to","Port","websocketServer","response","writeHead","end","debug","SubscriptionServer","execute","subscribe","onConnect","onWsConnect","path","proxServer","httpProxy","createProxyServer","on","req","socket","head","url","ws","target","host","modules","buildModules","GraphQLModule","imports","schemaSlots","map","extensionId","moduleDeps","getModuleDependencies","module","typeDefs","resolvers","session","verb","headers","READ","set","extension","extensions","get","deps","getDependencies","ids","dep","id","Array","entries","depId","includes","undefined","provider","loggerFactory","createLogger","GraphqlAspect","graphqlMain","Slot","withType","MainRuntime","LoggerAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;IAGYA,I;;;WAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;GAAAA,I,oBAAAA,I;;AA0BL,MAAMC,W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,UAAI,CAACJ,GAAL,EAAU,OAAOM,SAAP;AACV,aAAOpB,MAAP;AACD,KALI,EAMJ3E,MANI,CAMI2E,MAAD,IAAY,CAAC,CAACA,MANjB,CAAP;AAOD;;AAaoB,eAARqB,QAAQ,CACnB,CAACC,aAAD,CADmB,EAEnBvH,MAFmB,EAGnB,CAACC,UAAD,EAAaG,iBAAb,EAAgCC,UAAhC,CAHmB,EAInBH,OAJmB,EAKnB;AACA,UAAMC,MAAM,GAAGoH,aAAa,CAACC,YAAd,CAA2BC,0BAAcT,EAAzC,CAAf;AACA,UAAMU,WAAW,GAAG,IAAI5H,WAAJ,CAAgBE,MAAhB,EAAwBC,UAAxB,EAAoCC,OAApC,EAA6CC,MAA7C,EAAqDC,iBAArD,EAAwEC,UAAxE,CAApB;AACA,WAAOqH,WAAP;AACD;;AA5PsB;;;gCAAZ5H,W,WAwOI,CAAC6H,gBAAKC,QAAL,EAAD,EAA0BD,gBAAKC,QAAL,EAA1B,EAA0DD,gBAAKC,QAAL,EAA1D,C;gCAxOJ9H,W,mBA0OY;AACrBmD,EAAAA,IAAI,EAAE,IADe;AAErBH,EAAAA,sBAAsB,EAAE,CAAC,IAAD,EAAO,IAAP,CAFH;AAGrBe,EAAAA,iBAAiB,EAAE;AAHE,C;gCA1OZ/D,W,aAgPM+H,kB;gCAhPN/H,W,kBAiPW,CAACgI,sBAAD,C;;AAcxBL,0BAAcM,UAAd,CAAyBjI,WAAzB","sourcesContent":["import { mergeSchemas } from 'graphql-tools';\nimport { GraphQLModule } from '@graphql-modules/core';\nimport { MainRuntime } from '@teambit/cli';\nimport { Harmony, Slot, SlotRegistry } from '@teambit/harmony';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport express, { Express } from 'express';\nimport { graphqlHTTP } from 'express-graphql';\nimport { Port } from '@teambit/toolbox.network.get-port';\nimport { execute, subscribe } from 'graphql';\nimport { PubSubEngine, PubSub } from 'graphql-subscriptions';\nimport { createServer, Server } from 'http';\nimport httpProxy from 'http-proxy';\nimport { SubscriptionServer } from 'subscriptions-transport-ws';\nimport cors from 'cors';\nimport { GraphQLServer } from './graphql-server';\nimport { createRemoteSchemas } from './create-remote-schemas';\nimport { GraphqlAspect } from './graphql.aspect';\nimport { Schema } from './schema';\n\nexport enum Verb {\n WRITE = 'write',\n READ = 'read',\n}\n\nexport type GraphQLConfig = {\n port: number;\n subscriptionsPortRange: number[];\n subscriptionsPath: string;\n};\n\nexport type GraphQLServerSlot = SlotRegistry<GraphQLServer>;\n\nexport type SchemaSlot = SlotRegistry<Schema>;\n\nexport type PubSubSlot = SlotRegistry<PubSubEngine>;\n\nexport type GraphQLServerOptions = {\n schemaSlot?: SchemaSlot;\n app?: Express;\n graphiql?: boolean;\n remoteSchemas?: GraphQLServer[];\n subscriptionsPortRange?: number[];\n onWsConnect?: Function;\n};\n\nexport class GraphqlMain {\n constructor(\n /**\n * extension config\n */\n readonly config: GraphQLConfig,\n\n /**\n * slot for registering graphql modules\n */\n private moduleSlot: SchemaSlot,\n\n /**\n * harmony context.\n */\n private context: Harmony,\n\n /**\n * logger extension.\n */\n readonly logger: Logger,\n\n private graphQLServerSlot: GraphQLServerSlot,\n\n /**\n * graphql pubsub. allows to emit events to clients.\n */\n private pubSubSlot: PubSubSlot\n ) {}\n\n get pubsub(): PubSubEngine {\n const pubSubSlots = this.pubSubSlot.values();\n if (pubSubSlots.length) return pubSubSlots[0];\n return new PubSub();\n }\n\n private modules = new Map<string, GraphQLModule>();\n\n async createServer(options: GraphQLServerOptions) {\n const { graphiql = true } = options;\n const localSchema = this.createRootModule(options.schemaSlot);\n const remoteSchemas = await createRemoteSchemas(options.remoteSchemas || this.graphQLServerSlot.values());\n const schemas = [localSchema.schema].concat(remoteSchemas).filter((x) => x);\n const schema = mergeSchemas({\n schemas,\n });\n\n // TODO: @guy please consider to refactor to express extension.\n const app = options.app || express();\n app.use(\n // @ts-ignore todo: it's not clear what's the issue.\n cors({\n origin(origin, callback) {\n callback(null, true);\n },\n credentials: true,\n })\n );\n\n app.use(\n '/graphql',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n graphqlHTTP((request, res, params) => ({\n customFormatErrorFn: (err) => {\n this.logger.error('graphql got an error during running the following query:', params);\n this.logger.error('graphql error ', err);\n return Object.assign(err, {\n // @ts-ignore\n ERR_CODE: err?.originalError?.errors?.[0].ERR_CODE || err.originalError?.constructor?.name,\n // @ts-ignore\n HTTP_CODE: err?.originalError?.errors?.[0].HTTP_CODE || err.originalError?.code,\n });\n },\n schema,\n rootValue: request,\n graphiql,\n }))\n );\n\n const server = createServer(app);\n const subscriptionsPort = options.subscriptionsPortRange || this.config.subscriptionsPortRange;\n const subscriptionServerPort = await this.getPort(subscriptionsPort);\n const { port } = await this.createSubscription(options, subscriptionServerPort);\n this.proxySubscription(server, port);\n\n return server;\n }\n\n /**\n * register a new graphql server.\n */\n registerServer(server: GraphQLServer) {\n this.graphQLServerSlot.register(server);\n return this;\n }\n\n /**\n * register a pubsub client\n */\n registerPubSub(pubsub: PubSubEngine) {\n const pubSubSlots = this.pubSubSlot.toArray();\n if (pubSubSlots.length) throw new Error('can not register more then one pubsub provider');\n this.pubSubSlot.register(pubsub);\n return this;\n }\n\n /**\n * start a graphql server.\n */\n async listen(port?: number, server?: Server, app?: Express) {\n const serverPort = port || this.config.port;\n const subServer = server || (await this.createServer({ app }));\n\n subServer.listen(serverPort, () => {\n this.logger.info(`API Server over HTTP is now running on http://localhost:${serverPort}`);\n this.logger.info(\n `API Server over web socket with subscriptions is now running on ws://localhost:${serverPort}/${this.config.subscriptionsPath}`\n );\n });\n }\n\n /**\n * register a new graphql module.\n */\n register(schema: Schema) {\n // const module = new GraphQLModule(schema);\n this.moduleSlot.register(schema);\n return this;\n }\n\n private async getPort(range: number[]) {\n const [from, to] = range;\n return Port.getPort(from, to);\n }\n\n /** create Subscription server with different port */\n\n private async createSubscription(options: GraphQLServerOptions, port: number) {\n // Create WebSocket listener server\n const websocketServer = createServer((request, response) => {\n response.writeHead(404);\n response.end();\n });\n\n // Bind it to port and start listening\n websocketServer.listen(port, () =>\n this.logger.debug(`Websocket Server is now running on http://localhost:${port}`)\n );\n\n const localSchema = this.createRootModule(options.schemaSlot);\n const remoteSchemas = await createRemoteSchemas(options.remoteSchemas || this.graphQLServerSlot.values());\n const schemas = [localSchema.schema].concat(remoteSchemas).filter((x) => x);\n const schema = mergeSchemas({\n schemas,\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const subServer = new SubscriptionServer(\n {\n execute,\n subscribe,\n schema,\n onConnect: options.onWsConnect,\n },\n {\n server: websocketServer,\n path: this.config.subscriptionsPath,\n }\n );\n return { subServer, port };\n }\n /** proxy ws Subscription server to avoid conflict with different websocket connections */\n\n private proxySubscription(server: Server, port: number) {\n const proxServer = httpProxy.createProxyServer();\n const subscriptionsPath = this.config.subscriptionsPath;\n const logger = this.logger;\n server.on('upgrade', function (req, socket, head) {\n if (req.url === subscriptionsPath) {\n logger.debug(`proxy from ${req.url} to ${port}`);\n proxServer.ws(req, socket, head, { target: { host: 'localhost', port } });\n }\n });\n }\n\n private createRootModule(schemaSlot?: SchemaSlot) {\n const modules = this.buildModules(schemaSlot);\n\n return new GraphQLModule({\n imports: modules,\n });\n }\n\n private buildModules(schemaSlot?: SchemaSlot) {\n const schemaSlots = schemaSlot ? schemaSlot.toArray() : this.moduleSlot.toArray();\n return schemaSlots.map(([extensionId, schema]) => {\n const moduleDeps = this.getModuleDependencies(extensionId);\n\n const module = new GraphQLModule({\n typeDefs: schema.typeDefs,\n resolvers: schema.resolvers,\n imports: moduleDeps,\n context: (session) => {\n return {\n ...session,\n verb: session?.headers?.['x-verb'] || Verb.READ,\n };\n },\n });\n\n this.modules.set(extensionId, module);\n\n return module;\n });\n }\n\n private getModuleDependencies(extensionId: string): GraphQLModule[] {\n const extension = this.context.extensions.get(extensionId);\n if (!extension) throw new Error(`aspect ${extensionId} was not found`);\n const deps = this.context.getDependencies(extension);\n const ids = deps.map((dep) => dep.id);\n\n // @ts-ignore check :TODO why types are breaking here.\n return Array.from(this.modules.entries())\n .map(([depId, module]) => {\n const dep = ids.includes(depId);\n if (!dep) return undefined;\n return module;\n })\n .filter((module) => !!module);\n }\n\n static slots = [Slot.withType<Schema>(), Slot.withType<GraphQLServer>(), Slot.withType<PubSubSlot>()];\n\n static defaultConfig = {\n port: 4000,\n subscriptionsPortRange: [2000, 2100],\n subscriptionsPath: '/subscriptions',\n };\n\n static runtime = MainRuntime;\n static dependencies = [LoggerAspect];\n\n static async provider(\n [loggerFactory]: [LoggerMain],\n config: GraphQLConfig,\n [moduleSlot, graphQLServerSlot, pubSubSlot]: [SchemaSlot, GraphQLServerSlot, PubSubSlot],\n context: Harmony\n ) {\n const logger = loggerFactory.createLogger(GraphqlAspect.id);\n const graphqlMain = new GraphqlMain(config, moduleSlot, context, logger, graphQLServerSlot, pubSubSlot);\n return graphqlMain;\n }\n}\n\nGraphqlAspect.addRuntime(GraphqlMain);\n"]}
|
|
1
|
+
{"version":3,"sources":["graphql.main.runtime.ts"],"names":["Verb","GraphqlMain","constructor","config","moduleSlot","context","logger","graphQLServerSlot","pubSubSlot","Map","pubsub","pubSubSlots","values","length","PubSub","createServer","options","graphiql","localSchema","createRootModule","schemaSlot","remoteSchemas","schemas","schema","concat","filter","x","app","use","origin","callback","credentials","request","res","params","customFormatErrorFn","err","error","Object","assign","ERR_CODE","originalError","errors","name","HTTP_CODE","code","rootValue","server","subscriptionsPort","subscriptionsPortRange","subscriptionServerPort","getPort","port","createSubscription","proxySubscription","registerServer","register","registerPubSub","toArray","Error","listen","serverPort","subServer","info","subscriptionsPath","range","from","to","Port","websocketServer","response","writeHead","end","debug","SubscriptionServer","execute","subscribe","onConnect","onWsConnect","path","proxServer","httpProxy","createProxyServer","on","req","socket","head","url","ws","target","host","modules","buildModules","GraphQLModule","imports","schemaSlots","map","extensionId","moduleDeps","getModuleDependencies","module","typeDefs","resolvers","session","verb","headers","READ","set","extension","extensions","get","deps","getDependencies","ids","dep","id","Array","entries","depId","includes","undefined","provider","loggerFactory","createLogger","GraphqlAspect","graphqlMain","Slot","withType","MainRuntime","LoggerAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;IAGYA,I;;;WAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;GAAAA,I,oBAAAA,I;;AA0BL,MAAMC,WAAN,CAAkB;AACvBC,EAAAA,WAAW;AACT;AACJ;AACA;AACaC,EAAAA,MAJA;AAMT;AACJ;AACA;AACYC,EAAAA,UATC;AAWT;AACJ;AACA;AACYC,EAAAA,OAdC;AAgBT;AACJ;AACA;AACaC,EAAAA,MAnBA,EAqBDC,iBArBC;AAuBT;AACJ;AACA;AACYC,EAAAA,UA1BC,EA2BT;AAAA,SAvBSL,MAuBT,GAvBSA,MAuBT;AAAA,SAlBQC,UA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AxB,EAAoCC,OAApC,EAA6CC,MAA7C,EAAqDC,iBAArD,EAAwEC,UAAxE,CAApB;AACA,WAAOqH,WAAP;AACD;;AA1PsB;;;gCAAZ5H,W,WAsOI,CAAC6H,gBAAKC,QAAL,EAAD,EAA0BD,gBAAKC,QAAL,EAA1B,EAA0DD,gBAAKC,QAAL,EAA1D,C;gCAtOJ9H,W,mBAwOY;AACrBmD,EAAAA,IAAI,EAAE,IADe;AAErBH,EAAAA,sBAAsB,EAAE,CAAC,IAAD,EAAO,IAAP,CAFH;AAGrBe,EAAAA,iBAAiB,EAAE;AAHE,C;gCAxOZ/D,W,aA8OM+H,kB;gCA9ON/H,W,kBA+OW,CAACgI,sBAAD,C;;AAcxBL,0BAAcM,UAAd,CAAyBjI,WAAzB","sourcesContent":["import { mergeSchemas } from 'graphql-tools';\nimport { GraphQLModule } from '@graphql-modules/core';\nimport { MainRuntime } from '@teambit/cli';\nimport { Harmony, Slot, SlotRegistry } from '@teambit/harmony';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport express, { Express } from 'express';\nimport { graphqlHTTP } from 'express-graphql';\nimport { Port } from '@teambit/toolbox.network.get-port';\nimport { execute, subscribe } from 'graphql';\nimport { PubSubEngine, PubSub } from 'graphql-subscriptions';\nimport { createServer, Server } from 'http';\nimport httpProxy from 'http-proxy';\nimport { SubscriptionServer } from 'subscriptions-transport-ws';\nimport cors from 'cors';\nimport { GraphQLServer } from './graphql-server';\nimport { createRemoteSchemas } from './create-remote-schemas';\nimport { GraphqlAspect } from './graphql.aspect';\nimport { Schema } from './schema';\n\nexport enum Verb {\n WRITE = 'write',\n READ = 'read',\n}\n\nexport type GraphQLConfig = {\n port: number;\n subscriptionsPortRange: number[];\n subscriptionsPath: string;\n};\n\nexport type GraphQLServerSlot = SlotRegistry<GraphQLServer>;\n\nexport type SchemaSlot = SlotRegistry<Schema>;\n\nexport type PubSubSlot = SlotRegistry<PubSubEngine>;\n\nexport type GraphQLServerOptions = {\n schemaSlot?: SchemaSlot;\n app?: Express;\n graphiql?: boolean;\n remoteSchemas?: GraphQLServer[];\n subscriptionsPortRange?: number[];\n onWsConnect?: Function;\n};\n\nexport class GraphqlMain {\n constructor(\n /**\n * extension config\n */\n readonly config: GraphQLConfig,\n\n /**\n * slot for registering graphql modules\n */\n private moduleSlot: SchemaSlot,\n\n /**\n * harmony context.\n */\n private context: Harmony,\n\n /**\n * logger extension.\n */\n readonly logger: Logger,\n\n private graphQLServerSlot: GraphQLServerSlot,\n\n /**\n * graphql pubsub. allows to emit events to clients.\n */\n private pubSubSlot: PubSubSlot\n ) {}\n\n get pubsub(): PubSubEngine {\n const pubSubSlots = this.pubSubSlot.values();\n if (pubSubSlots.length) return pubSubSlots[0];\n return new PubSub();\n }\n\n private modules = new Map<string, GraphQLModule>();\n\n async createServer(options: GraphQLServerOptions) {\n const { graphiql = true } = options;\n const localSchema = this.createRootModule(options.schemaSlot);\n const remoteSchemas = await createRemoteSchemas(options.remoteSchemas || this.graphQLServerSlot.values());\n const schemas = [localSchema.schema].concat(remoteSchemas).filter((x) => x);\n const schema = mergeSchemas({\n schemas,\n });\n\n // TODO: @guy please consider to refactor to express extension.\n const app = options.app || express();\n app.use(\n // @ts-ignore todo: it's not clear what's the issue.\n cors({\n origin(origin, callback) {\n callback(null, true);\n },\n credentials: true,\n })\n );\n\n app.use(\n '/graphql',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n graphqlHTTP((request, res, params) => ({\n customFormatErrorFn: (err) => {\n this.logger.error('graphql got an error during running the following query:', params);\n this.logger.error('graphql error ', err);\n return Object.assign(err, {\n // @ts-ignore\n ERR_CODE: err?.originalError?.errors?.[0].ERR_CODE || err.originalError?.constructor?.name,\n // @ts-ignore\n HTTP_CODE: err?.originalError?.errors?.[0].HTTP_CODE || err.originalError?.code,\n });\n },\n schema,\n rootValue: request,\n graphiql,\n }))\n );\n\n const server = createServer(app);\n const subscriptionsPort = options.subscriptionsPortRange || this.config.subscriptionsPortRange;\n const subscriptionServerPort = await this.getPort(subscriptionsPort);\n const { port } = await this.createSubscription(options, subscriptionServerPort);\n this.proxySubscription(server, port);\n\n return server;\n }\n\n /**\n * register a new graphql server.\n */\n registerServer(server: GraphQLServer) {\n this.graphQLServerSlot.register(server);\n return this;\n }\n\n /**\n * register a pubsub client\n */\n registerPubSub(pubsub: PubSubEngine) {\n const pubSubSlots = this.pubSubSlot.toArray();\n if (pubSubSlots.length) throw new Error('can not register more then one pubsub provider');\n this.pubSubSlot.register(pubsub);\n return this;\n }\n\n /**\n * start a graphql server.\n */\n async listen(port?: number, server?: Server, app?: Express) {\n const serverPort = port || this.config.port;\n const subServer = server || (await this.createServer({ app }));\n\n subServer.listen(serverPort, () => {\n this.logger.info(`API Server over HTTP is now running on http://localhost:${serverPort}`);\n this.logger.info(\n `API Server over web socket with subscriptions is now running on ws://localhost:${serverPort}/${this.config.subscriptionsPath}`\n );\n });\n }\n\n /**\n * register a new graphql module.\n */\n register(schema: Schema) {\n // const module = new GraphQLModule(schema);\n this.moduleSlot.register(schema);\n return this;\n }\n\n private async getPort(range: number[]) {\n const [from, to] = range;\n return Port.getPort(from, to);\n }\n\n /** create Subscription server with different port */\n\n private async createSubscription(options: GraphQLServerOptions, port: number) {\n // Create WebSocket listener server\n const websocketServer = createServer((request, response) => {\n response.writeHead(404);\n response.end();\n });\n\n // Bind it to port and start listening\n websocketServer.listen(port, () =>\n this.logger.debug(`Websocket Server is now running on http://localhost:${port}`)\n );\n\n const localSchema = this.createRootModule(options.schemaSlot);\n const remoteSchemas = await createRemoteSchemas(options.remoteSchemas || this.graphQLServerSlot.values());\n const schemas = [localSchema.schema].concat(remoteSchemas).filter((x) => x);\n const schema = mergeSchemas({\n schemas,\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const subServer = new SubscriptionServer(\n {\n execute,\n subscribe,\n schema,\n onConnect: options.onWsConnect,\n },\n {\n server: websocketServer,\n path: this.config.subscriptionsPath,\n }\n );\n return { subServer, port };\n }\n /** proxy ws Subscription server to avoid conflict with different websocket connections */\n\n private proxySubscription(server: Server, port: number) {\n const proxServer = httpProxy.createProxyServer();\n const subscriptionsPath = this.config.subscriptionsPath;\n server.on('upgrade', function (req, socket, head) {\n if (req.url === subscriptionsPath) {\n proxServer.ws(req, socket, head, { target: { host: 'localhost', port } });\n }\n });\n }\n\n private createRootModule(schemaSlot?: SchemaSlot) {\n const modules = this.buildModules(schemaSlot);\n\n return new GraphQLModule({\n imports: modules,\n });\n }\n\n private buildModules(schemaSlot?: SchemaSlot) {\n const schemaSlots = schemaSlot ? schemaSlot.toArray() : this.moduleSlot.toArray();\n return schemaSlots.map(([extensionId, schema]) => {\n const moduleDeps = this.getModuleDependencies(extensionId);\n\n const module = new GraphQLModule({\n typeDefs: schema.typeDefs,\n resolvers: schema.resolvers,\n imports: moduleDeps,\n context: (session) => {\n return {\n ...session,\n verb: session?.headers?.['x-verb'] || Verb.READ,\n };\n },\n });\n\n this.modules.set(extensionId, module);\n\n return module;\n });\n }\n\n private getModuleDependencies(extensionId: string): GraphQLModule[] {\n const extension = this.context.extensions.get(extensionId);\n if (!extension) throw new Error(`aspect ${extensionId} was not found`);\n const deps = this.context.getDependencies(extension);\n const ids = deps.map((dep) => dep.id);\n\n // @ts-ignore check :TODO why types are breaking here.\n return Array.from(this.modules.entries())\n .map(([depId, module]) => {\n const dep = ids.includes(depId);\n if (!dep) return undefined;\n return module;\n })\n .filter((module) => !!module);\n }\n\n static slots = [Slot.withType<Schema>(), Slot.withType<GraphQLServer>(), Slot.withType<PubSubSlot>()];\n\n static defaultConfig = {\n port: 4000,\n subscriptionsPortRange: [2000, 2100],\n subscriptionsPath: '/subscriptions',\n };\n\n static runtime = MainRuntime;\n static dependencies = [LoggerAspect];\n\n static async provider(\n [loggerFactory]: [LoggerMain],\n config: GraphQLConfig,\n [moduleSlot, graphQLServerSlot, pubSubSlot]: [SchemaSlot, GraphQLServerSlot, PubSubSlot],\n context: Harmony\n ) {\n const logger = loggerFactory.createLogger(GraphqlAspect.id);\n const graphqlMain = new GraphqlMain(config, moduleSlot, context, logger, graphQLServerSlot, pubSubSlot);\n return graphqlMain;\n }\n}\n\nGraphqlAspect.addRuntime(GraphqlMain);\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { ApolloClient } from '@apollo/client';
|
|
3
3
|
import type { NormalizedCacheObject } from '@apollo/client';
|
|
4
|
-
import {
|
|
4
|
+
import { GraphqlRenderPlugins } from './render-lifecycle';
|
|
5
5
|
/**
|
|
6
6
|
* Type of gql client.
|
|
7
7
|
* Used to abstract Apollo client, so consumers could import the type from graphql.ui, and not have to depend on @apollo/client directly
|
|
@@ -28,7 +28,7 @@ export declare class GraphqlUI {
|
|
|
28
28
|
client: GraphQLClient<any>;
|
|
29
29
|
children: ReactNode;
|
|
30
30
|
}) => JSX.Element;
|
|
31
|
-
readonly
|
|
31
|
+
readonly renderPlugins: GraphqlRenderPlugins;
|
|
32
32
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
33
33
|
static dependencies: never[];
|
|
34
34
|
static slots: never[];
|
|
@@ -139,7 +139,7 @@ class GraphqlUI {
|
|
|
139
139
|
client: client
|
|
140
140
|
}, children);
|
|
141
141
|
});
|
|
142
|
-
(0, _defineProperty2().default)(this, "
|
|
142
|
+
(0, _defineProperty2().default)(this, "renderPlugins", new (_renderLifecycle().GraphqlRenderPlugins)(this));
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
createClient(uri, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["graphql.ui.runtime.tsx"],"names":["GraphqlUI","client","children","
|
|
1
|
+
{"version":3,"sources":["graphql.ui.runtime.tsx"],"names":["GraphqlUI","client","children","GraphqlRenderPlugins","createClient","uri","state","subscriptionUri","ApolloClient","link","createLink","cache","createCache","createSsrClient","serverUrl","headers","ApolloLink","from","logError","credentials","fetch","crossFetch","ssrMode","InMemoryCache","restore","httpLink","HttpLink","subsLink","WebSocketLink","options","reconnect","undefined","hybridLink","errorLogger","provider","graphqlUI","UIRuntime","GraphqlAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAeO,MAAMA,SAAN,CAAgB;AAAA;AAAA,yDAwDP,CAAC;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,KAAD,KAA+E;AAC3F,0BAAO,+BAAC,kCAAD;AAAiB,QAAA,MAAM,EAAED;AAAzB,SAAkCC,QAAlC,CAAP;AACD,KA1DoB;AAAA,2DA4DI,KAAIC,uCAAJ,EAAyB,IAAzB,CA5DJ;AAAA;;AACrBC,EAAAA,YAAY,CAACC,GAAD,EAAc;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAA4C,EAA1D,EAA8D;AACxE,UAAMN,MAAM,GAAG,KAAIO,sBAAJ,EAAiB;AAC9BC,MAAAA,IAAI,EAAE,KAAKC,UAAL,CAAgBL,GAAhB,EAAqB;AAAEE,QAAAA;AAAF,OAArB,CADwB;AAE9BI,MAAAA,KAAK,EAAE,KAAKC,WAAL,CAAiB;AAAEN,QAAAA;AAAF,OAAjB;AAFuB,KAAjB,CAAf;AAKA,WA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,WAAW,GAAG,sBAAQf,mBAAR,CAApB;AAEA,WAAOF,qBAAWC,IAAX,CAAgB,CAACgB,WAAD,EAAcD,UAAd,CAAhB,CAAP;AACD;AAED;AACF;AACA;;;AAWuB,eAARE,QAAQ,GAAG;AACtB,UAAMC,SAAS,GAAG,IAAInC,SAAJ,EAAlB;AAEA,WAAOmC,SAAP;AACD;;AAtEoB;;;gCAAVnC,S,aA8DMoC,e;gCA9DNpC,S,kBA+DW,E;gCA/DXA,S,WAgEI,E;;AASjBqC,yBAAcC,UAAd,CAAyBtC,SAAzB","sourcesContent":["import React, { ReactNode } from 'react';\nimport { UIRuntime } from '@teambit/ui';\n\nimport { InMemoryCache, ApolloClient, ApolloLink, HttpLink, createHttpLink } from '@apollo/client';\nimport type { NormalizedCacheObject } from '@apollo/client';\nimport { WebSocketLink } from '@apollo/client/link/ws';\nimport { onError } from '@apollo/client/link/error';\n\nimport crossFetch from 'cross-fetch';\n\nimport { createSplitLink } from './create-link';\nimport { GraphQLProvider } from './graphql-provider';\nimport { GraphqlAspect } from './graphql.aspect';\nimport { GraphqlRenderPlugins } from './render-lifecycle';\nimport { logError } from './logging';\n\n/**\n * Type of gql client.\n * Used to abstract Apollo client, so consumers could import the type from graphql.ui, and not have to depend on @apollo/client directly\n * */\nexport type GraphQLClient<T> = ApolloClient<T>;\n\ntype ClientOptions = {\n /** Preset in-memory cache with state (e.g. continue state from SSR) */\n state?: NormalizedCacheObject;\n /** endpoint for websocket connections */\n subscriptionUri?: string;\n};\n\nexport class GraphqlUI {\n createClient(uri: string, { state, subscriptionUri }: ClientOptions = {}) {\n const client = new ApolloClient({\n link: this.createLink(uri, { subscriptionUri }),\n cache: this.createCache({ state }),\n });\n\n return client;\n }\n\n createSsrClient({ serverUrl, headers }: { serverUrl: string; headers: any }) {\n const link = ApolloLink.from([\n onError(logError),\n createHttpLink({\n credentials: 'include',\n uri: serverUrl,\n headers,\n fetch: crossFetch,\n }),\n ]);\n\n const client = new ApolloClient({\n ssrMode: true,\n link,\n cache: this.createCache(),\n });\n\n return client;\n }\n\n private createCache({ state }: { state?: NormalizedCacheObject } = {}) {\n const cache = new InMemoryCache();\n\n if (state) cache.restore(state);\n\n return cache;\n }\n\n private createLink(uri: string, { subscriptionUri }: { subscriptionUri?: string } = {}) {\n const httpLink = new HttpLink({ credentials: 'include', uri });\n const subsLink = subscriptionUri\n ? new WebSocketLink({\n uri: subscriptionUri,\n options: { reconnect: true },\n })\n : undefined;\n\n const hybridLink = subsLink ? createSplitLink(httpLink, subsLink) : httpLink;\n const errorLogger = onError(logError);\n\n return ApolloLink.from([errorLogger, hybridLink]);\n }\n\n /**\n * get the graphQL provider\n */\n getProvider = ({ client, children }: { client: GraphQLClient<any>; children: ReactNode }) => {\n return <GraphQLProvider client={client}>{children}</GraphQLProvider>;\n };\n\n readonly renderPlugins = new GraphqlRenderPlugins(this);\n\n static runtime = UIRuntime;\n static dependencies = [];\n static slots = [];\n\n static async provider() {\n const graphqlUI = new GraphqlUI();\n\n return graphqlUI;\n }\n}\n\nGraphqlAspect.addRuntime(GraphqlUI);\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import type { ApolloClient, NormalizedCacheObject } from '@apollo/client';
|
|
3
|
-
import type { BrowserData,
|
|
3
|
+
import type { BrowserData, RenderPlugins } from '@teambit/ui';
|
|
4
4
|
import type { GraphqlUI, GraphQLClient } from './graphql.ui.runtime';
|
|
5
5
|
declare type RenderContext = {
|
|
6
6
|
client: GraphQLClient<any>;
|
|
7
7
|
};
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class GraphqlRenderPlugins implements RenderPlugins<RenderContext, {
|
|
9
9
|
state?: NormalizedCacheObject;
|
|
10
10
|
}> {
|
|
11
11
|
private graphqlUI;
|
package/dist/render-lifecycle.js
CHANGED
|
@@ -7,7 +7,7 @@ require("core-js/modules/es.promise.js");
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
|
-
exports.
|
|
10
|
+
exports.GraphqlRenderPlugins = void 0;
|
|
11
11
|
|
|
12
12
|
function _defineProperty2() {
|
|
13
13
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -71,7 +71,7 @@ function _graphqlProvider() {
|
|
|
71
71
|
|
|
72
72
|
const ALLOWED_HEADERS = ['cookie'];
|
|
73
73
|
|
|
74
|
-
class
|
|
74
|
+
class GraphqlRenderPlugins {
|
|
75
75
|
constructor(graphqlUI) {
|
|
76
76
|
this.graphqlUI = graphqlUI;
|
|
77
77
|
(0, _defineProperty2().default)(this, "serverInit", ({
|
|
@@ -154,7 +154,7 @@ class GraphqlRenderLifecycle {
|
|
|
154
154
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
exports.
|
|
157
|
+
exports.GraphqlRenderPlugins = GraphqlRenderPlugins;
|
|
158
158
|
|
|
159
159
|
function ServerGqlProvider({
|
|
160
160
|
renderCtx,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["render-lifecycle.tsx"],"names":["ALLOWED_HEADERS","
|
|
1
|
+
{"version":3,"sources":["render-lifecycle.tsx"],"names":["ALLOWED_HEADERS","GraphqlRenderPlugins","constructor","graphqlUI","browser","server","undefined","port","serverUrl","client","createSsrClient","headers","connection","ctx","app","json","JSON","stringify","extract","raw","state","parse","e","console","error","location","window","isInsecure","protocol","wsUrl","host","createClient","subscriptionUri","_client","renderCtx","children","TypeError","isBrowser","BrowserGqlProvider","ServerGqlProvider","getClient","browserInit"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA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;AACnB,WAAO,KAAKwB,OAAZ;AACD;;AAhE0G;;;;AA2E7G,SAASM,iBAAT,CAA2B;AAAEL,EAAAA,SAAF;AAAaC,EAAAA;AAAb,CAA3B,EAAwG;AACtG,MAAI,EAACD,SAAD,aAACA,SAAD,eAACA,SAAS,CAAEzB,MAAZ,CAAJ,EACE,MAAM,IAAI2B,SAAJ,CAAc,oFAAd,CAAN;AAEF,QAAM;AAAE3B,IAAAA;AAAF,MAAayB,SAAnB;AACA,sBAAO,+BAAC,kCAAD;AAAiB,IAAA,MAAM,EAAEzB;AAAzB,KAAkC0B,QAAlC,CAAP;AACD","sourcesContent":["import React, { ReactNode } from 'react';\nimport { getDataFromTree } from '@apollo/client/react/ssr';\nimport type { ApolloClient, NormalizedCacheObject } from '@apollo/client';\nimport pick from 'lodash.pick';\n\nimport { isBrowser } from '@teambit/ui-foundation.ui.is-browser';\nimport type { BrowserData, RenderPlugins } from '@teambit/ui';\n\nimport type { GraphqlUI, GraphQLClient } from './graphql.ui.runtime';\nimport { GraphQLProvider } from './graphql-provider';\n\ntype RenderContext = {\n client: GraphQLClient<any>;\n};\n\nconst ALLOWED_HEADERS = ['cookie'];\n\nexport class GraphqlRenderPlugins implements RenderPlugins<RenderContext, { state?: NormalizedCacheObject }> {\n constructor(private graphqlUI: GraphqlUI) {}\n\n serverInit = ({ browser, server }: { browser?: BrowserData; server?: { port: number } } = {}) => {\n if (!browser) return undefined;\n\n const port = server?.port || 3000;\n const serverUrl = `http://localhost:${port}/graphql`;\n\n const client = this.graphqlUI.createSsrClient({\n serverUrl,\n headers: pick(browser.connection.headers, ALLOWED_HEADERS),\n });\n\n const ctx: RenderContext = { client };\n return ctx;\n };\n\n /**\n * Eagerly and recursively execute all gql queries in the app.\n * Data will be available in gqlClient.extract()\n */\n onBeforeRender = async (ctx: RenderContext, app: ReactNode) => {\n await getDataFromTree(app);\n };\n\n serialize = (ctx?: RenderContext) => {\n const client = ctx?.client;\n if (!client) return undefined;\n\n return {\n json: JSON.stringify(client.extract()),\n };\n };\n\n deserialize = (raw?: string) => {\n if (!raw) return { state: undefined };\n let state: NormalizedCacheObject | undefined;\n try {\n state = JSON.parse(raw);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error('[GraphQL] failed deserializing state from DOM', e);\n }\n\n return { state };\n };\n\n private _client: ApolloClient<NormalizedCacheObject> | undefined = undefined;\n\n browserInit = ({ state }: { state?: NormalizedCacheObject } = {}) => {\n const { location } = window;\n const isInsecure = location.protocol === 'http:';\n const wsUrl = `${isInsecure ? 'ws:' : 'wss:'}//${location.host}/subscriptions`;\n\n const client = this.graphqlUI.createClient('/graphql', { state, subscriptionUri: wsUrl });\n this._client = client;\n\n return { client };\n };\n\n getClient() {\n if (!this._client) return this.browserInit().client;\n return this._client;\n }\n\n private BrowserGqlProvider = ({ renderCtx, children }: { renderCtx?: RenderContext; children: ReactNode }) => {\n if (!renderCtx?.client) throw new TypeError('GQL client is not initialized, make sure `.browserInit()` executes');\n\n return <this.graphqlUI.getProvider client={renderCtx?.client}>{children}</this.graphqlUI.getProvider>;\n };\n\n reactContext = isBrowser ? this.BrowserGqlProvider : ServerGqlProvider;\n}\n\nfunction ServerGqlProvider({ renderCtx, children }: { renderCtx?: RenderContext; children: ReactNode }) {\n if (!renderCtx?.client)\n throw new TypeError('GQL client has not been initialized during SSR, make sure `.serverInit()` executes');\n\n const { client } = renderCtx;\n return <GraphQLProvider client={client}>{children}</GraphQLProvider>;\n}\n"]}
|
package/graphql.ui.runtime.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import crossFetch from 'cross-fetch';
|
|
|
11
11
|
import { createSplitLink } from './create-link';
|
|
12
12
|
import { GraphQLProvider } from './graphql-provider';
|
|
13
13
|
import { GraphqlAspect } from './graphql.aspect';
|
|
14
|
-
import {
|
|
14
|
+
import { GraphqlRenderPlugins } from './render-lifecycle';
|
|
15
15
|
import { logError } from './logging';
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -87,7 +87,7 @@ export class GraphqlUI {
|
|
|
87
87
|
return <GraphQLProvider client={client}>{children}</GraphQLProvider>;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
readonly
|
|
90
|
+
readonly renderPlugins = new GraphqlRenderPlugins(this);
|
|
91
91
|
|
|
92
92
|
static runtime = UIRuntime;
|
|
93
93
|
static dependencies = [];
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/graphql",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.637",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/harmony/graphql",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.harmony",
|
|
8
8
|
"name": "graphql",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.637"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/harmony": "0.2.11",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@teambit/cli": "0.0.434",
|
|
36
36
|
"@teambit/logger": "0.0.524",
|
|
37
37
|
"@teambit/toolbox.network.get-port": "0.0.112",
|
|
38
|
-
"@teambit/preview": "0.0.
|
|
39
|
-
"@teambit/ui": "0.0.
|
|
38
|
+
"@teambit/preview": "0.0.637",
|
|
39
|
+
"@teambit/ui": "0.0.637",
|
|
40
40
|
"@teambit/ui-foundation.ui.is-browser": "0.0.485"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
package/render-lifecycle.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import type { ApolloClient, NormalizedCacheObject } from '@apollo/client';
|
|
|
4
4
|
import pick from 'lodash.pick';
|
|
5
5
|
|
|
6
6
|
import { isBrowser } from '@teambit/ui-foundation.ui.is-browser';
|
|
7
|
-
import type { BrowserData,
|
|
7
|
+
import type { BrowserData, RenderPlugins } from '@teambit/ui';
|
|
8
8
|
|
|
9
9
|
import type { GraphqlUI, GraphQLClient } from './graphql.ui.runtime';
|
|
10
10
|
import { GraphQLProvider } from './graphql-provider';
|
|
@@ -15,7 +15,7 @@ type RenderContext = {
|
|
|
15
15
|
|
|
16
16
|
const ALLOWED_HEADERS = ['cookie'];
|
|
17
17
|
|
|
18
|
-
export class
|
|
18
|
+
export class GraphqlRenderPlugins implements RenderPlugins<RenderContext, { state?: NormalizedCacheObject }> {
|
|
19
19
|
constructor(private graphqlUI: GraphqlUI) {}
|
|
20
20
|
|
|
21
21
|
serverInit = ({ browser, server }: { browser?: BrowserData; server?: { port: number } } = {}) => {
|
|
Binary file
|