Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(graphql-default-value-transformer): implemented default value directive #8291

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = {
'<rootDir>/packages/amplify-graphql-function-transformer',
'<rootDir>/packages/amplify-graphql-http-transformer',
'<rootDir>/packages/amplify-graphql-index-transformer',
'<rootDir>/packages/amplify-graphql-default-value-transformer',
'<rootDir>/packages/amplify-graphql-model-transformer',
'<rootDir>/packages/amplify-graphql-predictions-transformer',
'<rootDir>/packages/amplify-graphql-relational-transformer',
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions packages/amplify-graphql-default-value-transformer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# GraphQL @default Transformer

# Reference Documentation

### @default

The `@default` directive allows you to define the default value for your field.

#### Definition

```graphql
directive @default(value: String) on FIELD_DEFINITION
```
57 changes: 57 additions & 0 deletions packages/amplify-graphql-default-value-transformer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@aws-amplify/graphql-default-value-transformer",
"version": "0.1.0",
"description": "Amplify GraphQL default value transformer",
"repository": {
"type": "git",
"url": "https://github.com/aws-amplify/amplify-cli.git",
"directory": "packages/amplify-graphql-default-value-transformer"
},
"author": "Amazon Web Services",
"license": "Apache-2.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [
"graphql",
"cloudformation",
"aws",
"amplify"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"clean": "rimraf ./lib",
"test": "jest",
"test-watch": "jest --watch"
},
"dependencies": {
"@aws-amplify/graphql-transformer-interfaces": "1.9.1",
"@aws-amplify/graphql-transformer-core": "0.9.1",
"graphql-mapping-template": "4.18.3",
"graphql-transformer-common": "4.19.10",
"graphql": "^14.5.8",
"libphonenumber-js": "^1.7.31"
},
"devDependencies": {
"@aws-cdk/assert": "~1.124.0"
},
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testURL": "http://localhost",
"testRegex": "(src/__tests__/.*\\.(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"collectCoverage": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DefaultValueModelTransformer: should successfully transform simple valid schema 1`] = `
"
type Post {
id: ID!
stringValue: String
intVal: Int
floatValue: Float
booleanValue: Boolean
awsJsonValue: AWSJSON
awsDateValue: AWSDate
awsTimestampValue: AWSTimestamp
awsEmailValue: AWSEmail
awsURLValue: AWSURL
awsPhoneValue: AWSPhone
awsIPAddressValue1: AWSIPAddress
awsIPAddressValue2: AWSIPAddress
enumValue: Tag
awsTimeValue: AWSTime
awsDateTime: AWSDateTime
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
}

enum Tag {
NEWS
RANDOM
}

input ModelStringInput {
ne: String
eq: String
le: String
lt: String
ge: String
gt: String
contains: String
notContains: String
between: [String]
beginsWith: String
attributeExists: Boolean
attributeType: ModelAttributeTypes
size: ModelSizeInput
}

input ModelIntInput {
ne: Int
eq: Int
le: Int
lt: Int
ge: Int
gt: Int
between: [Int]
attributeExists: Boolean
attributeType: ModelAttributeTypes
}

input ModelFloatInput {
ne: Float
eq: Float
le: Float
lt: Float
ge: Float
gt: Float
between: [Float]
attributeExists: Boolean
attributeType: ModelAttributeTypes
}

input ModelBooleanInput {
ne: Boolean
eq: Boolean
attributeExists: Boolean
attributeType: ModelAttributeTypes
}

input ModelIDInput {
ne: ID
eq: ID
le: ID
lt: ID
ge: ID
gt: ID
contains: ID
notContains: ID
between: [ID]
beginsWith: ID
attributeExists: Boolean
attributeType: ModelAttributeTypes
size: ModelSizeInput
}

enum ModelAttributeTypes {
binary
binarySet
bool
list
map
number
numberSet
string
stringSet
_null
}

input ModelSizeInput {
ne: Int
eq: Int
le: Int
lt: Int
ge: Int
gt: Int
between: [Int]
}

enum ModelSortDirection {
ASC
DESC
}

type ModelPostConnection {
items: [Post]
nextToken: String
}

input ModelTagInput {
eq: Tag
ne: Tag
}

input ModelPostFilterInput {
id: ModelIDInput
stringValue: ModelStringInput
intVal: ModelIntInput
floatValue: ModelFloatInput
booleanValue: ModelBooleanInput
awsJsonValue: ModelStringInput
awsDateValue: ModelStringInput
awsTimestampValue: ModelIntInput
awsEmailValue: ModelStringInput
awsURLValue: ModelStringInput
awsPhoneValue: ModelStringInput
awsIPAddressValue1: ModelStringInput
awsIPAddressValue2: ModelStringInput
enumValue: ModelTagInput
awsTimeValue: ModelStringInput
awsDateTime: ModelStringInput
and: [ModelPostFilterInput]
or: [ModelPostFilterInput]
not: ModelPostFilterInput
}

type Query {
getPost(id: ID!): Post
listPosts(filter: ModelPostFilterInput, limit: Int, nextToken: String): ModelPostConnection
}

input ModelPostConditionInput {
stringValue: ModelStringInput
intVal: ModelIntInput
floatValue: ModelFloatInput
booleanValue: ModelBooleanInput
awsJsonValue: ModelStringInput
awsDateValue: ModelStringInput
awsTimestampValue: ModelIntInput
awsEmailValue: ModelStringInput
awsURLValue: ModelStringInput
awsPhoneValue: ModelStringInput
awsIPAddressValue1: ModelStringInput
awsIPAddressValue2: ModelStringInput
enumValue: ModelTagInput
awsTimeValue: ModelStringInput
awsDateTime: ModelStringInput
and: [ModelPostConditionInput]
or: [ModelPostConditionInput]
not: ModelPostConditionInput
}

input CreatePostInput {
id: ID
stringValue: String
intVal: Int
floatValue: Float
booleanValue: Boolean
awsJsonValue: AWSJSON
awsDateValue: AWSDate
awsTimestampValue: AWSTimestamp
awsEmailValue: AWSEmail
awsURLValue: AWSURL
awsPhoneValue: AWSPhone
awsIPAddressValue1: AWSIPAddress
awsIPAddressValue2: AWSIPAddress
enumValue: Tag
awsTimeValue: AWSTime
awsDateTime: AWSDateTime
}

input UpdatePostInput {
id: ID!
stringValue: String
intVal: Int
floatValue: Float
booleanValue: Boolean
awsJsonValue: AWSJSON
awsDateValue: AWSDate
awsTimestampValue: AWSTimestamp
awsEmailValue: AWSEmail
awsURLValue: AWSURL
awsPhoneValue: AWSPhone
awsIPAddressValue1: AWSIPAddress
awsIPAddressValue2: AWSIPAddress
enumValue: Tag
awsTimeValue: AWSTime
awsDateTime: AWSDateTime
}

input DeletePostInput {
id: ID!
}

type Mutation {
createPost(input: CreatePostInput!, condition: ModelPostConditionInput): Post
updatePost(input: UpdatePostInput!, condition: ModelPostConditionInput): Post
deletePost(input: DeletePostInput!, condition: ModelPostConditionInput): Post
}

type Subscription {
onCreatePost: Post @aws_subscribe(mutations: [\\"createPost\\"])
onUpdatePost: Post @aws_subscribe(mutations: [\\"updatePost\\"])
onDeletePost: Post @aws_subscribe(mutations: [\\"deletePost\\"])
}

"
`;
Loading