stellate 2.9.0 → 2.10.0
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/apollo-server.d.ts +1 -0
- package/dist/apollo-server.js +2 -2
- package/dist/apollo-server.mjs +44 -1
- package/dist/bin.js +2 -2
- package/dist/envelop.d.ts +1 -0
- package/dist/envelop.js +2 -2
- package/dist/envelop.mjs +76 -45
- package/dist/graphql-yoga.d.ts +1 -0
- package/dist/graphql-yoga.js +2 -2
- package/dist/graphql-yoga.mjs +71 -39
- package/package.json +1 -1
package/dist/apollo-server.d.ts
CHANGED
package/dist/apollo-server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);
|
|
1
|
+
"use strict";var b=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0})},D=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of q(t))!E.call(e,r)&&r!==n&&b(e,r,{get:()=>t[r],enumerable:!(o=A(t,r))||o.enumerable});return e};var R=e=>D(b({},"__esModule",{value:!0}),e);var J={};C(J,{createBlake3Hash:()=>g,createStellateLoggerPlugin:()=>$});module.exports=R(J);function g(e){let t=0,n=e.length;if(n===0)return t;for(let o=0;o<n;++o){let r=e.charCodeAt(o);t=(t<<5)-t+r,t&=t}return t>>>0}function T({headers:e,operation:t,method:n,start:o,operationName:r,errors:m,response:d,variables:u,responseHeaders:s,sendVariablesAsHash:l,hasSetCookie:p}){let h=e.get("x-forwarded-for"),y=h?h.split(","):[],c=s&&s.get("vary"),f;if(c&&c.length){let v=c.split(",").map(a=>a&&a.trim()).sort().map(a=>{let i=a&&e.get(a);return i?`${a}:${i}`:void 0}).filter(Boolean).join(`
|
|
2
|
+
`);f=g(v)}return{operation:t,operationName:r,variables:l?void 0:u,variableHash:l?g(JSON.stringify(u||{})):void 0,method:n,elapsed:Date.now()-o,ip:y[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:p,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:m,responseSize:JSON.stringify(d).length,responseHash:g(JSON.stringify(d)),varyHash:f}}function P(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var k=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function L({fetch:e,payload:t,token:n,serviceName:o}){return e(`https://${o}.${k}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":n}})}var N=require("graphql");var $=e=>{var d,u;let t=(d=e.sendVariablesAsHash)!=null?d:!0,n=(u=e.schemaSyncing)!=null?u:!0,o=!1,r,m=async s=>{if(n){let l=(0,N.introspectionFromSchema)(s),p=Math.random()*5e3;r&&clearTimeout(r),r=setTimeout(async()=>{if(r=null,!o)try{e.fetch(`https://${e.serviceName}.${k}/schema`,{method:"POST",body:JSON.stringify({schema:l}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{})}catch{}},p)}};return{async serverWillStart(){return{schemaDidLoadOrUpdate({apiSchema:s}){m(s)},async serverWillStop(){o=!0,r&&clearTimeout(r)}}},async requestDidStart(s){let l=Date.now(),{request:p}=s,{operationName:h,variables:y,http:c,query:f}=p;if(!c)return;let{headers:S,method:v}=c;if(!S.has("gcdn-request-id"))return{async willSendResponse(a){let{response:i,source:w}=a;if(i.body.kind!=="single"){console.warn("Stellate does not currently support logging incremental results.");return}let O=i.body.singleResult,H=f||w;if(!H)return;let x=T({headers:S,responseHeaders:i.http.headers,operation:H,method:v,sendVariablesAsHash:t,start:l,operationName:h,errors:a.errors,response:O,variables:y,hasSetCookie:i.http.headers.has("set-cookie")});P(e.fetch);try{await L({fetch:e.fetch,payload:x,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
|
package/dist/apollo-server.mjs
CHANGED
|
@@ -81,10 +81,53 @@ async function logRequest({
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// src/apollo-server.ts
|
|
84
|
+
import { introspectionFromSchema } from "graphql";
|
|
84
85
|
var createStellateLoggerPlugin = (options) => {
|
|
85
|
-
var _a;
|
|
86
|
+
var _a, _b;
|
|
86
87
|
const sendVariablesAsHash = (_a = options.sendVariablesAsHash) != null ? _a : true;
|
|
88
|
+
const shouldSyncSchema = (_b = options.schemaSyncing) != null ? _b : true;
|
|
89
|
+
let stopped = false, timeout;
|
|
90
|
+
const sendSchema = async (apiSchema) => {
|
|
91
|
+
if (shouldSyncSchema) {
|
|
92
|
+
const introspection = introspectionFromSchema(apiSchema);
|
|
93
|
+
const randomTimeout = Math.random() * 5e3;
|
|
94
|
+
if (timeout)
|
|
95
|
+
clearTimeout(timeout);
|
|
96
|
+
timeout = setTimeout(async () => {
|
|
97
|
+
timeout = null;
|
|
98
|
+
if (!stopped) {
|
|
99
|
+
try {
|
|
100
|
+
options.fetch(`https://${options.serviceName}.${hostname}/schema`, {
|
|
101
|
+
method: "POST",
|
|
102
|
+
body: JSON.stringify({
|
|
103
|
+
schema: introspection
|
|
104
|
+
}),
|
|
105
|
+
headers: {
|
|
106
|
+
"Content-Type": "application/json",
|
|
107
|
+
"Stellate-Schema-Token": options.token
|
|
108
|
+
}
|
|
109
|
+
}).then(() => {
|
|
110
|
+
});
|
|
111
|
+
} catch (e) {
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}, randomTimeout);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
87
117
|
return {
|
|
118
|
+
async serverWillStart() {
|
|
119
|
+
return {
|
|
120
|
+
schemaDidLoadOrUpdate({ apiSchema }) {
|
|
121
|
+
sendSchema(apiSchema);
|
|
122
|
+
},
|
|
123
|
+
async serverWillStop() {
|
|
124
|
+
stopped = true;
|
|
125
|
+
if (timeout) {
|
|
126
|
+
clearTimeout(timeout);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
},
|
|
88
131
|
async requestDidStart(requestCtx) {
|
|
89
132
|
const start = Date.now();
|
|
90
133
|
const { request } = requestCtx;
|
package/dist/bin.js
CHANGED
|
@@ -1094,7 +1094,7 @@ Try running "stellate pull" first if your service has been created already.`);le
|
|
|
1094
1094
|
|
|
1095
1095
|
-s, --service Name of the service
|
|
1096
1096
|
-b, --browser Automatically open the preview UI with the default browser
|
|
1097
|
-
`);var ms=Ae(sn());var vv=Ae(sn());var RD=class{async parse(e){return ji(e,{"--help":Boolean,"-h":"--help","--version":Boolean,"-v":"--version","--json":Boolean})["--help"]?this.help():"stellate@2.
|
|
1097
|
+
`);var ms=Ae(sn());var vv=Ae(sn());var RD=class{async parse(e){return ji(e,{"--help":Boolean,"-h":"--help","--version":Boolean,"-v":"--version","--json":Boolean})["--help"]?this.help():"stellate@2.10.0"}help(e){if(e)throw new pn(`
|
|
1098
1098
|
${vv.default.bold.red("!")} ${e}
|
|
1099
1099
|
${RD.help}`);return RD.help}},Py=RD;Py.help=Mi(`
|
|
1100
1100
|
Print current version of Stellate
|
|
@@ -1392,7 +1392,7 @@ Try running "stellate pull" first if your service has been created already.`);le
|
|
|
1392
1392
|
value
|
|
1393
1393
|
}
|
|
1394
1394
|
}
|
|
1395
|
-
`,u=await Cn();a=(await new Xi(u).query(l,{name:"serve-token-"+Date.now(),appName:e})).createAdminApiToken.value,this.writePurgeToken(e,a)}let o=(0,GJ.default)();o.use("/",(0,WJ.createProxyMiddleware)({target:s,changeOrigin:!0,logLevel:"silent",onProxyReq:l=>{l.path.endsWith("/")&&(l.path=l.path.slice(0,-1)),l.setHeader("stellate-cli-serve-port",r),l.setHeader("stellate-token",a)}})),o.listen(r)}setupApiProxy(e,r){let i=`https://${e}.stellate.${process.env.STELLATE_ENDPOINT==="staging"||process.env.STELLATE_ENDPOINT==="local"?"dev":"sh"}`,n=(0,GJ.default)();n.use("/",(0,WJ.createProxyMiddleware)({target:i,changeOrigin:!0,headers:{"stellate-cli-serve-port":""+r},logLevel:"silent"})),n.listen(r)}ensureConfig(){Wh.default.existsSync(lc)||Wh.default.mkdirSync(lc)}getCache(){try{this.ensureConfig();let e=Wh.default.readFileSync(BS,"utf-8");return JSON.parse(e)}catch{return{}}}getCacheEntry(e){try{this.ensureConfig();let r=Wh.default.readFileSync(BS,"utf-8"),i=JSON.parse(r);if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return i[e]||{checksum:"",envName:""}}catch{return{checksum:"",envName:""}}}getChecksum(e){return zdr(JSON.stringify(e)+"2.
|
|
1395
|
+
`,u=await Cn();a=(await new Xi(u).query(l,{name:"serve-token-"+Date.now(),appName:e})).createAdminApiToken.value,this.writePurgeToken(e,a)}let o=(0,GJ.default)();o.use("/",(0,WJ.createProxyMiddleware)({target:s,changeOrigin:!0,logLevel:"silent",onProxyReq:l=>{l.path.endsWith("/")&&(l.path=l.path.slice(0,-1)),l.setHeader("stellate-cli-serve-port",r),l.setHeader("stellate-token",a)}})),o.listen(r)}setupApiProxy(e,r){let i=`https://${e}.stellate.${process.env.STELLATE_ENDPOINT==="staging"||process.env.STELLATE_ENDPOINT==="local"?"dev":"sh"}`,n=(0,GJ.default)();n.use("/",(0,WJ.createProxyMiddleware)({target:i,changeOrigin:!0,headers:{"stellate-cli-serve-port":""+r},logLevel:"silent"})),n.listen(r)}ensureConfig(){Wh.default.existsSync(lc)||Wh.default.mkdirSync(lc)}getCache(){try{this.ensureConfig();let e=Wh.default.readFileSync(BS,"utf-8");return JSON.parse(e)}catch{return{}}}getCacheEntry(e){try{this.ensureConfig();let r=Wh.default.readFileSync(BS,"utf-8"),i=JSON.parse(r);if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return i[e]||{checksum:"",envName:""}}catch{return{checksum:"",envName:""}}}getChecksum(e){return zdr(JSON.stringify(e)+"2.10.0")}writePurgeToken(e,r){let i=this.getCache();i[e]={...i[e],purgeToken:r},Wh.default.writeFileSync(BS,JSON.stringify(i))}writeCache(e,r,i){let n=this.getCache();if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return n[e]={checksum:this.getChecksum(r),envName:i},Wh.default.writeFileSync(BS,JSON.stringify(n)),n[e]}},Tw=zJ;Tw.help=Mi(`
|
|
1396
1396
|
(BETA) - Use a local backend with Stellate\u2019s GraphQL Edge Cache.
|
|
1397
1397
|
|
|
1398
1398
|
${kv.default.bold("Usage")}
|
package/dist/envelop.d.ts
CHANGED
package/dist/envelop.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);
|
|
1
|
+
"use strict";var m=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var r in t)m(e,r,{get:t[r],enumerable:!0})},E=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of T(t))!O.call(e,o)&&o!==r&&m(e,o,{get:()=>t[o],enumerable:!(n=P(t,o))||n.enumerable});return e};var q=e=>E(m({},"__esModule",{value:!0}),e);var R={};C(R,{createBlake3Hash:()=>g,createStellateLoggerPlugin:()=>A});module.exports=q(R);var h=require("graphql"),L=require("@envelop/core");function g(e){let t=0,r=e.length;if(r===0)return t;for(let n=0;n<r;++n){let o=e.charCodeAt(n);t=(t<<5)-t+o,t&=t}return t>>>0}function w({headers:e,operation:t,method:r,start:n,operationName:o,errors:u,response:i,variables:a,responseHeaders:c,sendVariablesAsHash:s,hasSetCookie:p}){let d=e.get("x-forwarded-for"),b=d?d.split(","):[],f=c&&c.get("vary"),v;if(f&&f.length){let N=f.split(",").map(l=>l&&l.trim()).sort().map(l=>{let k=l&&e.get(l);return k?`${l}:${k}`:void 0}).filter(Boolean).join(`
|
|
2
|
+
`);v=g(N)}return{operation:t,operationName:o,variables:s?void 0:a,variableHash:s?g(JSON.stringify(a||{})):void 0,method:r,elapsed:Date.now()-n,ip:b[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:p,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:u,responseSize:JSON.stringify(i).length,responseHash:g(JSON.stringify(i)),varyHash:v}}function x(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var y=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function H({fetch:e,payload:t,token:r,serviceName:n}){return e(`https://${n}.${y}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":r}})}var S=class{constructor(t){this.headers=Object.keys(t).reduce((r,n)=>(r[n.trim().toLowerCase()]=t[n],r),{})}get(t){return this.headers[t.trim().toLowerCase()]}has(t){return!!this.headers[t.trim().toLowerCase()]}},A=e=>{var n;let t=(n=e.schemaSyncing)!=null?n:!0,r;return{onSchemaChange(o){if(t){let u=o.schema,i=Math.random()*5e3;r&&clearTimeout(r),r=setTimeout(async()=>{r=null;try{let a=(0,h.introspectionFromSchema)(u);e.fetch(`https://${e.serviceName}.${y}/schema`,{method:"POST",body:JSON.stringify({schema:a}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{})}catch{}},i)}},onExecute(o){var a;let u=(a=e.sendVariablesAsHash)!=null?a:!0,i=Date.now();return{async onExecuteDone({result:c}){if((0,L.isAsyncIterable)(c)){console.warn("Stellate does not currently support logging incremental results.");return}let{headers:s}=o.args.contextValue.request,{method:p}=o.args.contextValue.request;if(typeof s.get!="function"&&(s=new S(s)),s.has("gcdn-request-id"))return;let d=w({headers:s,operation:(0,h.print)(o.args.document),method:p,sendVariablesAsHash:u,start:i,operationName:o.args.operationName,errors:c.errors,response:c});x(e.fetch);try{await H({fetch:e.fetch,payload:d,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
|
package/dist/envelop.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/envelop.ts
|
|
2
|
-
import { print } from "graphql";
|
|
2
|
+
import { introspectionFromSchema, print } from "graphql";
|
|
3
3
|
import { isAsyncIterable } from "@envelop/core";
|
|
4
4
|
|
|
5
5
|
// src/server-plugins-shared.ts
|
|
@@ -99,52 +99,83 @@ var FauxHeaders = class {
|
|
|
99
99
|
return !!this.headers[key.trim().toLowerCase()];
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
|
-
var createStellateLoggerPlugin = (options) =>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
102
|
+
var createStellateLoggerPlugin = (options) => {
|
|
103
|
+
var _a;
|
|
104
|
+
const shouldSyncSchema = (_a = options.schemaSyncing) != null ? _a : true;
|
|
105
|
+
let timeout;
|
|
106
|
+
return {
|
|
107
|
+
onSchemaChange(opts) {
|
|
108
|
+
if (shouldSyncSchema) {
|
|
109
|
+
const apiSchema = opts.schema;
|
|
110
|
+
const randomTimeout = Math.random() * 5e3;
|
|
111
|
+
if (timeout)
|
|
112
|
+
clearTimeout(timeout);
|
|
113
|
+
timeout = setTimeout(async () => {
|
|
114
|
+
timeout = null;
|
|
115
|
+
try {
|
|
116
|
+
const introspection = introspectionFromSchema(apiSchema);
|
|
117
|
+
options.fetch(`https://${options.serviceName}.${hostname}/schema`, {
|
|
118
|
+
method: "POST",
|
|
119
|
+
body: JSON.stringify({
|
|
120
|
+
schema: introspection
|
|
121
|
+
}),
|
|
122
|
+
headers: {
|
|
123
|
+
"Content-Type": "application/json",
|
|
124
|
+
"Stellate-Schema-Token": options.token
|
|
125
|
+
}
|
|
126
|
+
}).then(() => {
|
|
127
|
+
});
|
|
128
|
+
} catch (e) {
|
|
129
|
+
}
|
|
130
|
+
}, randomTimeout);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
onExecute(payload) {
|
|
134
|
+
var _a2;
|
|
135
|
+
const sendVariablesAsHash = (_a2 = options.sendVariablesAsHash) != null ? _a2 : true;
|
|
136
|
+
const start = Date.now();
|
|
137
|
+
return {
|
|
138
|
+
async onExecuteDone({ result }) {
|
|
139
|
+
if (isAsyncIterable(result)) {
|
|
140
|
+
console.warn(
|
|
141
|
+
`Stellate does not currently support logging incremental results.`
|
|
142
|
+
);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
let { headers } = payload.args.contextValue.request;
|
|
146
|
+
const { method } = payload.args.contextValue.request;
|
|
147
|
+
if (typeof headers.get !== "function") {
|
|
148
|
+
headers = new FauxHeaders(
|
|
149
|
+
headers
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (headers.has("gcdn-request-id"))
|
|
153
|
+
return;
|
|
154
|
+
const stellatePayload = extractStellatePayload({
|
|
155
|
+
headers,
|
|
156
|
+
operation: print(payload.args.document),
|
|
157
|
+
method,
|
|
158
|
+
sendVariablesAsHash,
|
|
159
|
+
start,
|
|
160
|
+
operationName: payload.args.operationName,
|
|
161
|
+
errors: result.errors,
|
|
162
|
+
response: result
|
|
141
163
|
});
|
|
142
|
-
|
|
164
|
+
warnFetch(options.fetch);
|
|
165
|
+
try {
|
|
166
|
+
await logRequest({
|
|
167
|
+
fetch: options.fetch,
|
|
168
|
+
payload: stellatePayload,
|
|
169
|
+
token: options.token,
|
|
170
|
+
serviceName: options.serviceName
|
|
171
|
+
});
|
|
172
|
+
} catch (e) {
|
|
173
|
+
}
|
|
143
174
|
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
};
|
|
148
179
|
export {
|
|
149
180
|
createBlake3Hash,
|
|
150
181
|
createStellateLoggerPlugin
|
package/dist/graphql-yoga.d.ts
CHANGED
package/dist/graphql-yoga.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);
|
|
1
|
+
"use strict";var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var n in t)m(e,n,{get:t[n],enumerable:!0})},E=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of L(t))!w.call(e,r)&&r!==n&&m(e,r,{get:()=>t[r],enumerable:!(a=T(t,r))||a.enumerable});return e};var A=e=>E(m({},"__esModule",{value:!0}),e);var q={};O(q,{createBlake3Hash:()=>g,createStellateLoggerPlugin:()=>C});module.exports=A(q);var p=require("graphql"),N=require("graphql-yoga");function g(e){let t=0,n=e.length;if(n===0)return t;for(let a=0;a<n;++a){let r=e.charCodeAt(a);t=(t<<5)-t+r,t&=t}return t>>>0}function k({headers:e,operation:t,method:n,start:a,operationName:r,errors:l,response:s,variables:o,responseHeaders:i,sendVariablesAsHash:u,hasSetCookie:h}){let d=e.get("x-forwarded-for"),S=d?d.split(","):[],f=i&&i.get("vary"),b;if(f&&f.length){let P=f.split(",").map(c=>c&&c.trim()).sort().map(c=>{let v=c&&e.get(c);return v?`${c}:${v}`:void 0}).filter(Boolean).join(`
|
|
2
|
+
`);b=g(P)}return{operation:t,operationName:r,variables:u?void 0:o,variableHash:u?g(JSON.stringify(o||{})):void 0,method:n,elapsed:Date.now()-a,ip:S[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:h,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:l,responseSize:JSON.stringify(s).length,responseHash:g(JSON.stringify(s)),varyHash:b}}function x(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var y=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function H({fetch:e,payload:t,token:n,serviceName:a}){return e(`https://${a}.${y}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":n}})}var C=e=>{var a;let t=(a=e.schemaSyncing)!=null?a:!0,n;return{onSchemaChange(r){if(t){let l=r.schema,s=Math.random()*5e3;n&&clearTimeout(n),n=setTimeout(async()=>{n=null;try{let o=(0,p.introspectionFromSchema)(l);e.fetch(`https://${e.serviceName}.${y}/schema`,{method:"POST",body:JSON.stringify({schema:o}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{}).catch(()=>{})}catch{}},s)}},onExecute(r){var o;let l=(o=e.sendVariablesAsHash)!=null?o:!0,s=Date.now();return{async onExecuteDone({result:i}){if((0,N.isAsyncIterable)(i)){console.warn("Stellate does not currently support logging incremental results.");return}let{headers:u,method:h}=r.args.contextValue.request;if(u.has("gcdn-request-id"))return;let d=k({headers:u,operation:(0,p.print)(r.args.document),method:h,sendVariablesAsHash:l,start:s,operationName:r.args.operationName,errors:i.errors,response:i});x(e.fetch);try{await H({fetch:e.fetch,payload:d,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
|
package/dist/graphql-yoga.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/graphql-yoga.ts
|
|
2
|
-
import { print } from "graphql";
|
|
2
|
+
import { print, introspectionFromSchema } from "graphql";
|
|
3
3
|
import { isAsyncIterable } from "graphql-yoga";
|
|
4
4
|
|
|
5
5
|
// src/server-plugins-shared.ts
|
|
@@ -85,46 +85,78 @@ async function logRequest({
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// src/graphql-yoga.ts
|
|
88
|
-
var createStellateLoggerPlugin = (options) =>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
88
|
+
var createStellateLoggerPlugin = (options) => {
|
|
89
|
+
var _a;
|
|
90
|
+
const shouldSyncSchema = (_a = options.schemaSyncing) != null ? _a : true;
|
|
91
|
+
let timeout;
|
|
92
|
+
return {
|
|
93
|
+
onSchemaChange(opts) {
|
|
94
|
+
if (shouldSyncSchema) {
|
|
95
|
+
const apiSchema = opts.schema;
|
|
96
|
+
const randomTimeout = Math.random() * 5e3;
|
|
97
|
+
if (timeout)
|
|
98
|
+
clearTimeout(timeout);
|
|
99
|
+
timeout = setTimeout(async () => {
|
|
100
|
+
timeout = null;
|
|
101
|
+
try {
|
|
102
|
+
const introspection = introspectionFromSchema(apiSchema);
|
|
103
|
+
options.fetch(`https://${options.serviceName}.${hostname}/schema`, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
body: JSON.stringify({
|
|
106
|
+
schema: introspection
|
|
107
|
+
}),
|
|
108
|
+
headers: {
|
|
109
|
+
"Content-Type": "application/json",
|
|
110
|
+
"Stellate-Schema-Token": options.token
|
|
111
|
+
}
|
|
112
|
+
}).then(() => {
|
|
113
|
+
}).catch(() => {
|
|
114
|
+
});
|
|
115
|
+
} catch (e) {
|
|
116
|
+
}
|
|
117
|
+
}, randomTimeout);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
onExecute(payload) {
|
|
121
|
+
var _a2;
|
|
122
|
+
const sendVariablesAsHash = (_a2 = options.sendVariablesAsHash) != null ? _a2 : true;
|
|
123
|
+
const start = Date.now();
|
|
124
|
+
return {
|
|
125
|
+
async onExecuteDone({ result }) {
|
|
126
|
+
if (isAsyncIterable(result)) {
|
|
127
|
+
console.warn(
|
|
128
|
+
`Stellate does not currently support logging incremental results.`
|
|
129
|
+
);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const { headers, method } = payload.args.contextValue.request;
|
|
133
|
+
if (headers.has("gcdn-request-id"))
|
|
134
|
+
return;
|
|
135
|
+
const stellatePayload = extractStellatePayload({
|
|
136
|
+
headers,
|
|
137
|
+
operation: print(payload.args.document),
|
|
138
|
+
method,
|
|
139
|
+
sendVariablesAsHash,
|
|
140
|
+
start,
|
|
141
|
+
operationName: payload.args.operationName,
|
|
142
|
+
errors: result.errors,
|
|
143
|
+
response: result
|
|
121
144
|
});
|
|
122
|
-
|
|
145
|
+
warnFetch(options.fetch);
|
|
146
|
+
try {
|
|
147
|
+
await logRequest({
|
|
148
|
+
fetch: options.fetch,
|
|
149
|
+
payload: stellatePayload,
|
|
150
|
+
token: options.token,
|
|
151
|
+
serviceName: options.serviceName
|
|
152
|
+
});
|
|
153
|
+
} catch (e) {
|
|
154
|
+
}
|
|
123
155
|
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
};
|
|
128
160
|
export {
|
|
129
161
|
createBlake3Hash,
|
|
130
162
|
createStellateLoggerPlugin
|