graphql requests in lambda

Solutions on MaxInterview for graphql requests in lambda by the best coders in the world

showing results for - "graphql requests in lambda"
Dominick
21 May 2017
1const axios = require('axios');
2const gql = require('graphql-tag');
3const graphql = require('graphql');
4const { print } = graphql;
5
6const listTodos = gql`
7  query listTodos {
8    listTodos {
9      items {
10        id
11        name
12        description
13      }
14    }
15  }
16`
17
18exports.handler = async (event) => {
19  try {
20    const graphqlData = await axios({
21      url: process.env.API_URL,
22      method: 'post',
23      headers: {
24        'x-api-key': process.env.API_<YOUR_API_NAME>_GRAPHQLAPIKEYOUTPUT
25      },
26      data: {
27        query: print(listTodos),
28      }
29    });
30    const body = {
31        graphqlData: graphqlData.data.data.listTodos
32    }
33    return {
34        statusCode: 200,
35        body: JSON.stringify(body),
36        headers: {
37            "Access-Control-Allow-Origin": "*",
38        }
39    }
40  } catch (err) {
41    console.log('error posting to appsync: ', err);
42  } 
43}
44const axios = require('axios');
45const gql = require('graphql-tag');
46const graphql = require('graphql');
47const { print } = graphql;
48
49const listTodos = gql`
50  query listTodos {
51    listTodos {
52      items {
53        id
54        name
55        description
56      }
57    }
58  }
59`
60
61exports.handler = async (event) => {
62  try {
63    const graphqlData = await axios({
64      url: process.env.API_URL,
65      method: 'post',
66      headers: {
67        'x-api-key': process.env.API_<YOUR_API_NAME>_GRAPHQLAPIKEYOUTPUT
68      },
69      data: {
70        query: print(listTodos),
71      }
72    });
73    const body = {
74        graphqlData: graphqlData.data.data.listTodos
75    }
76    return {
77        statusCode: 200,
78        body: JSON.stringify(body),
79        headers: {
80            "Access-Control-Allow-Origin": "*",
81        }
82    }
83  } catch (err) {
84    console.log('error posting to appsync: ', err);
85  } 
86}
similar questions
queries leading to this page
graphql requests in lambda