stellate 2.8.2 → 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 -1
- package/dist/apollo-server.mjs +58 -2
- package/dist/bin.js +215 -215
- package/dist/envelop.d.ts +1 -0
- package/dist/envelop.js +2 -1
- package/dist/envelop.mjs +89 -46
- package/dist/graphql-yoga.d.ts +1 -0
- package/dist/graphql-yoga.js +2 -1
- package/dist/graphql-yoga.mjs +84 -40
- package/dist/index.d.ts +138 -0
- package/package.json +2 -2
package/dist/apollo-server.d.ts
CHANGED
package/dist/apollo-server.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
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
|
@@ -21,11 +21,22 @@ function extractStellatePayload({
|
|
|
21
21
|
errors,
|
|
22
22
|
response,
|
|
23
23
|
variables,
|
|
24
|
+
responseHeaders,
|
|
24
25
|
sendVariablesAsHash,
|
|
25
26
|
hasSetCookie
|
|
26
27
|
}) {
|
|
27
28
|
const forwardedFor = headers.get("x-forwarded-for");
|
|
28
29
|
const ips = forwardedFor ? forwardedFor.split(",") : [];
|
|
30
|
+
const vary = responseHeaders && responseHeaders.get("vary");
|
|
31
|
+
let varyHash = void 0;
|
|
32
|
+
if (vary && vary.length) {
|
|
33
|
+
const varyHeaders = vary.split(",").map((headerName) => headerName && headerName.trim()).sort();
|
|
34
|
+
const variedValues = varyHeaders.map((headerName) => {
|
|
35
|
+
const headerValue = headerName && headers.get(headerName);
|
|
36
|
+
return headerValue ? `${headerName}:${headerValue}` : void 0;
|
|
37
|
+
}).filter(Boolean).join("\n");
|
|
38
|
+
varyHash = createBlake3Hash(variedValues);
|
|
39
|
+
}
|
|
29
40
|
return {
|
|
30
41
|
operation,
|
|
31
42
|
operationName,
|
|
@@ -40,7 +51,8 @@ function extractStellatePayload({
|
|
|
40
51
|
statusCode: 200,
|
|
41
52
|
errors,
|
|
42
53
|
responseSize: JSON.stringify(response).length,
|
|
43
|
-
responseHash: createBlake3Hash(JSON.stringify(response))
|
|
54
|
+
responseHash: createBlake3Hash(JSON.stringify(response)),
|
|
55
|
+
varyHash
|
|
44
56
|
};
|
|
45
57
|
}
|
|
46
58
|
function warnFetch(fetch) {
|
|
@@ -69,10 +81,53 @@ async function logRequest({
|
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
// src/apollo-server.ts
|
|
84
|
+
import { introspectionFromSchema } from "graphql";
|
|
72
85
|
var createStellateLoggerPlugin = (options) => {
|
|
73
|
-
var _a;
|
|
86
|
+
var _a, _b;
|
|
74
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
|
+
};
|
|
75
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
|
+
},
|
|
76
131
|
async requestDidStart(requestCtx) {
|
|
77
132
|
const start = Date.now();
|
|
78
133
|
const { request } = requestCtx;
|
|
@@ -97,6 +152,7 @@ var createStellateLoggerPlugin = (options) => {
|
|
|
97
152
|
return;
|
|
98
153
|
const stellatePayload = extractStellatePayload({
|
|
99
154
|
headers,
|
|
155
|
+
responseHeaders: response.http.headers,
|
|
100
156
|
operation: queryString,
|
|
101
157
|
method,
|
|
102
158
|
sendVariablesAsHash,
|