Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
13 changed files
with
989 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
**/__mocks__/** | ||
**/__tests__/** | ||
src | ||
tsconfig.json | ||
tsconfig.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
...ttp-transformer/src/__tests__/__snapshots__/amplify-graphql-http-transformer.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. **", | ||
} | ||
`; |
Oops, something went wrong.