From df960efb4e9f3100cf47be85dfb42e4f821f3b3f Mon Sep 17 00:00:00 2001 From: mstoyanovv <51913821+mstoyanovv@users.noreply.github.com> Date: Mon, 4 Jul 2022 12:12:45 +0300 Subject: [PATCH 1/7] Fix "Must provide Source" error Without Content Type header local mock is failing with "Must Provice Source" --- src/fragments/lib/graphqlapi/graphql-from-node.mdx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fragments/lib/graphqlapi/graphql-from-node.mdx b/src/fragments/lib/graphqlapi/graphql-from-node.mdx index b2168a8ed44..d2bbdb926cb 100644 --- a/src/fragments/lib/graphqlapi/graphql-from-node.mdx +++ b/src/fragments/lib/graphqlapi/graphql-from-node.mdx @@ -90,7 +90,8 @@ export const handler = async (event) => { const options = { method: 'POST', headers: { - 'x-api-key': GRAPHQL_API_KEY + 'x-api-key': GRAPHQL_API_KEY, + 'Content-Type': 'application/json' }, body: JSON.stringify({ query, variables }) }; @@ -162,7 +163,8 @@ export const handler = async (event) => { const options = { method: 'POST', headers: { - 'x-api-key': GRAPHQL_API_KEY + 'x-api-key': GRAPHQL_API_KEY, + 'Content-Type': 'application/json' }, body: JSON.stringify({ query, variables }) }; @@ -276,7 +278,8 @@ export const handler = async (event) => { const requestToBeSigned = new HttpRequest({ method: 'POST', headers: { - host: endpoint.host + host: endpoint.host, + 'Content-Type': 'application/json' }, hostname: endpoint.host, body: JSON.stringify({ query }), From 485a87e35b90cd689671f11941e94b329b3e8ff9 Mon Sep 17 00:00:00 2001 From: mstoyanovv <51913821+mstoyanovv@users.noreply.github.com> Date: Mon, 4 Jul 2022 12:14:00 +0300 Subject: [PATCH 2/7] Amplify mock commonjs note Added a note stating that the proposed functions written in ES module syntax are not supported by amplify mock. Removed wrongly referenced 'variables' in one of the examples. --- src/fragments/lib/graphqlapi/graphql-from-node.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fragments/lib/graphqlapi/graphql-from-node.mdx b/src/fragments/lib/graphqlapi/graphql-from-node.mdx index d2bbdb926cb..f38d38f60be 100644 --- a/src/fragments/lib/graphqlapi/graphql-from-node.mdx +++ b/src/fragments/lib/graphqlapi/graphql-from-node.mdx @@ -56,6 +56,7 @@ The examples on this page use [`node-fetch`](https://www.npmjs.com/package/node- } } ``` +NOTE: The examples bellow are using ES module syntax and currently not supported by amplify mock function. If you wish to use amplify mock please use commonjs syntax. ## Query @@ -93,7 +94,7 @@ export const handler = async (event) => { 'x-api-key': GRAPHQL_API_KEY, 'Content-Type': 'application/json' }, - body: JSON.stringify({ query, variables }) + body: JSON.stringify({ query }) }; const request = new Request(GRAPHQL_ENDPOINT, options); From 514bde6543d46385e201d0894a8675013c460845 Mon Sep 17 00:00:00 2001 From: mstoyanovv <51913821+mstoyanovv@users.noreply.github.com> Date: Tue, 12 Jul 2022 10:04:52 +0300 Subject: [PATCH 3/7] Added callout to use node-fetch v2 for cjs --- src/fragments/lib/graphqlapi/graphql-from-node.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fragments/lib/graphqlapi/graphql-from-node.mdx b/src/fragments/lib/graphqlapi/graphql-from-node.mdx index f38d38f60be..263473b869b 100644 --- a/src/fragments/lib/graphqlapi/graphql-from-node.mdx +++ b/src/fragments/lib/graphqlapi/graphql-from-node.mdx @@ -38,7 +38,7 @@ You can access the following resource attributes as environment variables from y REGION ``` -The examples on this page use [`node-fetch`](https://www.npmjs.com/package/node-fetch) to make a HTTP request to our GraphQL API. When the Node.js v18 runtime is released for Lambda this dependency can be removed in favor of [native `fetch`](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch) To get started, add the `node-fetch` module as a dependency: +The examples on this page use [`node-fetch`](https://www.npmjs.com/package/node-fetch) to make a HTTP request to our GraphQL API. When the Node.js v18 runtime is released for Lambda this dependency can be removed in favor of [native `fetch`](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch). To get started, add the `node-fetch` module as a dependency: ```diff { @@ -56,7 +56,7 @@ The examples on this page use [`node-fetch`](https://www.npmjs.com/package/node- } } ``` -NOTE: The examples bellow are using ES module syntax and currently not supported by amplify mock function. If you wish to use amplify mock please use commonjs syntax. +NOTE: The examples bellow are using ES module syntax and currently not supported by amplify mock function. If you wish to use amplify mock please use commonjs syntax with node-fetch v2. ## Query From 19581d7abecf62c89f50fbb1a5a0f9c718457d6a Mon Sep 17 00:00:00 2001 From: mstoyanovv Date: Tue, 15 Nov 2022 11:14:06 +0200 Subject: [PATCH 4/7] reverse order of http headers in last example --- src/fragments/lib/graphqlapi/graphql-from-node.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib/graphqlapi/graphql-from-node.mdx b/src/fragments/lib/graphqlapi/graphql-from-node.mdx index ad4da38aac7..0ef17dbb01a 100644 --- a/src/fragments/lib/graphqlapi/graphql-from-node.mdx +++ b/src/fragments/lib/graphqlapi/graphql-from-node.mdx @@ -301,8 +301,8 @@ export const handler = async (event) => { const requestToBeSigned = new HttpRequest({ method: 'POST', headers: { - host: endpoint.host, 'Content-Type': 'application/json' + host: endpoint.host, }, hostname: endpoint.host, body: JSON.stringify({ query }), From b941d1ab8267b2e65d90207895f285494a3a1010 Mon Sep 17 00:00:00 2001 From: mstoyanovv Date: Tue, 15 Nov 2022 11:15:52 +0200 Subject: [PATCH 5/7] Remove wrong comma in doc's example --- src/fragments/lib/graphqlapi/graphql-from-node.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fragments/lib/graphqlapi/graphql-from-node.mdx b/src/fragments/lib/graphqlapi/graphql-from-node.mdx index 0ef17dbb01a..707c23b6478 100644 --- a/src/fragments/lib/graphqlapi/graphql-from-node.mdx +++ b/src/fragments/lib/graphqlapi/graphql-from-node.mdx @@ -301,8 +301,8 @@ export const handler = async (event) => { const requestToBeSigned = new HttpRequest({ method: 'POST', headers: { - 'Content-Type': 'application/json' - host: endpoint.host, + 'Content-Type': 'application/json', + host: endpoint.host }, hostname: endpoint.host, body: JSON.stringify({ query }), From 46f634caad2ef131e1aa1e1d7fe4abb003110f3e Mon Sep 17 00:00:00 2001 From: mstoyanovv <51913821+mstoyanovv@users.noreply.github.com> Date: Mon, 21 Nov 2022 10:31:53 +0200 Subject: [PATCH 6/7] Update src/fragments/lib/graphqlapi/graphql-from-node.mdx Co-authored-by: josef --- src/fragments/lib/graphqlapi/graphql-from-node.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fragments/lib/graphqlapi/graphql-from-node.mdx b/src/fragments/lib/graphqlapi/graphql-from-node.mdx index 707c23b6478..1de3ea11456 100644 --- a/src/fragments/lib/graphqlapi/graphql-from-node.mdx +++ b/src/fragments/lib/graphqlapi/graphql-from-node.mdx @@ -78,7 +78,6 @@ For functions written using CommonJS, you will need to install version 2 of `nod } } ``` -NOTE: The examples bellow are using ES module syntax and currently not supported by amplify mock function. If you wish to use amplify mock please use commonjs syntax with node-fetch v2. ## Query From 445e420553986f4f5b394991a70e38c9f2d30f6c Mon Sep 17 00:00:00 2001 From: Katie Goines <30757403+katiegoines@users.noreply.github.com> Date: Thu, 23 Mar 2023 10:48:04 -0700 Subject: [PATCH 7/7] commit to re-trigger checks --- src/fragments/lib/graphqlapi/graphql-from-node.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib/graphqlapi/graphql-from-node.mdx b/src/fragments/lib/graphqlapi/graphql-from-node.mdx index 1de3ea11456..f8043eb6b8c 100644 --- a/src/fragments/lib/graphqlapi/graphql-from-node.mdx +++ b/src/fragments/lib/graphqlapi/graphql-from-node.mdx @@ -1,5 +1,5 @@ You can call an AppSync GraphQL API from a Node.js app or a Lambda function. Take a basic `Todo` app as an example: - + ```graphql type Todo @model @auth(rules: [{ allow: public }]) { name: String