@teambit/graphql 0.0.802 → 0.0.803
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/dist/render-lifecycle.d.ts +4 -8
- package/dist/render-lifecycle.js +15 -6
- package/dist/render-lifecycle.js.map +1 -1
- package/package-tar/teambit-graphql-0.0.803.tgz +0 -0
- package/package.json +6 -6
- package/{preview-1659151732866.js → preview-1659271062546.js} +2 -2
- package/render-lifecycle.tsx +7 -6
- package/package-tar/teambit-graphql-0.0.802.tgz +0 -0
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import type { ApolloClient, NormalizedCacheObject } from '@apollo/client';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SSR } 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 GraphqlRenderPlugins implements
|
|
8
|
+
export declare class GraphqlRenderPlugins implements SSR.RenderPlugin<RenderContext, {
|
|
9
9
|
state?: NormalizedCacheObject;
|
|
10
10
|
}> {
|
|
11
11
|
private graphqlUI;
|
|
12
12
|
constructor(graphqlUI: GraphqlUI);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
server?: {
|
|
16
|
-
port: number;
|
|
17
|
-
} | undefined;
|
|
18
|
-
}) => RenderContext | undefined;
|
|
13
|
+
key: string;
|
|
14
|
+
serverInit: ({ browser }: SSR.SsrSession) => RenderContext;
|
|
19
15
|
/**
|
|
20
16
|
* Eagerly and recursively execute all gql queries in the app.
|
|
21
17
|
* Data will be available in gqlClient.extract()
|
package/dist/render-lifecycle.js
CHANGED
|
@@ -69,21 +69,30 @@ function _graphqlProvider() {
|
|
|
69
69
|
return data;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
function _graphql() {
|
|
73
|
+
const data = require("./graphql.aspect");
|
|
74
|
+
|
|
75
|
+
_graphql = function () {
|
|
76
|
+
return data;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
|
|
72
82
|
const ALLOWED_HEADERS = ['cookie'];
|
|
73
83
|
|
|
74
84
|
class GraphqlRenderPlugins {
|
|
75
85
|
constructor(graphqlUI) {
|
|
76
86
|
this.graphqlUI = graphqlUI;
|
|
87
|
+
(0, _defineProperty2().default)(this, "key", _graphql().GraphqlAspect.id);
|
|
77
88
|
(0, _defineProperty2().default)(this, "serverInit", ({
|
|
78
|
-
browser
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!browser) return undefined;
|
|
82
|
-
const port = (server === null || server === void 0 ? void 0 : server.port) || 3000;
|
|
89
|
+
browser
|
|
90
|
+
}) => {
|
|
91
|
+
const port = (browser === null || browser === void 0 ? void 0 : browser.location.port) || 3000;
|
|
83
92
|
const serverUrl = `http://localhost:${port}/graphql`;
|
|
84
93
|
const client = this.graphqlUI.createSsrClient({
|
|
85
94
|
serverUrl,
|
|
86
|
-
headers: (0, _lodash().default)(browser.
|
|
95
|
+
headers: (0, _lodash().default)(browser === null || browser === void 0 ? void 0 : browser.headers, ALLOWED_HEADERS)
|
|
87
96
|
});
|
|
88
97
|
const ctx = {
|
|
89
98
|
client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ALLOWED_HEADERS","GraphqlRenderPlugins","constructor","graphqlUI","
|
|
1
|
+
{"version":3,"names":["ALLOWED_HEADERS","GraphqlRenderPlugins","constructor","graphqlUI","GraphqlAspect","id","browser","port","location","serverUrl","client","createSsrClient","headers","pick","ctx","app","getDataFromTree","undefined","json","JSON","stringify","extract","raw","state","parse","e","console","error","window","isInsecure","protocol","wsUrl","host","createClient","subscriptionUri","_client","renderCtx","children","TypeError","isBrowser","BrowserGqlProvider","ServerGqlProvider","getClient","browserInit"],"sources":["render-lifecycle.tsx"],"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 { SSR } from '@teambit/ui';\n\nimport type { GraphqlUI, GraphQLClient } from './graphql.ui.runtime';\nimport { GraphQLProvider } from './graphql-provider';\nimport { GraphqlAspect } from './graphql.aspect';\n\ntype RenderContext = {\n client: GraphQLClient<any>;\n};\n\nconst ALLOWED_HEADERS = ['cookie'];\n\nexport class GraphqlRenderPlugins implements SSR.RenderPlugin<RenderContext, { state?: NormalizedCacheObject }> {\n constructor(private graphqlUI: GraphqlUI) {}\n\n key = GraphqlAspect.id;\n\n serverInit = ({ browser }: SSR.SsrSession) => {\n const port = browser?.location.port || 3000;\n const serverUrl = `http://localhost:${port}/graphql`;\n\n const client = this.graphqlUI.createSsrClient({\n serverUrl,\n headers: pick(browser?.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMA,MAAMA,eAAe,GAAG,CAAC,QAAD,CAAxB;;AAEO,MAAMC,oBAAN,CAAyG;EAC9GC,WAAW,CAASC,SAAT,EAA+B;IAAA,KAAtBA,SAAsB,GAAtBA,SAAsB;IAAA,6CAEpCC,wBAAA,CAAcC,EAFsB;IAAA,oDAI7B,CAAC;MAAEC;IAAF,CAAD,KAAiC;MAC5C,MAAMC,IAAI,GAAG,CAAAD,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEE,QAAT,CAAkBD,IAAlB,KAA0B,IAAvC;MACA,MAAME,SAAS,GAAI,oBAAmBF,IAAK,UAA3C;MAEA,MAAMG,MAAM,GAAG,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/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.803"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@graphql-modules/core": "0.7.17",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"@babel/runtime": "7.12.18",
|
|
33
33
|
"core-js": "^3.0.0",
|
|
34
34
|
"@teambit/harmony": "0.3.3",
|
|
35
|
-
"@teambit/cli": "0.0.
|
|
36
|
-
"@teambit/logger": "0.0.
|
|
35
|
+
"@teambit/cli": "0.0.535",
|
|
36
|
+
"@teambit/logger": "0.0.628",
|
|
37
37
|
"@teambit/toolbox.network.get-port": "0.0.113",
|
|
38
|
-
"@teambit/ui": "0.0.
|
|
38
|
+
"@teambit/ui": "0.0.803",
|
|
39
39
|
"@teambit/ui-foundation.ui.is-browser": "0.0.486"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@apollo/client": "^3.0.0",
|
|
55
55
|
"graphql": "14.7.0",
|
|
56
|
-
"@teambit/legacy": "1.0.
|
|
56
|
+
"@teambit/legacy": "1.0.317",
|
|
57
57
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
58
58
|
"react": "^16.8.0 || ^17.0.0"
|
|
59
59
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_graphql@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_graphql@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_graphql@0.0.803/dist/graphql.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_graphql@0.0.803/dist/graphql.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
package/render-lifecycle.tsx
CHANGED
|
@@ -4,10 +4,11 @@ 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 {
|
|
7
|
+
import type { SSR } from '@teambit/ui';
|
|
8
8
|
|
|
9
9
|
import type { GraphqlUI, GraphQLClient } from './graphql.ui.runtime';
|
|
10
10
|
import { GraphQLProvider } from './graphql-provider';
|
|
11
|
+
import { GraphqlAspect } from './graphql.aspect';
|
|
11
12
|
|
|
12
13
|
type RenderContext = {
|
|
13
14
|
client: GraphQLClient<any>;
|
|
@@ -15,18 +16,18 @@ type RenderContext = {
|
|
|
15
16
|
|
|
16
17
|
const ALLOWED_HEADERS = ['cookie'];
|
|
17
18
|
|
|
18
|
-
export class GraphqlRenderPlugins implements
|
|
19
|
+
export class GraphqlRenderPlugins implements SSR.RenderPlugin<RenderContext, { state?: NormalizedCacheObject }> {
|
|
19
20
|
constructor(private graphqlUI: GraphqlUI) {}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
if (!browser) return undefined;
|
|
22
|
+
key = GraphqlAspect.id;
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
serverInit = ({ browser }: SSR.SsrSession) => {
|
|
25
|
+
const port = browser?.location.port || 3000;
|
|
25
26
|
const serverUrl = `http://localhost:${port}/graphql`;
|
|
26
27
|
|
|
27
28
|
const client = this.graphqlUI.createSsrClient({
|
|
28
29
|
serverUrl,
|
|
29
|
-
headers: pick(browser
|
|
30
|
+
headers: pick(browser?.headers, ALLOWED_HEADERS),
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
const ctx: RenderContext = { client };
|
|
Binary file
|