Skip to content

Commit 9c981ac

Browse files
mstoyanovvjosefaidtkatieklein
authored andcommitted
Updated graphql-from-node examples to be amplify mock compatible (#4441)
* Fix "Must provide Source" error Without Content Type header local mock is failing with "Must Provice Source" * 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. * Added callout to use node-fetch v2 for cjs * reverse order of http headers in last example * Remove wrong comma in doc's example * Update src/fragments/lib/graphqlapi/graphql-from-node.mdx Co-authored-by: josef <[email protected]> * commit to re-trigger checks --------- Co-authored-by: josef <[email protected]> Co-authored-by: Katie Goines <[email protected]>
1 parent d3e8494 commit 9c981ac

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/fragments/lib/graphqlapi/graphql-from-node.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
You can call an AppSync GraphQL API from a Node.js app or a Lambda function. Take a basic `Todo` app as an example:
2-
2+
33
```graphql
44
type Todo @model @auth(rules: [{ allow: public }]) {
55
name: String
@@ -150,9 +150,10 @@ export const handler = async (event) => {
150150
const options = {
151151
method: 'POST',
152152
headers: {
153-
'x-api-key': GRAPHQL_API_KEY
153+
'x-api-key': GRAPHQL_API_KEY,
154+
'Content-Type': 'application/json'
154155
},
155-
body: JSON.stringify({ query, variables })
156+
body: JSON.stringify({ query })
156157
};
157158

158159
const request = new Request(GRAPHQL_ENDPOINT, options);
@@ -222,7 +223,8 @@ export const handler = async (event) => {
222223
const options = {
223224
method: 'POST',
224225
headers: {
225-
'x-api-key': GRAPHQL_API_KEY
226+
'x-api-key': GRAPHQL_API_KEY,
227+
'Content-Type': 'application/json'
226228
},
227229
body: JSON.stringify({ query, variables })
228230
};

0 commit comments

Comments
 (0)