Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graph): fix siteId codegen issues #5056

Merged
merged 2 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"multiparty": "^4.2.1",
"netlify": "^12.0.1",
"netlify-headers-parser": "^6.0.2",
"netlify-onegraph-internal": "0.10.0",
"netlify-onegraph-internal": "0.10.1",
"netlify-redirect-parser": "^13.0.5",
"netlify-redirector": "^0.3.1",
"node-fetch": "^2.6.0",
Expand Down
105 changes: 42 additions & 63 deletions tests/integration/snapshots/530.graph-codegen.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@ The actual snapshot is saved in `530.graph-codegen.test.js.snap`.

Generated by [AVA](https://avajs.dev).

## netlify graph handler codegen [netlify-graph-codegen/next-js-0.0.1]:/TestSubscription.js

> Snapshot 1

'"import NetlifyGraph from /"./netlifyGraph/";/n/nexport const handler = async (req, res) => {/n const reqBody = await extractBody(req);/n/n const payload = NetlifyGraph.parseAndVerifyTestSubscriptionEvent({/n headers: {/n /"x-netlify-graph-signature/": req.headers[/n /"x-netlify-graph-signature/"/n ]/n },/n body: reqBody,/n });/n/n if (!payload) {/n return res.status(422).json({/n success: false,/n error: \'Unable to verify payload signature\',/n });/n }/n/n const { errors, data } = payload;/n/n if (errors) {/n console.error(errors);/n }/n/n console.log(data);/n/n res.setHeader(/"Content-Type/", /"application/json/");/n/n /**/n * If you want to unsubscribe from this webhook/n * in order to stop receiving new events,/n * simply return status 410, e.g.:/n * /n * return res.status(410).json({});/n *//n/n return res.status(200).json({/n successfullyProcessedIncomingWebhook: true,/n });/n};/n/nexport default handler;/n/nexport const config = {/n api: {/n // We manually parse the body of the request in order to verify/n // that it\'s signed by Netlify before processing the event./n bodyParser: false,/n },/n};/n/nconst extractBody = (req) => {/n let body = [];/n const promise = new Promise((resolve, reject) => {/n req/n .on(/"data/", (chunk) => {/n body.push(chunk);/n })/n .on(/"end/", () => {/n const fullBody = Buffer.concat(body).toString();/n resolve(fullBody);/n });/n });/n/n return promise;/n};/n"'

## netlify graph handler codegen [netlify-graph-codegen/remix-0.0.1]:/app/routes/webhooks/TestSubscription.js

> Snapshot 1

'"import { json } from /"remix/";/nimport NetlifyGraph from /"../.,netlifyGraph/";/n/nexport const action = async ({ context, request }) => {/n const reqBody = await request.text();/n/n const payload = NetlifyGraph.parseAndVerifyTestSubscriptionEvent({/n body: reqBody,/n headers: {/n \'x-netlify-graph-signature\': context.netlifyGraphSignature/n },/n });/n/n if (!payload) {/n return json({/n success: false,/n error: \'Unable to verify payload signature\',/n }, { status: 422 });/n }/n/n const { errors, data } = payload;/n/n if (errors) {/n console.error(errors);/n }/n/n console.log(data);/n/n /**/n * If you want to unsubscribe from this webhook/n * in order to stop receiving new events,/n * simply return status 410, e.g.:/n */n * return json({}, { status: 410 });/n *//n/n return json({/n successfullyProcessedIncomingWebhook: true,/n });/n};/n"'

## netlify graph handler codegen [netlify-graph-codegen/serverless-0.0.1]:/TestSubscription.js

> Snapshot 1

'"import NetlifyGraph from /".,netlifyGraph/"/n/nexport const handler = async (event, context) => {/n const payload = NetlifyGraph.parseAndVerifyTestSubscriptionEvent(event);/n/n if (!payload) {/n return {/n statusCode: 412,/n data: JSON.stringify({/n success: false,/n error: \'Unable to verify payload signature\',/n }),/n };/n }/n const { errors: TestSubscriptionErrors, data: TestSubscriptionData } = payload;/n/n if (TestSubscriptionErrors) {/n console.error(TestSubscriptionErrors);/n }/n/n console.log(TestSubscriptionData);/n/n /**/n * If you want to unsubscribe from this webhook/n * in order to stop receiving new events,/n * simply return status 410, e.g.:/n */n * return {/n * statusCode: 410,/n * body: JSON.stringify(null),/n * headers: {/n * \'content-type\': \'application/json\',/n * },/n * }/n *//n/n return {/n statusCode: 200,/n body: JSON.stringify({/n successfullyProcessedIncomingWebhook: true,/n }),/n headers: {/n \'content-type\': \'application/json\',/n },/n };/n};/n"'

## netlify graph function library runtime codegen library [netlify-builtin:nextjs-0.0.1]:./dummy/index.js}

> Snapshot 1
Expand Down Expand Up @@ -72,15 +54,13 @@ Generated by [AVA](https://avajs.dev).
const calculateCacheKey = (payload) => {␊
return JSON.stringify(payload);␊
};␊
␊
␊
const schemaId = 'stable-schema-id';␊
␊
␊
const netlifyGraphHostWithProtocol =␊
process.env.NETLIFY_GRAPH_HOST_WITH_PROTOCOL || 'https://graph.netlify.com';␊
␊
const siteId = process.env.SITE_ID;␊
␊
const makeNetlifyGraphUrl = ({ operationName }) => {␊
␊
const makeNetlifyGraphUrl = ({ operationName, siteId }) => {␊
return (␊
netlifyGraphHostWithProtocol +␊
'/graphql?app_id=' +␊
Expand All @@ -91,26 +71,27 @@ Generated by [AVA](https://avajs.dev).
schemaId␊
);␊
};␊
␊
␊
const httpFetch = (operationName, options) => {␊
const reqBody = options.body || null;␊
const userHeaders = options.headers || {};␊
const headers = {␊
...userHeaders,␊
'Content-Type': 'application/json',␊
};␊
␊
␊
const timeoutMs = 30_000;␊
␊
␊
const reqOptions = {␊
method: 'POST',␊
headers: headers,␊
timeout: timeoutMs,␊
body: reqBody,␊
};␊
␊
const netlifyGraphUrl = makeNetlifyGraphUrl({ operationName: operationName });␊
␊
␊
const siteId = options.siteId || process.env.SITE_ID;␊
const netlifyGraphUrl = makeNetlifyGraphUrl({ operationName: operationName, siteId: siteId });␊
␊
return fetch(netlifyGraphUrl, reqOptions).then((body) => {␊
return body.text().then((bodyString) => {␊
const headers = {};␊
Expand All @@ -124,7 +105,7 @@ Generated by [AVA](https://avajs.dev).
});␊
});␊
};␊
␊
␊
const fetchNetlifyGraph = function fetchNetlifyGraph(input) {␊
const query = input.query;␊
const docId = input.doc_id;␊
Expand All @@ -133,7 +114,6 @@ Generated by [AVA](https://avajs.dev).
␊
const options = input.options || {};␊
const accessToken = options.accessToken;␊
const siteId = options.siteId || process.env.SITE_ID;␊
␊
const payload = {␊
query: query,␊
Expand Down Expand Up @@ -162,6 +142,7 @@ Generated by [AVA](https://avajs.dev).
}␊
␊
const response = httpFetch(operationName, {␊
...options,␊
method: 'POST',␊
headers: {␊
...conditionalHeaders,␊
Expand Down Expand Up @@ -194,7 +175,7 @@ Generated by [AVA](https://avajs.dev).
␊
return cachedOrLiveValue;␊
};␊
␊
␊
export const executeUpdateCLISessionMetadataMutation = (␊
variables,␊
options␊
Expand Down Expand Up @@ -2492,15 +2473,13 @@ Generated by [AVA](https://avajs.dev).
const calculateCacheKey = (payload) => {␊
return JSON.stringify(payload);␊
};␊
␊
␊
const schemaId = 'stable-schema-id';␊
␊
␊
const netlifyGraphHostWithProtocol =␊
process.env.NETLIFY_GRAPH_HOST_WITH_PROTOCOL || 'https://graph.netlify.com';␊
␊
const siteId = process.env.SITE_ID;␊
␊
const makeNetlifyGraphUrl = ({ operationName }) => {␊
␊
const makeNetlifyGraphUrl = ({ operationName, siteId }) => {␊
return (␊
netlifyGraphHostWithProtocol +␊
'/graphql?app_id=' +␊
Expand All @@ -2511,26 +2490,27 @@ Generated by [AVA](https://avajs.dev).
schemaId␊
);␊
};␊
␊
␊
const httpFetch = (operationName, options) => {␊
const reqBody = options.body || null;␊
const userHeaders = options.headers || {};␊
const headers = {␊
...userHeaders,␊
'Content-Type': 'application/json',␊
};␊
␊
␊
const timeoutMs = 30_000;␊
␊
␊
const reqOptions = {␊
method: 'POST',␊
headers: headers,␊
timeout: timeoutMs,␊
body: reqBody,␊
};␊
␊
const netlifyGraphUrl = makeNetlifyGraphUrl({ operationName: operationName });␊
␊
␊
const siteId = options.siteId || process.env.SITE_ID;␊
const netlifyGraphUrl = makeNetlifyGraphUrl({ operationName: operationName, siteId: siteId });␊
␊
return fetch(netlifyGraphUrl, reqOptions).then((body) => {␊
return body.text().then((bodyString) => {␊
const headers = {};␊
Expand All @@ -2544,7 +2524,7 @@ Generated by [AVA](https://avajs.dev).
});␊
});␊
};␊
␊
␊
const fetchNetlifyGraph = function fetchNetlifyGraph(input) {␊
const query = input.query;␊
const docId = input.doc_id;␊
Expand All @@ -2553,7 +2533,6 @@ Generated by [AVA](https://avajs.dev).
␊
const options = input.options || {};␊
const accessToken = options.accessToken;␊
const siteId = options.siteId || process.env.SITE_ID;␊
␊
const payload = {␊
query: query,␊
Expand Down Expand Up @@ -2582,6 +2561,7 @@ Generated by [AVA](https://avajs.dev).
}␊
␊
const response = httpFetch(operationName, {␊
...options,␊
method: 'POST',␊
headers: {␊
...conditionalHeaders,␊
Expand Down Expand Up @@ -2614,7 +2594,7 @@ Generated by [AVA](https://avajs.dev).
␊
return cachedOrLiveValue;␊
};␊
␊
␊
export const executeUpdateCLISessionMetadataMutation = (␊
variables,␊
options␊
Expand Down Expand Up @@ -4912,15 +4892,13 @@ Generated by [AVA](https://avajs.dev).
const calculateCacheKey = (payload) => {␊
return JSON.stringify(payload);␊
};␊
␊
␊
const schemaId = 'stable-schema-id';␊
␊
␊
const netlifyGraphHostWithProtocol =␊
process.env.NETLIFY_GRAPH_HOST_WITH_PROTOCOL || 'https://graph.netlify.com';␊
␊
const siteId = process.env.SITE_ID;␊
␊
const makeNetlifyGraphUrl = ({ operationName }) => {␊
␊
const makeNetlifyGraphUrl = ({ operationName, siteId }) => {␊
return (␊
netlifyGraphHostWithProtocol +␊
'/graphql?app_id=' +␊
Expand All @@ -4931,26 +4909,27 @@ Generated by [AVA](https://avajs.dev).
schemaId␊
);␊
};␊
␊
␊
const httpFetch = (operationName, options) => {␊
const reqBody = options.body || null;␊
const userHeaders = options.headers || {};␊
const headers = {␊
...userHeaders,␊
'Content-Type': 'application/json',␊
};␊
␊
␊
const timeoutMs = 30_000;␊
␊
␊
const reqOptions = {␊
method: 'POST',␊
headers: headers,␊
timeout: timeoutMs,␊
body: reqBody,␊
};␊
␊
const netlifyGraphUrl = makeNetlifyGraphUrl({ operationName: operationName });␊
␊
␊
const siteId = options.siteId || process.env.SITE_ID;␊
const netlifyGraphUrl = makeNetlifyGraphUrl({ operationName: operationName, siteId: siteId });␊
␊
return fetch(netlifyGraphUrl, reqOptions).then((body) => {␊
return body.text().then((bodyString) => {␊
const headers = {};␊
Expand All @@ -4964,7 +4943,7 @@ Generated by [AVA](https://avajs.dev).
});␊
});␊
};␊
␊
␊
const fetchNetlifyGraph = function fetchNetlifyGraph(input) {␊
const query = input.query;␊
const docId = input.doc_id;␊
Expand All @@ -4973,7 +4952,6 @@ Generated by [AVA](https://avajs.dev).
␊
const options = input.options || {};␊
const accessToken = options.accessToken;␊
const siteId = options.siteId || process.env.SITE_ID;␊
␊
const payload = {␊
query: query,␊
Expand Down Expand Up @@ -5002,6 +4980,7 @@ Generated by [AVA](https://avajs.dev).
}␊
␊
const response = httpFetch(operationName, {␊
...options,␊
method: 'POST',␊
headers: {␊
...conditionalHeaders,␊
Expand Down Expand Up @@ -5034,7 +5013,7 @@ Generated by [AVA](https://avajs.dev).
␊
return cachedOrLiveValue;␊
};␊
␊
␊
export const executeUpdateCLISessionMetadataMutation = (␊
variables,␊
options␊
Expand Down
Binary file modified tests/integration/snapshots/530.graph-codegen.test.js.snap
Binary file not shown.