{
    "Amplify API Configuration": {
        "prefix": "API: ",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "API: {",
            "\tendpoints: [",
            "\t\t{",
                "\t\t\tname: ${1:\"MyAPIGatewayAPI\"},",
                "\t\t\tendpoint: ${2:\"https://1234567890-abcdefgh.amazonaws.com\"}",
            "\t\t},",
            "\t\t{",
                "\t\t\tname: ${3:\"MyCustomCloudFrontApi\"},",
                "\t\t\tendpoint: ${4:\"https://api.my-custom-cloudfront-domain.com\"}",
            "\t\t},",
            "\t\t{",
                "\t\t\tname: ${5:\"MyCustomLambdaApi\"},",
                "\t\t\tendpoint: ${6:\"https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/yourFuncName/invocations\"},",
                "\t\t\tservice: ${7:\"lambda\"},",
                "\t\t\tregion: ${8:\"us-east-1\"}",
            "\t\t},",
            "\t]",
            "}"
        ]
    },
    "Amplify Get": {
        "prefix": "API.get",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "API.get(${1:apiName, path, myInit})",
            "\t.then(response => {",
            "\t\t// Add your code here",
            "\t})",
            "\t.catch(error => {",
            "\t\tconsole.log(error.response)",
            "\t})"
        ]
    },
    "Amplify Post": {
        "prefix": "API.post",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "API.post(${1:apiName, path, myInit})",
            "\t.then(response => {",
            "\t\t// Add your code here",
            "\t})",
            "\t.catch(error => {",
            "\t\tconsole.log(error.response)",
            "\t})"
        ]      
    },
    "Amplify Put": {
        "prefix": "API.put",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "API.put(${1:apiName, path, myInit})",
            "\t.then(response => {",
            "\t\t// Add your code here",
            "\t})",
            "\t.catch(error => {",
            "\t\tconsole.log(error.response)",
            "\t})"
        ]      
    },
    "Amplify Delete": {
        "prefix": "API.del",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "API.del(${1:apiName, path, myInit})",
            "\t.then(response => {",
            "\t\t// Add your code here",
            "\t})",
            "\t.catch(error => {",
            "\t\tconsole.log(error.response)",
            "\t})"
        ]      
    },
    "Amplify Head": {
        "prefix": "API.head",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "API.head(${1:apiName, path, myInit})",
            "\t.then(response => {",
            "\t\t// Add your code here",
            "\t})"
        ]      
    },
    "API async getData()": {
        "prefix": "getData()",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "getData() {",
            "\tlet apiName = ${1:'MyApiName'};",
            "\tlet path = ${2:'/path'};",
            "\tlet myInit = { // OPTIONAL",
                "\t\theaders: {} // OPTIONAL",
            "\t}",
            "\treturn await API.get(apiName, path, myInit);",
            "\t} \n",
            "getData();"
        ]
    },
    "API async postData()": {
        "prefix": "postData()",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "postData() {",
            "\tlet apiName = ${1:'MyApiName'};",
            "\tlet path = ${2:'/path'};",
            "\tlet myInit = { // OPTIONAL",
                "\t\tbody: {}, // replace this with attributes you need",
                "\t\theaders: {} // OPTIONAL",
            "\t}",
            "\treturn await API.post(apiName, path, myInit);",
            "\t} \n",
            "postData();"
        ]
    },
    "API async putData()": {
        "prefix": "putData()",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "putData() {",
            "\tlet apiName = ${1:'MyApiName'};",
            "\tlet path = ${2:'/path'};",
            "\tlet myInit = { // OPTIONAL",
                "\t\tbody: {}, // replace this with attributes you need",
                "\t\theaders: {} // OPTIONAL",
            "\t}",
            "\treturn await API.put(apiName, path, myInit);",
            "\t} \n",
            "putData();"
        ]
    },
    "API async deleteData()": {
        "prefix": "deleteData()",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "deleteData() {",
            "\tlet apiName = ${1:'MyApiName'};",
            "\tlet path = ${2:'/path'};",
            "\tlet myInit = { // OPTIONAL",
                "\t\theaders: {} // OPTIONAL",
            "\t}",
            "\treturn await API.del(apiName, path, myInit);",
            "\t} \n",
            "deleteData();"
        ]
    },
    "API async head()": {
        "prefix": "head()",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "head() {",
            "\tlet apiName = ${1:'MyApiName'};",
            "\tlet path = ${2:'/path'};",
            "\tlet myInit = { // OPTIONAL",
                "\t\theaders: {} // OPTIONAL",
            "\t}",
            "\treturn await API.head(apiName, path, myInit);",
            "\t} \n",
            "head();"
        ]
    },
    "APIGraphQL Endpoint": {
        "prefix": "graphql_endpoint:",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "graphql_endpoint: ${1:'https:/www.example.com/my-graphql-endpoint'}"
        ]
    },
    "APIGraphQL Endpoint IAM Region": {
        "prefix": "graphql_endpoint_iam_region:",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "graphql_endpoint_iam_region: ${1:'my_graphql_apigateway_region'}"
        ]
    },
    "APIGraphQL Operation": {
        "prefix": "graphqlOperation",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "graphqlOperation"
        ]
    },
    "API AppSync Configuration": {
        "prefix": "myAppConfig",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "myAppConfig = {",
                "\t// ...",
                "\t'aws_appsync_graphqlEndpoint': ${1:'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql'},",
                "\t'aws_appsync_region': ${2:'us-east-1'},",
                "\t'aws_appsync_authenticationType': ${3:'OPENID_CONNECT'}, // Before calling API.graphql(...) is required to do Auth.federatedSignIn(...) check authentication guide for details.",
                "\t// ...",
            "}\n",
            "Amplify.configure(myAppConfig)"
        ]
    },
    "Query ListEvents": {
        "prefix": "ListEvents",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "ListEvents = `query ListEvents {",
                "\tlistEvents {",
                    "\t\titems {",
                        "\t\t\tid",
                        "\t\t\twhere",
                        "\t\t\tdescription",
                    "\t\t}",
                "\t}",
            "}`;"
        ]
    },
    "Query GetEvent": {
        "prefix": "GetEvent",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "GetEvent = `query GetEvent($id: ID! $nextToken: String) {",
                "\tgetEvent(id: $id) {",
                    "\t\tid",
                    "\t\tname",
                    "\t\tdescription",
                    "\t\tcomments(nextToken: $nextToken) {",
                        "\t\t\titems {",
                            "\t\t\t\tcontent",
                        "\t\t\t}",
                    "\t\t}",
                "\t}",
            "}`;"
        ]
    },
    "Mutations CreateEvent": {
        "prefix": "CreateEvent",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "CreateEvent = `mutation CreateEvent($name: String!, $when: String!, $where: String!, $description: String!) {",
                "\tcreateEvent(name: $name, when: $when, where: $where, description: $description) {",
                    "\t\tid",
                    "\t\tname",
                    "\t\twhere",
                    "\t\twhen",
                    "\t\tdescription",
                "\t}",
            "}`;\n",
            "// Mutation",
            "const eventDetails = {",
                "\tname: ${1:'Party tonight!}',",
                "\twhen: ${2:'8:00pm'},",
                "\twhere: ${3:'Ballroom'},",
                "\tdescription: ${4:'Coming together as a team!'}",
            "};\n",
            "const newEvent = await API.graphql(graphqlOperation(CreateEvent, eventDetails));",
            "console.log(newEvent);"
        ]
    },
    "Subscriptions SubscribeToEventComments": {
        "prefix": "SubscribeToEventComments",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "SubscribeToEventComments = `subscription SubscribeToEventComments($eventId: String!) {",
                "\tsubscribeToEventComments(eventId: $eventId) {",
                    "\t\teventId",
                    "\t\tcommentId",
                    "\t\tcontent",
                "\t}",
            "}`;\n",
            "// Subscribe with eventId 123",
            "const subscription = API.graphql(",
            "\tgraphqlOperation(SubscribeToEventComments, { eventId: ${1:'123'} })",
            ").subscribe({",
                "\tnext: (eventData) => console.log(eventData)",
            "});\n",
            "// Stop receiving data updates from the subscription",
            "subscription.unsubscribe();"
        ]
    },
    "queryStringParameters": {
        "prefix": "queryStringParameters",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "queryStringParameters"
        ]
    },
    "awsServerlessExpressMiddleware": {
        "prefix": "awsServerlessExpressMiddleware",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "awsServerlessExpressMiddleware"
        ]
    },
    "apiGateway": {
        "prefix": "apiGateway",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "apiGateway"
        ]
    },
    "custom_header": {
        "prefix": "custom_header",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "custom_header: async () => {",
                "\treturn { Authorization : ${1:'token'} }",
                "\t// Alternatively, with Cognito User Pools use this:",
                "\t// return { (await Auth.currentSession()).idToken.jwtToken }",
            "}"
        ]
    },
    "React Connect": {
        "prefix": "<Connect",
        "scope": "javascript,javascriptreact,typescript",
        "body": [
            "<Connect query={graphqlOperation(GetEvent, { id: currEventId })}",
            "\t\tsubscription={graphqlOperation(SubscribeToEventComments, { eventId: currEventId })}",
            "\t\tonSubscriptionsMsg={(prev, { subscribeToEventComments }) => {",
                "\t\t\tconsole.log ( subscribeToEventComments);",
                "\t\t\treturn prev; }}>",
            "\t{({ data: { listEvents } }) => (",
            "\t\t<AllEvents events={listEvents ? listEvents.items : []} />",
            "\t)}",
            "</Connect>"
        ]
    }
}