netlify-onegraph-internal
Advanced tools
Comparing version 0.8.7 to 0.9.0
@@ -28,3 +28,3 @@ import * as GraphQL from "graphql"; | ||
schema: GraphQLSchema; | ||
}) => ExporterResult; | ||
}) => Promise<ExporterResult>; | ||
export declare type GenerateHandlerPreviewFunction = (opts: { | ||
@@ -31,0 +31,0 @@ GraphQL: typeof GraphQL; |
@@ -13,2 +13,38 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -329,58 +365,61 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
version: "0.0.1", | ||
generateHandler: function (opts) { | ||
var netlifyGraphConfig = opts.netlifyGraphConfig, options = opts.options; | ||
var operationDataList = opts.operationDataList.map(function (operationData, idx) { | ||
if (!isOperationNamed(operationData)) { | ||
return __assign(__assign({}, operationData), { name: ("unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1)).trim(), query: "# Consider giving this " + operationData.type + " a unique, descriptive\n# name in your application as a best practice\n" + operationData.type + " unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1) + " " + operationData.query | ||
.trim() | ||
.replace(/^(query|mutation|subscription) /i, "") }); | ||
generateHandler: function (opts) { return __awaiter(void 0, void 0, void 0, function () { | ||
var netlifyGraphConfig, options, operationDataList, firstOperation, filename, isSubscription, result, fetcherInvocation, passThroughResults, clientSideCalls, whitespace, snippet, content; | ||
return __generator(this, function (_a) { | ||
netlifyGraphConfig = opts.netlifyGraphConfig, options = opts.options; | ||
operationDataList = opts.operationDataList.map(function (operationData, idx) { | ||
if (!isOperationNamed(operationData)) { | ||
return __assign(__assign({}, operationData), { name: ("unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1)).trim(), query: "# Consider giving this " + operationData.type + " a unique, descriptive\n# name in your application as a best practice\n" + operationData.type + " unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1) + " " + operationData.query | ||
.trim() | ||
.replace(/^(query|mutation|subscription) /i, "") }); | ||
} | ||
return operationData; | ||
}); | ||
firstOperation = operationDataList.find(function (operation) { | ||
return operation.operationDefinition.kind === "OperationDefinition"; | ||
}); | ||
if (!firstOperation) { | ||
return [2 /*return*/, { | ||
exportedFiles: [ | ||
{ | ||
kind: "UnnamedExportedFile", | ||
content: "// No operation found", | ||
language: "javascript", | ||
}, | ||
], | ||
}]; | ||
} | ||
return operationData; | ||
filename = firstOperation.name + "." + netlifyGraphConfig.extension; | ||
isSubscription = firstOperation.type === "subscription"; | ||
if (isSubscription) { | ||
result = subscriptionHandler({ | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
}); | ||
return [2 /*return*/, { | ||
exportedFiles: [result], | ||
}]; | ||
} | ||
fetcherInvocation = asyncFetcherInvocation(operationDataList, options.postHttpMethod === true ? "post" : "get"); | ||
passThroughResults = operationDataList | ||
.filter(function (operationData) { | ||
return ["query", "mutation", "subscription"].includes(operationData.type); | ||
}) | ||
.map(function (operationData) { return operationData.name + "Errors: " + operationData.name + "Errors,\n" + operationData.name + "Data: " + operationData.name + "Data"; }) | ||
.join(",\n"); | ||
clientSideCalls = clientSideInvocations(operationDataList, options.postHttpMethod === true ? "post" : "get", options.useClientAuth); | ||
whitespace = 6; | ||
snippet = imp(netlifyGraphConfig, "NetlifyGraph", "./netlifyGraph") + "\n\n" + exp(netlifyGraphConfig, "handler") + " = async (event) => {\n // By default, all API calls use no authentication\n let accessToken;\n\n //// If you want to use the client's accessToken when making API calls on the user's behalf:\n // accessToken = event.headers[\"authorization\"]?.split(\" \")[1]\n\n //// If you want to use the API with your own access token:\n // accessToken = event.netlifyGraphToken\n \n const eventBodyJson = JSON.parse(event.body || \"{}\");\n\n " + fetcherInvocation + "\n\n return {\n statusCode: 200,\n body: JSON.stringify({\n success: true,\n" + addLeftWhitespace(passThroughResults, whitespace) + "\n }),\n headers: {\n 'content-type': 'application/json',\n },\n };\n};\n\n/** \n * Client-side invocations:\n * Call your Netlify function from the browser (after saving\n * the code to `" + filename + "`) with these helpers:\n */\n\n/**\n" + clientSideCalls + "\n*/\n"; | ||
content = collapseExtraNewlines(snippet); | ||
return [2 /*return*/, { | ||
exportedFiles: [ | ||
{ | ||
kind: "UnnamedExportedFile", | ||
content: content, | ||
language: "javascript", | ||
}, | ||
], | ||
}]; | ||
}); | ||
var firstOperation = operationDataList.find(function (operation) { | ||
return operation.operationDefinition.kind === "OperationDefinition"; | ||
}); | ||
if (!firstOperation) { | ||
return { | ||
exportedFiles: [ | ||
{ | ||
kind: "UnnamedExportedFile", | ||
content: "// No operation found", | ||
language: "javascript", | ||
}, | ||
], | ||
}; | ||
} | ||
var filename = firstOperation.name + "." + netlifyGraphConfig.extension; | ||
var isSubscription = firstOperation.type === "subscription"; | ||
if (isSubscription) { | ||
var result = subscriptionHandler({ | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
}); | ||
return { | ||
exportedFiles: [result], | ||
}; | ||
} | ||
var fetcherInvocation = asyncFetcherInvocation(operationDataList, options.postHttpMethod === true ? "post" : "get"); | ||
var passThroughResults = operationDataList | ||
.filter(function (operationData) { | ||
return ["query", "mutation", "subscription"].includes(operationData.type); | ||
}) | ||
.map(function (operationData) { return operationData.name + "Errors: " + operationData.name + "Errors,\n" + operationData.name + "Data: " + operationData.name + "Data"; }) | ||
.join(",\n"); | ||
var clientSideCalls = clientSideInvocations(operationDataList, options.postHttpMethod === true ? "post" : "get", options.useClientAuth); | ||
var whitespace = 6; | ||
var snippet = imp(netlifyGraphConfig, "NetlifyGraph", "./netlifyGraph") + "\n\n" + exp(netlifyGraphConfig, "handler") + " = async (event) => {\n // By default, all API calls use no authentication\n let accessToken;\n\n //// If you want to use the client's accessToken when making API calls on the user's behalf:\n // accessToken = event.headers[\"authorization\"]?.split(\" \")[1]\n\n //// If you want to use the API with your own access token:\n // accessToken = event.netlifyGraphToken\n \n const eventBodyJson = JSON.parse(event.body || \"{}\");\n\n " + fetcherInvocation + "\n\n return {\n statusCode: 200,\n body: JSON.stringify({\n success: true,\n" + addLeftWhitespace(passThroughResults, whitespace) + "\n }),\n headers: {\n 'content-type': 'application/json',\n },\n };\n};\n\n/** \n * Client-side invocations:\n * Call your Netlify function from the browser (after saving\n * the code to `" + filename + "`) with these helpers:\n */\n\n/**\n" + clientSideCalls + "\n*/\n"; | ||
var content = collapseExtraNewlines(snippet); | ||
return { | ||
exportedFiles: [ | ||
{ | ||
kind: "UnnamedExportedFile", | ||
content: content, | ||
language: "javascript", | ||
}, | ||
], | ||
}; | ||
}, | ||
}); }, | ||
}; | ||
@@ -387,0 +426,0 @@ exports.id = "netlify-builtin:serverless"; |
@@ -13,2 +13,38 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -363,67 +399,70 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
version: "0.0.1", | ||
generateHandler: function (opts) { | ||
var netlifyGraphConfig = opts.netlifyGraphConfig, options = opts.options; | ||
var operationDataList = opts.operationDataList.map(function (operationData, idx) { | ||
if (!isOperationNamed(operationData)) { | ||
return __assign(__assign({}, operationData), { name: ("unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1)).trim(), query: "# Consider giving this " + operationData.type + " a unique, descriptive\n# name in your application as a best practice\n" + operationData.type + " unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1) + " " + operationData.query | ||
.trim() | ||
.replace(/^(query|mutation|subscription) /i, "") }); | ||
generateHandler: function (opts) { return __awaiter(void 0, void 0, void 0, function () { | ||
var netlifyGraphConfig, options, operationDataList, firstOperation, filename, isSubscription, result, fetcherInvocation, passThroughResults, clientSideCalls, whitespace, snippet, page, api; | ||
return __generator(this, function (_a) { | ||
netlifyGraphConfig = opts.netlifyGraphConfig, options = opts.options; | ||
operationDataList = opts.operationDataList.map(function (operationData, idx) { | ||
if (!isOperationNamed(operationData)) { | ||
return __assign(__assign({}, operationData), { name: ("unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1)).trim(), query: "# Consider giving this " + operationData.type + " a unique, descriptive\n# name in your application as a best practice\n" + operationData.type + " unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1) + " " + operationData.query | ||
.trim() | ||
.replace(/^(query|mutation|subscription) /i, "") }); | ||
} | ||
return operationData; | ||
}); | ||
firstOperation = operationDataList.find(function (operation) { | ||
return operation.operationDefinition.kind === "OperationDefinition"; | ||
}); | ||
if (!firstOperation) { | ||
return [2 /*return*/, { | ||
exportedFiles: [ | ||
{ | ||
kind: "UnnamedExportedFile", | ||
content: "// No operation found", | ||
language: "javascript", | ||
}, | ||
], | ||
}]; | ||
} | ||
return operationData; | ||
}); | ||
var firstOperation = operationDataList.find(function (operation) { | ||
return operation.operationDefinition.kind === "OperationDefinition"; | ||
}); | ||
if (!firstOperation) { | ||
return { | ||
exportedFiles: [ | ||
{ | ||
kind: "UnnamedExportedFile", | ||
content: "// No operation found", | ||
language: "javascript", | ||
}, | ||
], | ||
}; | ||
} | ||
var filename = firstOperation.name + "." + netlifyGraphConfig.extension; | ||
var isSubscription = firstOperation.type === "subscription"; | ||
if (isSubscription) { | ||
var result = subscriptionHandler({ | ||
filename = firstOperation.name + "." + netlifyGraphConfig.extension; | ||
isSubscription = firstOperation.type === "subscription"; | ||
if (isSubscription) { | ||
result = subscriptionHandler({ | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
}); | ||
return [2 /*return*/, { | ||
language: netlifyGraphConfig.language, | ||
exportedFiles: [result], | ||
}]; | ||
} | ||
fetcherInvocation = asyncFetcherInvocation(opts.GraphQL, operationDataList, options.postHttpMethod === true ? "post" : "get"); | ||
passThroughResults = operationDataList.length === 1 | ||
? "errors, data" | ||
: operationDataList | ||
.filter(function (operationData) { | ||
return ["query", "mutation", "subscription"].includes(operationData.type); | ||
}) | ||
.map(function (_operationData) { return "errors,\ndata"; }) | ||
.join(",\n"); | ||
clientSideCalls = clientSideInvocations(operationDataList, options.postHttpMethod === true ? "post" : "get", options.useClientAuth); | ||
whitespace = 4; | ||
snippet = ts(netlifyGraphConfig, 'import type { NextApiRequest, NextApiResponse } from "next";') + "\n" + imp(netlifyGraphConfig, "NetlifyGraph", netlifyGraphConfig.netlifyGraphRequirePath) + ";\n\n" + exp(netlifyGraphConfig, "handler") + " = async (req" + ts(netlifyGraphConfig, ": NextApiRequest") + ", res" + ts(netlifyGraphConfig, ": NextApiResponse") + ") => {\n // By default, all API calls use no authentication\n let accessToken = null;\n\n //// If you want to use the client's accessToken when making API calls on the user's behalf:\n // accessToken = req.headers[\"authorization\"]?.split(\" \")[1];\n\n //// If you want to use the API with your own access token:\n // accessToken = process.env.NETLIFY_GRAPH_TOKEN;\n \n const eventBodyJson = req.body || {};\n\n " + fetcherInvocation + "\n\n res.setHeader(\"Content-Type\", \"application/json\");\n\n return res.status(200).json({\n" + addLeftWhitespace(passThroughResults, whitespace) + "\n });\n};\n\n" + expDefault(netlifyGraphConfig, "handler") + ";\n\n/** \n * Client-side invocations:\n * Call your Netlify function from the browser with this helper:\n */\n\n/**\n" + clientSideCalls + "\n*/"; | ||
page = generatePage({ | ||
GraphQL: opts.GraphQL, | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
schema: opts.schema, | ||
route: "/api/" + firstOperation.displayName, | ||
}); | ||
return { | ||
api = { | ||
kind: "UnnamedExportedFile", | ||
content: collapseExtraNewlines(snippet), | ||
language: netlifyGraphConfig.language, | ||
exportedFiles: [result], | ||
}; | ||
} | ||
var fetcherInvocation = asyncFetcherInvocation(opts.GraphQL, operationDataList, options.postHttpMethod === true ? "post" : "get"); | ||
var passThroughResults = operationDataList.length === 1 | ||
? "errors, data" | ||
: operationDataList | ||
.filter(function (operationData) { | ||
return ["query", "mutation", "subscription"].includes(operationData.type); | ||
}) | ||
.map(function (_operationData) { return "errors,\ndata"; }) | ||
.join(",\n"); | ||
var clientSideCalls = clientSideInvocations(operationDataList, options.postHttpMethod === true ? "post" : "get", options.useClientAuth); | ||
var whitespace = 4; | ||
var snippet = ts(netlifyGraphConfig, 'import type { NextApiRequest, NextApiResponse } from "next";') + "\n" + imp(netlifyGraphConfig, "NetlifyGraph", netlifyGraphConfig.netlifyGraphRequirePath) + ";\n\n" + exp(netlifyGraphConfig, "handler") + " = async (req" + ts(netlifyGraphConfig, ": NextApiRequest") + ", res" + ts(netlifyGraphConfig, ": NextApiResponse") + ") => {\n // By default, all API calls use no authentication\n let accessToken = null;\n\n //// If you want to use the client's accessToken when making API calls on the user's behalf:\n // accessToken = req.headers[\"authorization\"]?.split(\" \")[1];\n\n //// If you want to use the API with your own access token:\n // accessToken = process.env.NETLIFY_GRAPH_TOKEN;\n \n const eventBodyJson = req.body || {};\n\n " + fetcherInvocation + "\n\n res.setHeader(\"Content-Type\", \"application/json\");\n\n return res.status(200).json({\n" + addLeftWhitespace(passThroughResults, whitespace) + "\n });\n};\n\n" + expDefault(netlifyGraphConfig, "handler") + ";\n\n/** \n * Client-side invocations:\n * Call your Netlify function from the browser with this helper:\n */\n\n/**\n" + clientSideCalls + "\n*/"; | ||
var page = generatePage({ | ||
GraphQL: opts.GraphQL, | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
schema: opts.schema, | ||
route: "/api/" + firstOperation.displayName, | ||
return [2 /*return*/, { | ||
language: "javascript", | ||
exportedFiles: [api, page], | ||
}]; | ||
}); | ||
var api = { | ||
kind: "UnnamedExportedFile", | ||
content: collapseExtraNewlines(snippet), | ||
language: netlifyGraphConfig.language, | ||
}; | ||
return { | ||
language: "javascript", | ||
exportedFiles: [api, page], | ||
}; | ||
}, | ||
}); }, | ||
}; | ||
@@ -430,0 +469,0 @@ exports.id = "netlify-builtin:nextjs"; |
@@ -13,2 +13,38 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -390,60 +426,63 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
version: "0.0.1", | ||
generateHandler: function (opts) { | ||
var netlifyGraphConfig = opts.netlifyGraphConfig, options = opts.options; | ||
var operationDataList = opts.operationDataList.map(function (operationData, idx) { | ||
if (!isOperationNamed(operationData)) { | ||
return __assign(__assign({}, operationData), { name: ("unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1)).trim(), query: "# Consider giving this " + operationData.type + " a unique, descriptive\n# name in your application as a best practice\n" + operationData.type + " unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1) + " " + operationData.query | ||
.trim() | ||
.replace(/^(query|mutation|subscription) /i, "") }); | ||
generateHandler: function (opts) { return __awaiter(void 0, void 0, void 0, function () { | ||
var netlifyGraphConfig, options, operationDataList, firstOperation, filename, isSubscription, result, passThroughResults, clientSideCalls, whitespace, snippet, route; | ||
return __generator(this, function (_a) { | ||
netlifyGraphConfig = opts.netlifyGraphConfig, options = opts.options; | ||
operationDataList = opts.operationDataList.map(function (operationData, idx) { | ||
if (!isOperationNamed(operationData)) { | ||
return __assign(__assign({}, operationData), { name: ("unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1)).trim(), query: "# Consider giving this " + operationData.type + " a unique, descriptive\n# name in your application as a best practice\n" + operationData.type + " unnamed" + capitalizeFirstLetter(operationData.type) + (idx + 1) + " " + operationData.query | ||
.trim() | ||
.replace(/^(query|mutation|subscription) /i, "") }); | ||
} | ||
return operationData; | ||
}); | ||
firstOperation = operationDataList.find(function (operation) { | ||
return operation.operationDefinition.kind === "OperationDefinition"; | ||
}); | ||
if (!firstOperation) { | ||
return [2 /*return*/, { | ||
exportedFiles: [ | ||
{ | ||
kind: "UnnamedExportedFile", | ||
content: "// No operation found", | ||
language: "javascript", | ||
}, | ||
], | ||
}]; | ||
} | ||
return operationData; | ||
}); | ||
var firstOperation = operationDataList.find(function (operation) { | ||
return operation.operationDefinition.kind === "OperationDefinition"; | ||
}); | ||
if (!firstOperation) { | ||
return { | ||
exportedFiles: [ | ||
{ | ||
kind: "UnnamedExportedFile", | ||
content: "// No operation found", | ||
language: "javascript", | ||
}, | ||
], | ||
}; | ||
} | ||
var filename = firstOperation.name + "." + netlifyGraphConfig.extension; | ||
var isSubscription = firstOperation.type === "subscription"; | ||
if (isSubscription) { | ||
var result = subscriptionHandler({ | ||
filename = firstOperation.name + "." + netlifyGraphConfig.extension; | ||
isSubscription = firstOperation.type === "subscription"; | ||
if (isSubscription) { | ||
result = subscriptionHandler({ | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
}); | ||
return [2 /*return*/, { | ||
exportedFiles: [result], | ||
}]; | ||
} | ||
passThroughResults = operationDataList.length === 1 | ||
? "errors, data" | ||
: operationDataList | ||
.filter(function (operationData) { | ||
return ["query", "mutation", "subscription"].includes(operationData.type); | ||
}) | ||
.map(function (_operationData) { return "errors,\ndata"; }) | ||
.join(",\n"); | ||
clientSideCalls = clientSideInvocations(operationDataList, options.postHttpMethod === true ? "post" : "get", options.useClientAuth); | ||
whitespace = 4; | ||
snippet = ts(netlifyGraphConfig, 'import type { NextApiRequest, NextApiResponse } from "next";') + "\n" + imp(netlifyGraphConfig, "NetlifyGraph", netlifyGraphConfig.netlifyGraphRequirePath) + ";\n\n/**\n * Client-side invocations:\n * Call your Netlify function from the browser with this helper:\n */\n\n/**\n" + clientSideCalls + "\n*/"; | ||
route = generateRoute({ | ||
GraphQL: opts.GraphQL, | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
schema: opts.schema, | ||
route: "/" + firstOperation.displayName, | ||
}); | ||
return { | ||
exportedFiles: [result], | ||
}; | ||
} | ||
var passThroughResults = operationDataList.length === 1 | ||
? "errors, data" | ||
: operationDataList | ||
.filter(function (operationData) { | ||
return ["query", "mutation", "subscription"].includes(operationData.type); | ||
}) | ||
.map(function (_operationData) { return "errors,\ndata"; }) | ||
.join(",\n"); | ||
var clientSideCalls = clientSideInvocations(operationDataList, options.postHttpMethod === true ? "post" : "get", options.useClientAuth); | ||
var whitespace = 4; | ||
var snippet = ts(netlifyGraphConfig, 'import type { NextApiRequest, NextApiResponse } from "next";') + "\n" + imp(netlifyGraphConfig, "NetlifyGraph", netlifyGraphConfig.netlifyGraphRequirePath) + ";\n\n/**\n * Client-side invocations:\n * Call your Netlify function from the browser with this helper:\n */\n\n/**\n" + clientSideCalls + "\n*/"; | ||
var route = generateRoute({ | ||
GraphQL: opts.GraphQL, | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
schema: opts.schema, | ||
route: "/" + firstOperation.displayName, | ||
return [2 /*return*/, { | ||
language: "javascript", | ||
exportedFiles: [route], | ||
}]; | ||
}); | ||
return { | ||
language: "javascript", | ||
exportedFiles: [route], | ||
}; | ||
}, | ||
}); }, | ||
}; | ||
@@ -450,0 +489,0 @@ exports.id = "netlify-builtin:remix"; |
@@ -148,6 +148,6 @@ import { DocumentNode, FragmentDefinitionNode, GraphQLSchema, OperationDefinitionNode, OperationTypeNode } from "graphql"; | ||
schema: GraphQLSchema; | ||
}) => { | ||
}) => Promise<{ | ||
exportedFiles: ExportedFile[]; | ||
operation: OperationDefinitionNode; | ||
} | undefined; | ||
} | undefined>; | ||
/** | ||
@@ -164,6 +164,6 @@ * Given a schema, GraphQL operations doc, a target operationId, and a Netlify Graph config, generates a set of handlers (and potentially components) for the correct framework. | ||
generate: Codegen["generateHandler"]; | ||
}) => { | ||
}) => Promise<{ | ||
exportedFiles: ExportedFile[]; | ||
operation: OperationDefinitionNode; | ||
} | undefined; | ||
} | undefined>; | ||
/** | ||
@@ -170,0 +170,0 @@ * Given a schema, GraphQL operations doc, a target operationId, and a Netlify Graph config, generates a preview of the full handler's output |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,58 +45,67 @@ var fs_1 = require("fs"); | ||
var internalConsole_1 = require("./internalConsole"); | ||
var test = function () { | ||
(0, internalConsole_1.registerConsole)(console); | ||
var sourceGraphQLFilename = "./tests/assets/netlifyGraphOperationsLibrary.graphql"; | ||
var schemaGraphQLFilename = "./tests/assets/netlifyGraphSchema.graphql"; | ||
var sourceGraphQLFile = (0, fs_1.readFileSync)(sourceGraphQLFilename, "utf8"); | ||
var schemaGraphQLFile = (0, fs_1.readFileSync)(schemaGraphQLFilename, "utf8"); | ||
var schema = (0, graphql_1.buildASTSchema)((0, graphql_1.parse)(schemaGraphQLFile)); | ||
var parsedDoc = (0, graphql_1.parse)(sourceGraphQLFile); | ||
var functions = index_1.NetlifyGraph.extractFunctionsFromOperationDoc(GraphQL, parsedDoc); | ||
console.log("functions:", functions); | ||
var netlifyGraphConfig = { | ||
netlifyGraphPath: ["..", "..", "lib", "netlifyGraph"], | ||
graphQLConfigJsonFilename: [".graphqlrc.json"], | ||
framework: "custom", | ||
webhookBasePath: "/api", | ||
functionsPath: [], | ||
graphQLOperationsSourceDirectory: ["..", "..", "lib", "netlifyGraph"], | ||
graphQLSchemaFilename: [ | ||
"..", | ||
"..", | ||
"lib", | ||
"netlifyGraph", | ||
"netlifyGraphSchema.graphql", | ||
], | ||
netlifyGraphImplementationFilename: ["..", "..", "lib", "index.js"], | ||
netlifyGraphTypeDefinitionsFilename: ["..", "..", "lib", "index.d.ts"], | ||
netlifyGraphRequirePath: ["..", "..", "lib", "netlifyGraph"], | ||
extension: "ts", | ||
moduleType: "esm", | ||
language: "typescript", | ||
runtimeTargetEnv: "node", | ||
}; | ||
var result = index_1.NetlifyGraph.generateHandlerSource({ | ||
GraphQL: GraphQL, | ||
handlerOptions: { | ||
postHttpMethod: true, | ||
useClientAuth: true, | ||
}, | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationId: "5c7bb879-a810-4a7e-8aec-55d05fd9c172", | ||
operationsDoc: sourceGraphQLFile, | ||
schema: schema, | ||
var test = function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var sourceGraphQLFilename, schemaGraphQLFilename, sourceGraphQLFile, schemaGraphQLFile, schema, parsedDoc, functions, netlifyGraphConfig, result, exportedFiles; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
(0, internalConsole_1.registerConsole)(console); | ||
sourceGraphQLFilename = "./tests/assets/netlifyGraphOperationsLibrary.graphql"; | ||
schemaGraphQLFilename = "./tests/assets/netlifyGraphSchema.graphql"; | ||
sourceGraphQLFile = (0, fs_1.readFileSync)(sourceGraphQLFilename, "utf8"); | ||
schemaGraphQLFile = (0, fs_1.readFileSync)(schemaGraphQLFilename, "utf8"); | ||
schema = (0, graphql_1.buildASTSchema)((0, graphql_1.parse)(schemaGraphQLFile)); | ||
parsedDoc = (0, graphql_1.parse)(sourceGraphQLFile); | ||
functions = index_1.NetlifyGraph.extractFunctionsFromOperationDoc(GraphQL, parsedDoc); | ||
console.log("functions:", functions); | ||
netlifyGraphConfig = { | ||
netlifyGraphPath: ["..", "..", "lib", "netlifyGraph"], | ||
graphQLConfigJsonFilename: [".graphqlrc.json"], | ||
framework: "custom", | ||
webhookBasePath: "/api", | ||
functionsPath: [], | ||
graphQLOperationsSourceDirectory: ["..", "..", "lib", "netlifyGraph"], | ||
graphQLSchemaFilename: [ | ||
"..", | ||
"..", | ||
"lib", | ||
"netlifyGraph", | ||
"netlifyGraphSchema.graphql", | ||
], | ||
netlifyGraphImplementationFilename: ["..", "..", "lib", "index.js"], | ||
netlifyGraphTypeDefinitionsFilename: ["..", "..", "lib", "index.d.ts"], | ||
netlifyGraphRequirePath: ["..", "..", "lib", "netlifyGraph"], | ||
extension: "ts", | ||
moduleType: "esm", | ||
language: "typescript", | ||
runtimeTargetEnv: "node", | ||
}; | ||
return [4 /*yield*/, index_1.NetlifyGraph.generateHandlerSource({ | ||
GraphQL: GraphQL, | ||
handlerOptions: { | ||
postHttpMethod: true, | ||
useClientAuth: true, | ||
}, | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationId: "5c7bb879-a810-4a7e-8aec-55d05fd9c172", | ||
operationsDoc: sourceGraphQLFile, | ||
schema: schema, | ||
})]; | ||
case 1: | ||
result = _a.sent(); | ||
if (!result) { | ||
throw new Error("result is undefined"); | ||
} | ||
exportedFiles = result.exportedFiles; | ||
exportedFiles === null || exportedFiles === void 0 ? void 0 : exportedFiles.forEach(function (exportedFile) { | ||
var filename = exportedFile.kind === "NamedExportedFile" | ||
? path.join.apply(path, exportedFile.name) : "default"; | ||
var contentPath = "/tmp/" + filename + ".ts"; | ||
console.log(contentPath + ":\n", exportedFile.content); | ||
(0, fs_1.writeFileSync)(contentPath, exportedFile.content); | ||
}); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
if (!result) { | ||
throw new Error("result is undefined"); | ||
} | ||
var exportedFiles = result.exportedFiles; | ||
exportedFiles === null || exportedFiles === void 0 ? void 0 : exportedFiles.forEach(function (exportedFile) { | ||
var filename = exportedFile.kind === "NamedExportedFile" | ||
? path.join.apply(path, exportedFile.name) : "default"; | ||
var contentPath = "/tmp/" + filename + ".ts"; | ||
console.log(contentPath + ":\n", exportedFile.content); | ||
(0, fs_1.writeFileSync)(contentPath, exportedFile.content); | ||
}); | ||
}; | ||
}); }; | ||
test(); | ||
//# sourceMappingURL=sanity.test.js.map |
{ | ||
"name": "netlify-onegraph-internal", | ||
"version": "0.8.7", | ||
"version": "0.9.0", | ||
"description": "Internal tools for use by Netlify", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
617913
7964