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

Add checks for parsing validate directive #3125

Open
wants to merge 32 commits into
base: feature/server-side-validation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9656730
add `field` method in `ValidateTransformer` class, add checks when pa…
bobbyu99 Jan 21, 2025
c8ccf7f
rename the test folder so that no duplicate tests are run
bobbyu99 Jan 22, 2025
8b83f69
update snapshot test for repeatable use of validate directive
bobbyu99 Jan 22, 2025
e1f4d7f
ignore types.ts in test coverage
bobbyu99 Jan 22, 2025
c628310
refactor and simplify
bobbyu99 Jan 22, 2025
8210e6f
refactor validator and its tests
bobbyu99 Jan 22, 2025
ee67f15
update API.md and a comment
bobbyu99 Jan 22, 2025
73ca173
used c8 ignore instead of excluding in jest.config.js
bobbyu99 Jan 22, 2025
11161e2
update length value validators and add more edge case tests
bobbyu99 Jan 22, 2025
d280323
add and refactor tests for duplicate validation types
bobbyu99 Jan 22, 2025
3506ca5
refactor type compatibility tests
bobbyu99 Jan 22, 2025
2a8e0c7
update integer validation logic
bobbyu99 Jan 22, 2025
0cbcdfc
prettier
bobbyu99 Jan 22, 2025
310a303
rename test files
bobbyu99 Jan 22, 2025
b5fddfa
refactor tests and add some more test
bobbyu99 Jan 23, 2025
801c31e
fix some bug in tests
bobbyu99 Jan 23, 2025
8dc62d4
prettier
bobbyu99 Jan 23, 2025
714c777
nit
bobbyu99 Jan 23, 2025
873f598
add snapshot tests
bobbyu99 Jan 23, 2025
f389fc7
update types comments to use JSDoc style
bobbyu99 Jan 23, 2025
4a97be8
add numeric validation tests to cover 0, positive & negative ints, po…
bobbyu99 Jan 23, 2025
d21a347
use Number in place of parseInt
bobbyu99 Jan 23, 2025
ba63312
refactor duplicate-validation-types.test.ts
bobbyu99 Jan 23, 2025
4a1b249
refactor minmax-length.test and validation-field-type-compatibility-test
bobbyu99 Jan 24, 2025
8abce32
update snapshot tests
bobbyu99 Jan 24, 2025
f84ca3e
refactor test files
bobbyu99 Jan 24, 2025
3eb7b66
refactor tests files
bobbyu99 Jan 25, 2025
6e642b7
added check and tests for non-model type
bobbyu99 Jan 26, 2025
9101a17
add test description
bobbyu99 Jan 26, 2025
3f8a360
add docs for helper
bobbyu99 Jan 26, 2025
a60fbd6
nit
bobbyu99 Jan 26, 2025
2abf979
add some docs
bobbyu99 Jan 26, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ Object {
type: ValidationType!
value: String!
errorMessage: String
) on FIELD_DEFINITION
) repeatable on FIELD_DEFINITION

enum ValidationType {
gt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const definition = /* GraphQL */ `
type: ValidationType!
value: String!
errorMessage: String
) on FIELD_DEFINITION
) repeatable on FIELD_DEFINITION

enum ValidationType {
gt
Expand Down
12 changes: 10 additions & 2 deletions packages/amplify-graphql-validate-transformer/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@

```ts

import { DirectiveNode } from 'graphql';
import { FieldDefinitionNode } from 'graphql';
import { InterfaceTypeDefinitionNode } from 'graphql';
import { ObjectTypeDefinitionNode } from 'graphql';
import { TransformerContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
import { TransformerPluginBase } from '@aws-amplify/graphql-transformer-core';
import { TransformerPluginProvider } from '@aws-amplify/graphql-transformer-interfaces';
import { TransformerSchemaVisitStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces';

// @public (undocumented)
export class ValidateTransformer extends TransformerPluginBase {
export class ValidateTransformer extends TransformerPluginBase implements TransformerPluginProvider {
constructor();
// (undocumented)
generateResolvers: (ctx: TransformerContextProvider) => void;
field: (parent: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode, definition: FieldDefinitionNode, directive: DirectiveNode, _: TransformerSchemaVisitStepContextProvider) => void;
// (undocumented)
generateResolvers: (_: TransformerContextProvider) => void;
}

// (No @packageDocumentation comment for this package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,4 @@ const baseConfig = require('../../jest.config.base.js'); // eslint-disable-line

module.exports = {
...baseConfig,
coverageThreshold: {
global: {
branches: 100,
lines: 100,
functions: 100,
},
},
};
4 changes: 4 additions & 0 deletions packages/amplify-graphql-validate-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@
"@aws-amplify/graphql-transformer-interfaces": "4.2.1",
"graphql": "^15.5.0",
"graphql-transformer-common": "5.1.2"
},
"devDependencies": {
"@aws-amplify/graphql-transformer-test-utils": "1.0.11",
"@aws-amplify/graphql-model-transformer": "3.1.4"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Duplicate Validation Types Valid usage accepts different validation types on same field 1`] = `
"type Post {
id: ID!
title: String!
rating: Float!
score: Int!
description: String!
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
}

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
}

input ModelSubscriptionStringInput {
ne: String
eq: String
le: String
lt: String
ge: String
gt: String
contains: String
notContains: String
between: [String]
beginsWith: String
in: [String]
notIn: [String]
}

input ModelSubscriptionIntInput {
ne: Int
eq: Int
le: Int
lt: Int
ge: Int
gt: Int
between: [Int]
in: [Int]
notIn: [Int]
}

input ModelSubscriptionFloatInput {
ne: Float
eq: Float
le: Float
lt: Float
ge: Float
gt: Float
between: [Float]
in: [Float]
notIn: [Float]
}

input ModelSubscriptionBooleanInput {
ne: Boolean
eq: Boolean
}

input ModelSubscriptionIDInput {
ne: ID
eq: ID
le: ID
lt: ID
ge: ID
gt: ID
contains: ID
notContains: ID
between: [ID]
beginsWith: ID
in: [ID]
notIn: [ID]
}

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 ModelPostFilterInput {
id: ModelIDInput
title: ModelStringInput
rating: ModelFloatInput
score: ModelIntInput
description: ModelStringInput
createdAt: ModelStringInput
updatedAt: ModelStringInput
and: [ModelPostFilterInput]
or: [ModelPostFilterInput]
not: ModelPostFilterInput
}

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

input ModelPostConditionInput {
title: ModelStringInput
rating: ModelFloatInput
score: ModelIntInput
description: ModelStringInput
and: [ModelPostConditionInput]
or: [ModelPostConditionInput]
not: ModelPostConditionInput
createdAt: ModelStringInput
updatedAt: ModelStringInput
}

input CreatePostInput {
id: ID
title: String!
rating: Float!
score: Int!
description: String!
}

input UpdatePostInput {
id: ID!
title: String
rating: Float
score: Int
description: String
}

input DeletePostInput {
id: ID!
}

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

input ModelSubscriptionPostFilterInput {
id: ModelSubscriptionIDInput
title: ModelSubscriptionStringInput
rating: ModelSubscriptionFloatInput
score: ModelSubscriptionIntInput
description: ModelSubscriptionStringInput
createdAt: ModelSubscriptionStringInput
updatedAt: ModelSubscriptionStringInput
and: [ModelSubscriptionPostFilterInput]
or: [ModelSubscriptionPostFilterInput]
}

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