Skip to content

Commit

Permalink
feat: port @http to GraphQL Transformer v2 (#7139)
Browse files Browse the repository at this point in the history
This commit ports the @http directive to v2 of the GraphQL Transformer.
  • Loading branch information
cjihrig committed Apr 29, 2021
1 parent 8f8deba commit 2803605
Show file tree
Hide file tree
Showing 13 changed files with 989 additions and 1 deletion.
1 change: 1 addition & 0 deletions jest.config.js
Expand Up @@ -45,6 +45,7 @@ module.exports = {
// '<rootDir>/packages/amplify-graphiql-explorer',
'<rootDir>/packages/amplify-graphql-docs-generator',
'<rootDir>/packages/amplify-graphql-function-transformer',
'<rootDir>/packages/amplify-graphql-http-transformer',
'<rootDir>/packages/amplify-graphql-types-generator',
'<rootDir>/packages/amplify-provider-awscloudformation',
'<rootDir>/packages/amplify-storage-simulator',
Expand Down
5 changes: 5 additions & 0 deletions packages/amplify-graphql-http-transformer/.npmignore
@@ -0,0 +1,5 @@
**/__mocks__/**
**/__tests__/**
src
tsconfig.json
tsconfig.tsbuildinfo
4 changes: 4 additions & 0 deletions packages/amplify-graphql-http-transformer/CHANGELOG.md
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
25 changes: 25 additions & 0 deletions packages/amplify-graphql-http-transformer/README.md
@@ -0,0 +1,25 @@
# GraphQL @http Transformer

# Reference Documentation

### @http

The `@http` directive allows you to quickly and easily configure HTTP
resolvers within your AWS AppSync API.

#### Definition

```graphql
directive @http(method: HttpMethod = GET, url: String!, headers: [HttpHeader] = []) on FIELD_DEFINITION
enum HttpMethod {
GET
POST
PUT
DELETE
PATCH
}
input HttpHeader {
key: String
value: String
}
```
52 changes: 52 additions & 0 deletions packages/amplify-graphql-http-transformer/package.json
@@ -0,0 +1,52 @@
{
"name": "@aws-amplify/graphql-http-transformer",
"version": "0.1.0",
"description": "Amplify GraphQL @http tranformer",
"repository": {
"type": "git",
"url": "https://github.com/aws-amplify/amplify-cli.git",
"directory": "packages/amplify-graphql-http-transformer"
},
"author": "Amazon Web Services",
"license": "Apache-2.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [
"graphql",
"cloudformation",
"aws",
"amplify"
],
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"clean": "rimraf ./lib",
"test": "jest"
},
"dependencies": {
"@aws-amplify/graphql-transformer-core": "0.3.4",
"@aws-amplify/graphql-transformer-interfaces": "1.3.1",
"@aws-cdk/core": "~1.72.0",
"graphql": "^14.5.8",
"graphql-mapping-template": "4.18.1",
"graphql-transformer-common": "4.19.1"
},
"devDependencies": {
"@aws-cdk/assert": "~1.72.0"
},
"jest": {
"transform": {
"^.+\\.(ts|tsx)?$": "ts-jest"
},
"testRegex": "(src/__tests__/.*.test.ts)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"collectCoverage": true
}
}
@@ -0,0 +1,141 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generates expected VTL 1`] = `
Object {
"Comment.complexPut.req.vtl": "## [Start] Create request. **
## START: Manually checking that all non-null arguments are provided either in the query or the body **
#if( (!$ctx.args.body.userId && !$ctx.args.query.userId) )
$util.error(\\"An argument you marked as Non-Null is not present in the query nor the body of your request.\\"))
#end
## END: Manually checking that all non-null arguments are provided either in the query or the body **
#set( $headers = $utils.http.copyHeaders($ctx.request.headers) )
$util.qr($headers.put(\\"accept-encoding\\", \\"application/json\\"))
$util.qr($headers.put(\\"Content-Type\\", \\"application/json\\"))
$util.qr($headers.put(\\"X-Header\\", \\"X-Header-ValuePut\\"))
{
\\"version\\": \\"2018-05-29\\",
\\"method\\": \\"PUT\\",
\\"resourcePath\\": \\"/posts/\${ctx.args.params.title}/\${ctx.args.params.id}/\${ctx.source.id}\\",
\\"params\\": {
\\"headers\\": $util.toJson($headers),
\\"query\\": $util.toJson($ctx.args.query),
\\"body\\": $util.toJson($ctx.args.body)
}
}
## [End] Create request. **",
"Comment.complexPut.res.vtl": "## [Start] Process response. **
#if( $ctx.result.statusCode == 200 || $ctx.result.statusCode == 201 )
#if( $ctx.result.headers.get(\\"Content-Type\\").toLowerCase().contains(\\"xml\\") )
$utils.xml.toJsonString($ctx.result.body)
#else
$ctx.result.body
#end
#else
$util.qr($util.appendError($ctx.result.body, $ctx.result.statusCode))
#end
## [End] Process response. **",
"Comment.content.req.vtl": "## [Start] Create request. **
#set( $headers = $utils.http.copyHeaders($ctx.request.headers) )
$util.qr($headers.put(\\"accept-encoding\\", \\"application/json\\"))
$util.qr($headers.put(\\"X-Header\\", \\"X-Header-Value\\"))
{
\\"version\\": \\"2018-05-29\\",
\\"method\\": \\"GET\\",
\\"resourcePath\\": \\"/ping\\",
\\"params\\": {
\\"headers\\": $util.toJson($headers),
\\"query\\": $util.toJson($ctx.args.query)
}
}
## [End] Create request. **",
"Comment.content.res.vtl": "## [Start] Process response. **
#if( $ctx.result.statusCode == 200 )
#if( $ctx.result.headers.get(\\"Content-Type\\").toLowerCase().contains(\\"xml\\") )
$utils.xml.toJsonString($ctx.result.body)
#else
$ctx.result.body
#end
#else
$util.qr($util.appendError($ctx.result.body, $ctx.result.statusCode))
#end
## [End] Process response. **",
"Comment.contentDelete.req.vtl": "## [Start] Create request. **
#set( $headers = $utils.http.copyHeaders($ctx.request.headers) )
$util.qr($headers.put(\\"accept-encoding\\", \\"application/json\\"))
$util.qr($headers.put(\\"X-Header\\", \\"X-Header-ValueDelete\\"))
{
\\"version\\": \\"2018-05-29\\",
\\"method\\": \\"DELETE\\",
\\"resourcePath\\": \\"/ping\\",
\\"params\\": {
\\"headers\\": $util.toJson($headers)
}
}
## [End] Create request. **",
"Comment.contentDelete.res.vtl": "## [Start] Process response. **
#if( $ctx.result.statusCode == 200 )
#if( $ctx.result.headers.get(\\"Content-Type\\").toLowerCase().contains(\\"xml\\") )
$utils.xml.toJsonString($ctx.result.body)
#else
$ctx.result.body
#end
#else
$util.qr($util.appendError($ctx.result.body, $ctx.result.statusCode))
#end
## [End] Process response. **",
"Comment.contentPatch.req.vtl": "## [Start] Create request. **
#set( $headers = $utils.http.copyHeaders($ctx.request.headers) )
$util.qr($headers.put(\\"accept-encoding\\", \\"application/json\\"))
$util.qr($headers.put(\\"Content-Type\\", \\"application/json\\"))
$util.qr($headers.put(\\"X-Header\\", \\"X-Header-ValuePatch\\"))
{
\\"version\\": \\"2018-05-29\\",
\\"method\\": \\"PATCH\\",
\\"resourcePath\\": \\"/ping\\",
\\"params\\": {
\\"headers\\": $util.toJson($headers),
\\"query\\": $util.toJson($ctx.args.query),
\\"body\\": $util.toJson($ctx.args.body)
}
}
## [End] Create request. **",
"Comment.contentPatch.res.vtl": "## [Start] Process response. **
#if( $ctx.result.statusCode == 200 || $ctx.result.statusCode == 201 )
#if( $ctx.result.headers.get(\\"Content-Type\\").toLowerCase().contains(\\"xml\\") )
$utils.xml.toJsonString($ctx.result.body)
#else
$ctx.result.body
#end
#else
$util.qr($util.appendError($ctx.result.body, $ctx.result.statusCode))
#end
## [End] Process response. **",
"Comment.contentPost.req.vtl": "## [Start] Create request. **
#set( $headers = $utils.http.copyHeaders($ctx.request.headers) )
$util.qr($headers.put(\\"accept-encoding\\", \\"application/json\\"))
$util.qr($headers.put(\\"Content-Type\\", \\"application/json\\"))
$util.qr($headers.put(\\"X-Header\\", \\"X-Header-ValuePost\\"))
{
\\"version\\": \\"2018-05-29\\",
\\"method\\": \\"POST\\",
\\"resourcePath\\": \\"/ping\\",
\\"params\\": {
\\"headers\\": $util.toJson($headers),
\\"query\\": $util.toJson($ctx.args.query),
\\"body\\": $util.toJson($ctx.args.body)
}
}
## [End] Create request. **",
"Comment.contentPost.res.vtl": "## [Start] Process response. **
#if( $ctx.result.statusCode == 200 || $ctx.result.statusCode == 201 )
#if( $ctx.result.headers.get(\\"Content-Type\\").toLowerCase().contains(\\"xml\\") )
$utils.xml.toJsonString($ctx.result.body)
#else
$ctx.result.body
#end
#else
$util.qr($util.appendError($ctx.result.body, $ctx.result.statusCode))
#end
## [End] Process response. **",
}
`;

0 comments on commit 2803605

Please sign in to comment.