graphql-connection-transformer
Advanced tools
Comparing version 1.0.27 to 1.0.28-beta.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="1.0.28-beta.0"></a> | ||
## [1.0.28-beta.0](https://github.com/aws-amplify/amplify-cli/compare/graphql-connection-transformer@1.0.12...graphql-connection-transformer@1.0.28-beta.0) (2018-10-12) | ||
### Bug Fixes | ||
* **graphql-connection-transformer:** Remove unused types ([87c3e0a](https://github.com/aws-amplify/amplify-cli/commit/87c3e0a)) | ||
<a name="1.0.12"></a> | ||
@@ -8,0 +19,0 @@ ## [1.0.12](https://github.com/aws-amplify/amplify-cli/compare/graphql-connection-transformer@1.0.11...graphql-connection-transformer@1.0.12) (2018-08-23) |
@@ -70,3 +70,3 @@ "use strict"; | ||
test('Test ModelConnectionTransformer simple one to many happy case with custom keyField', function () { | ||
var validSchema = "\n type Post @model {\n id: ID!\n title: String!\n createdAt: String\n updatedAt: String\n comments: [Comment] @connection(name: \"PostComments\", keyField: \"postId\")\n }\n type Comment @model {\n id: ID!\n content: String!\n post: Post @connection(name: \"PostComments\", keyField: \"postId\")\n }\n "; | ||
var validSchema = "\n type Post @model {\n id: ID!\n title: String!\n createdAt: String\n updatedAt: String\n comments: [Comment] @connection(name: \"PostComments\", keyField: \"postId\")\n }\n type Comment @model {\n id: ID!\n content: String!\n post: Post! @connection(name: \"PostComments\", keyField: \"postId\")\n }\n "; | ||
var transformer = new graphql_transformer_core_1.default({ | ||
@@ -96,5 +96,7 @@ transformers: [ | ||
expect(connectionId).toBeTruthy(); | ||
expect(connectionId.type.kind).toEqual(graphql_1.Kind.NON_NULL_TYPE); | ||
var commentUpdateInput = getInputType(schemaDoc, graphql_transformer_common_1.ModelResourceIDs.ModelUpdateInputObjectName('Comment')); | ||
var connectionUpdateId = commentUpdateInput.fields.find(function (f) { return f.name.value === 'postId'; }); | ||
expect(connectionUpdateId).toBeTruthy(); | ||
expect(connectionUpdateId.type.kind).toEqual(graphql_1.Kind.NAMED_TYPE); | ||
}); | ||
@@ -197,2 +199,42 @@ test('Test ModelConnectionTransformer complex one to many happy case', function () { | ||
}); | ||
test('Test ModelConnectionTransformer with non null @connections', function () { | ||
var validSchema = "\n type Post @model {\n id: ID!\n title: String!\n createdAt: String\n updatedAt: String\n comments: [Comment] @connection(name: \"PostComments\", keyField: \"postId\")\n\n # A non null on the one in a 1-M does enforce a non-null\n # on the CreatePostInput\n singleComment: Comment! @connection\n\n # A non null on the many in a 1-M does not enforce a non-null\n # in the CommentCreateInput because it is not explicitly implied.\n manyComments: [Comment]! @connection\n }\n type Comment @model {\n id: ID!\n content: String!\n\n # A non-null on the one in 1-M again enforces a non null.\n post: Post! @connection(name: \"PostComments\", keyField: \"postId\")\n }\n "; | ||
var transformer = new graphql_transformer_core_1.default({ | ||
transformers: [ | ||
new graphql_appsync_transformer_1.default(), | ||
new graphql_dynamodb_transformer_1.default(), | ||
new ModelConnectionTransformer_1.ModelConnectionTransformer() | ||
] | ||
}); | ||
var out = transformer.transform(validSchema); | ||
expect(out).toBeDefined(); | ||
expect(out.Resources[graphql_transformer_common_1.ResolverResourceIDs.ResolverResourceID('Post', 'comments')]).toBeTruthy(); | ||
var schemaDoc = graphql_1.parse(out.Resources[graphql_transformer_common_1.ResourceConstants.RESOURCES.GraphQLSchemaLogicalID].Properties.Definition); | ||
// Post.comments field | ||
var postType = getObjectType(schemaDoc, 'Post'); | ||
expectFields(postType, ['comments']); | ||
var commentField = postType.fields.find(function (f) { return f.name.value === 'comments'; }); | ||
expect(commentField.arguments.length).toEqual(4); | ||
expectArguments(commentField, ['filter', 'limit', 'nextToken', 'sortDirection']); | ||
expect(commentField.type.kind).toEqual(graphql_1.Kind.NAMED_TYPE); | ||
expect(commentField.type.name.value).toEqual('ModelCommentConnection'); | ||
// Check the Comment.commentPostId | ||
// Check the Comment.commentPostId inputs | ||
var commentCreateInput = getInputType(schemaDoc, graphql_transformer_common_1.ModelResourceIDs.ModelCreateInputObjectName('Comment')); | ||
var connectionId = commentCreateInput.fields.find(function (f) { return f.name.value === 'postId'; }); | ||
expect(connectionId).toBeTruthy(); | ||
expect(connectionId.type.kind).toEqual(graphql_1.Kind.NON_NULL_TYPE); | ||
var manyCommentId = commentCreateInput.fields.find(function (f) { return f.name.value === 'postManyCommentsId'; }); | ||
expect(manyCommentId).toBeTruthy(); | ||
expect(manyCommentId.type.kind).toEqual(graphql_1.Kind.NAMED_TYPE); | ||
var commentUpdateInput = getInputType(schemaDoc, graphql_transformer_common_1.ModelResourceIDs.ModelUpdateInputObjectName('Comment')); | ||
var connectionUpdateId = commentUpdateInput.fields.find(function (f) { return f.name.value === 'postId'; }); | ||
expect(connectionUpdateId).toBeTruthy(); | ||
expect(connectionUpdateId.type.kind).toEqual(graphql_1.Kind.NAMED_TYPE); | ||
// Check the post create type | ||
var postCreateInput = getInputType(schemaDoc, graphql_transformer_common_1.ModelResourceIDs.ModelCreateInputObjectName('Post')); | ||
var postConnectionId = postCreateInput.fields.find(function (f) { return f.name.value === 'postSingleCommentId'; }); | ||
expect(postConnectionId).toBeTruthy(); | ||
expect(postConnectionId.type.kind).toEqual(graphql_1.Kind.NON_NULL_TYPE); | ||
}); | ||
function expectFields(type, fields) { | ||
@@ -199,0 +241,0 @@ var _loop_1 = function (fieldName) { |
@@ -82,3 +82,5 @@ "use strict"; | ||
var leftConnectionIsList = graphql_transformer_common_1.isListType(field.type); | ||
var leftConnectionIsNonNull = graphql_transformer_common_1.isNonNullType(field.type); | ||
var rightConnectionIsList = associatedConnectionField ? graphql_transformer_common_1.isListType(associatedConnectionField.type) : undefined; | ||
var rightConnectionIsNonNull = associatedConnectionField ? graphql_transformer_common_1.isNonNullType(associatedConnectionField.type) : undefined; | ||
var connectionAttributeName = graphql_transformer_common_1.getDirectiveArgument(directive)("keyField"); | ||
@@ -124,3 +126,3 @@ // Relationship Cardinalities: | ||
if (createInput) { | ||
var updated_1 = definitions_1.updateCreateInputWithConnectionField(createInput, connectionAttributeName); | ||
var updated_1 = definitions_1.updateCreateInputWithConnectionField(createInput, connectionAttributeName, leftConnectionIsNonNull); | ||
ctx.putType(updated_1); | ||
@@ -176,3 +178,3 @@ } | ||
if (createInput) { | ||
var updated = definitions_1.updateCreateInputWithConnectionField(createInput, connectionAttributeName); | ||
var updated = definitions_1.updateCreateInputWithConnectionField(createInput, connectionAttributeName, leftConnectionIsNonNull); | ||
ctx.putType(updated); | ||
@@ -179,0 +181,0 @@ } |
{ | ||
"name": "graphql-connection-transformer", | ||
"version": "1.0.27", | ||
"version": "1.0.28-beta.0", | ||
"description": "An AppSync model transform for connecting objects.", | ||
@@ -21,6 +21,6 @@ "main": "lib/index.js", | ||
"graphql": "^0.13.2", | ||
"graphql-dynamodb-transformer": "^1.0.27", | ||
"graphql-mapping-template": "^1.0.27", | ||
"graphql-transformer-common": "^1.0.27", | ||
"graphql-transformer-core": "^1.0.27" | ||
"graphql-dynamodb-transformer": "^1.0.28-beta.0", | ||
"graphql-mapping-template": "^1.0.28-beta.0", | ||
"graphql-transformer-common": "^1.0.28-beta.0", | ||
"graphql-transformer-core": "^1.0.28-beta.0" | ||
}, | ||
@@ -32,3 +32,3 @@ "devDependencies": { | ||
"aws-sdk": "^2.259.1", | ||
"graphql-appsync-transformer": "^1.0.27", | ||
"graphql-appsync-transformer": "^1.0.28-beta.0", | ||
"jest": "^23.1.0", | ||
@@ -53,4 +53,3 @@ "ts-jest": "^22.4.6", | ||
] | ||
}, | ||
"gitHead": "c90740936a898d3975a7a99d5827c9d357be0efe" | ||
} | ||
} |
@@ -112,3 +112,3 @@ import { | ||
content: String! | ||
post: Post @connection(name: "PostComments", keyField: "postId") | ||
post: Post! @connection(name: "PostComments", keyField: "postId") | ||
} | ||
@@ -142,2 +142,3 @@ ` | ||
expect(connectionId).toBeTruthy() | ||
expect(connectionId.type.kind).toEqual(Kind.NON_NULL_TYPE) | ||
@@ -147,2 +148,3 @@ const commentUpdateInput = getInputType(schemaDoc, ModelResourceIDs.ModelUpdateInputObjectName('Comment')) | ||
expect(connectionUpdateId).toBeTruthy() | ||
expect(connectionUpdateId.type.kind).toEqual(Kind.NAMED_TYPE) | ||
}); | ||
@@ -296,2 +298,72 @@ | ||
test('Test ModelConnectionTransformer with non null @connections', () => { | ||
const validSchema = ` | ||
type Post @model { | ||
id: ID! | ||
title: String! | ||
createdAt: String | ||
updatedAt: String | ||
comments: [Comment] @connection(name: "PostComments", keyField: "postId") | ||
# A non null on the one in a 1-M does enforce a non-null | ||
# on the CreatePostInput | ||
singleComment: Comment! @connection | ||
# A non null on the many in a 1-M does not enforce a non-null | ||
# in the CommentCreateInput because it is not explicitly implied. | ||
manyComments: [Comment]! @connection | ||
} | ||
type Comment @model { | ||
id: ID! | ||
content: String! | ||
# A non-null on the one in 1-M again enforces a non null. | ||
post: Post! @connection(name: "PostComments", keyField: "postId") | ||
} | ||
` | ||
const transformer = new GraphQLTransform({ | ||
transformers: [ | ||
new AppSyncTransformer(), | ||
new DynamoDBModelTransformer(), | ||
new ModelConnectionTransformer() | ||
] | ||
}) | ||
const out = transformer.transform(validSchema); | ||
expect(out).toBeDefined() | ||
expect(out.Resources[ResolverResourceIDs.ResolverResourceID('Post', 'comments')]).toBeTruthy() | ||
const schemaDoc = parse(out.Resources[ResourceConstants.RESOURCES.GraphQLSchemaLogicalID].Properties.Definition) | ||
// Post.comments field | ||
const postType = getObjectType(schemaDoc, 'Post') | ||
expectFields(postType, ['comments']) | ||
const commentField = postType.fields.find(f => f.name.value === 'comments') | ||
expect(commentField.arguments.length).toEqual(4) | ||
expectArguments(commentField, ['filter', 'limit', 'nextToken', 'sortDirection']) | ||
expect(commentField.type.kind).toEqual(Kind.NAMED_TYPE) | ||
expect((commentField.type as any).name.value).toEqual('ModelCommentConnection') | ||
// Check the Comment.commentPostId | ||
// Check the Comment.commentPostId inputs | ||
const commentCreateInput = getInputType(schemaDoc, ModelResourceIDs.ModelCreateInputObjectName('Comment')) | ||
const connectionId = commentCreateInput.fields.find(f => f.name.value === 'postId') | ||
expect(connectionId).toBeTruthy() | ||
expect(connectionId.type.kind).toEqual(Kind.NON_NULL_TYPE) | ||
const manyCommentId = commentCreateInput.fields.find(f => f.name.value === 'postManyCommentsId') | ||
expect(manyCommentId).toBeTruthy() | ||
expect(manyCommentId.type.kind).toEqual(Kind.NAMED_TYPE) | ||
const commentUpdateInput = getInputType(schemaDoc, ModelResourceIDs.ModelUpdateInputObjectName('Comment')) | ||
const connectionUpdateId = commentUpdateInput.fields.find(f => f.name.value === 'postId') | ||
expect(connectionUpdateId).toBeTruthy() | ||
expect(connectionUpdateId.type.kind).toEqual(Kind.NAMED_TYPE) | ||
// Check the post create type | ||
const postCreateInput = getInputType(schemaDoc, ModelResourceIDs.ModelCreateInputObjectName('Post')) | ||
const postConnectionId = postCreateInput.fields.find(f => f.name.value === 'postSingleCommentId') | ||
expect(postConnectionId).toBeTruthy() | ||
expect(postConnectionId.type.kind).toEqual(Kind.NON_NULL_TYPE) | ||
}); | ||
function expectFields(type: ObjectTypeDefinitionNode, fields: string[]) { | ||
@@ -298,0 +370,0 @@ for (const fieldName of fields) { |
@@ -18,3 +18,3 @@ import { Transformer, TransformerContext, InvalidDirectiveError } from 'graphql-transformer-core' | ||
getBaseType, isListType, getDirectiveArgument, blankObject, | ||
toCamelCase | ||
toCamelCase, isNonNullType | ||
} from 'graphql-transformer-common' | ||
@@ -103,3 +103,5 @@ import { ResolverResourceIDs, ModelResourceIDs } from 'graphql-transformer-common' | ||
const leftConnectionIsList = isListType(field.type) | ||
const leftConnectionIsNonNull = isNonNullType(field.type) | ||
const rightConnectionIsList = associatedConnectionField ? isListType(associatedConnectionField.type) : undefined | ||
const rightConnectionIsNonNull = associatedConnectionField ? isNonNullType(associatedConnectionField.type) : undefined | ||
@@ -160,3 +162,3 @@ let connectionAttributeName = getDirectiveArgument(directive)("keyField") | ||
if (createInput) { | ||
const updated = updateCreateInputWithConnectionField(createInput, connectionAttributeName) | ||
const updated = updateCreateInputWithConnectionField(createInput, connectionAttributeName, leftConnectionIsNonNull) | ||
ctx.putType(updated) | ||
@@ -227,3 +229,3 @@ } | ||
if (createInput) { | ||
const updated = updateCreateInputWithConnectionField(createInput, connectionAttributeName) | ||
const updated = updateCreateInputWithConnectionField(createInput, connectionAttributeName, leftConnectionIsNonNull) | ||
ctx.putType(updated) | ||
@@ -230,0 +232,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1600
118668
20
2