graphql-versioned-transformer
Advanced tools
Comparing version 1.0.12 to 1.0.13-publish-test.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="1.0.13-publish-test.0"></a> | ||
## [1.0.13-publish-test.0](https://github.com/aws-amplify/amplify-cli/compare/graphql-versioned-transformer@1.0.12...graphql-versioned-transformer@1.0.13-publish-test.0) (2018-10-03) | ||
### Bug Fixes | ||
* **graphql-versioned-transformer:** Remove unused imports ([0975ad1](https://github.com/aws-amplify/amplify-cli/commit/0975ad1)) | ||
<a name="1.0.12"></a> | ||
@@ -8,0 +19,0 @@ ## [1.0.12](https://github.com/aws-amplify/amplify-cli/compare/graphql-versioned-transformer@1.0.11...graphql-versioned-transformer@1.0.12) (2018-08-23) |
@@ -62,3 +62,4 @@ "use strict"; | ||
var out = transformer.transform(validSchema); | ||
var schemaDoc = graphql_1.parse(out.Resources[graphql_transformer_common_1.ResourceConstants.RESOURCES.GraphQLSchemaLogicalID].Properties.Definition); | ||
var sdl = out.Resources[graphql_transformer_common_1.ResourceConstants.RESOURCES.GraphQLSchemaLogicalID].Properties.Definition; | ||
var schemaDoc = graphql_1.parse(sdl); | ||
var versionField = getField(getType(schemaDoc)('Post'), 'version'); | ||
@@ -65,0 +66,0 @@ expect(versionField).toBeDefined(); |
@@ -52,3 +52,3 @@ "use strict"; | ||
if (!modelDirective) { | ||
throw new graphql_transformer_core_1.InvalidDirectiveError('Types annotated with @auth must also be annotated with @model.'); | ||
throw new graphql_transformer_core_1.InvalidDirectiveError('Types annotated with @versioned must also be annotated with @model.'); | ||
} | ||
@@ -162,3 +162,3 @@ var isArg = function (s) { return function (arg) { return arg.name.value === s; }; }; | ||
var updatedFields = input.fields.concat([ | ||
graphql_transformer_common_1.makeArg(versionInput, graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType("Int"))) | ||
graphql_transformer_common_1.makeInputValueDefinition(versionInput, graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType("Int"))) | ||
]); | ||
@@ -172,4 +172,5 @@ var updatedInput = __assign({}, input, { fields: updatedFields }); | ||
if (type && type.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION) { | ||
var updatedFields = type.fields; | ||
var versionFieldImpl = type.fields.find(function (f) { return f.name.value === versionField; }); | ||
var updatedField = versionFieldImpl; | ||
var updatedField_1 = versionFieldImpl; | ||
if (versionFieldImpl) { | ||
@@ -180,3 +181,4 @@ var baseType = graphql_transformer_common_1.getBaseType(versionFieldImpl.type); | ||
if (versionFieldImpl.type.kind !== graphql_1.Kind.NON_NULL_TYPE) { | ||
updatedField = __assign({}, updatedField, { type: graphql_transformer_common_1.makeNonNullType(versionFieldImpl.type) }); | ||
updatedField_1 = __assign({}, updatedField_1, { type: graphql_transformer_common_1.makeNonNullType(versionFieldImpl.type) }); | ||
updatedFields = updatedFields.map(function (f) { return f.name.value === versionField ? updatedField_1 : f; }); | ||
} | ||
@@ -189,7 +191,7 @@ } | ||
else { | ||
updatedField = graphql_transformer_common_1.makeField(versionField, [], graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('Int'))); | ||
updatedField_1 = graphql_transformer_common_1.makeField(versionField, [], graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('Int'))); | ||
updatedFields = updatedFields.concat([ | ||
updatedField_1 | ||
]); | ||
} | ||
var updatedFields = type.fields.concat([ | ||
updatedField | ||
]); | ||
var updatedType = __assign({}, type, { fields: updatedFields }); | ||
@@ -196,0 +198,0 @@ ctx.putType(updatedType); |
{ | ||
"name": "graphql-versioned-transformer", | ||
"version": "1.0.12", | ||
"version": "1.0.13-publish-test.0", | ||
"description": "A GraphQL transform that enabled object versioning and conflict resolution for a @model type.", | ||
@@ -9,4 +9,3 @@ "main": "lib/index.js", | ||
"build": "tsc", | ||
"clean": "rm -rf ./lib", | ||
"lint": "tslint -p ./tslint.json" | ||
"clean": "rm -rf ./lib" | ||
}, | ||
@@ -23,5 +22,5 @@ "keywords": [ | ||
"graphql": "^0.13.2", | ||
"graphql-mapping-template": "^1.0.12", | ||
"graphql-transformer-common": "^1.0.12", | ||
"graphql-transformer-core": "^1.0.12" | ||
"graphql-mapping-template": "^1.0.13-publish-test.0", | ||
"graphql-transformer-common": "^1.0.13-publish-test.0", | ||
"graphql-transformer-core": "^1.0.13-publish-test.0" | ||
}, | ||
@@ -33,4 +32,4 @@ "devDependencies": { | ||
"aws-sdk": "^2.259.1", | ||
"graphql-appsync-transformer": "^1.0.12", | ||
"graphql-dynamodb-transformer": "^1.0.12", | ||
"graphql-appsync-transformer": "^1.0.13-publish-test.0", | ||
"graphql-dynamodb-transformer": "^1.0.13-publish-test.0", | ||
"jest": "^23.1.0", | ||
@@ -37,0 +36,0 @@ "ts-jest": "^22.4.6", |
import { | ||
ObjectTypeDefinitionNode, parse, FieldDefinitionNode, DocumentNode, | ||
DefinitionNode, Kind, TypeDefinitionNode, InputObjectTypeDefinitionNode | ||
ObjectTypeDefinitionNode, parse, DocumentNode, | ||
Kind, InputObjectTypeDefinitionNode | ||
} from 'graphql' | ||
import GraphQLTransform, { TransformerContractError } from 'graphql-transformer-core' | ||
import { ResourceConstants, ModelResourceIDs, ResolverResourceIDs } from 'graphql-transformer-common' | ||
import GraphQLTransform from 'graphql-transformer-core' | ||
import { ResourceConstants } from 'graphql-transformer-common' | ||
import { VersionedModelTransformer } from '../VersionedModelTransformer' | ||
@@ -11,6 +11,6 @@ import AppSyncTransformer from 'graphql-appsync-transformer' | ||
const getInputType = (schemaDoc: DocumentNode) => (name: string): InputObjectTypeDefinitionNode => | ||
schemaDoc.definitions.find(d => d.kind !== Kind.SCHEMA_DEFINITION ? d.name.value === name : false) as InputObjectTypeDefinitionNode | ||
const getInputType = (schemaDoc: DocumentNode) => (name: string): InputObjectTypeDefinitionNode => | ||
schemaDoc.definitions.find(d => d.kind !== Kind.SCHEMA_DEFINITION ? d.name.value === name : false) as InputObjectTypeDefinitionNode | ||
const getInputField = (input: InputObjectTypeDefinitionNode, field: string) => input.fields.find(f => f.name.value === field) | ||
const getType = (schemaDoc: DocumentNode) => (name: string): ObjectTypeDefinitionNode => | ||
const getType = (schemaDoc: DocumentNode) => (name: string): ObjectTypeDefinitionNode => | ||
schemaDoc.definitions.find(d => d.kind !== Kind.SCHEMA_DEFINITION ? d.name.value === name : false) as ObjectTypeDefinitionNode | ||
@@ -90,3 +90,4 @@ const getField = (input: ObjectTypeDefinitionNode, field: string) => input.fields.find(f => f.name.value === field) | ||
const out = transformer.transform(validSchema); | ||
const schemaDoc = parse(out.Resources[ResourceConstants.RESOURCES.GraphQLSchemaLogicalID].Properties.Definition) | ||
const sdl = out.Resources[ResourceConstants.RESOURCES.GraphQLSchemaLogicalID].Properties.Definition | ||
const schemaDoc = parse(sdl) | ||
const versionField = getField(getType(schemaDoc)('Post'), 'version') | ||
@@ -93,0 +94,0 @@ expect(versionField).toBeDefined() |
@@ -10,8 +10,7 @@ import { Transformer, TransformerContext, InvalidDirectiveError, TransformerContractError } from "graphql-transformer-core"; | ||
import { printBlock, compoundExpression, set, ref, qref, obj, str, raw } from 'graphql-mapping-template' | ||
import { | ||
ResourceConstants, blankObject, makeSchema, | ||
makeOperationType, | ||
import { | ||
ResourceConstants, | ||
ModelResourceIDs, | ||
ResolverResourceIDs, | ||
makeArg, | ||
makeInputValueDefinition, | ||
makeNonNullType, | ||
@@ -35,5 +34,5 @@ makeNamedType, | ||
* When a type is annotated with @versioned enable conflict resolution for the type. | ||
* | ||
* | ||
* Usage: | ||
* | ||
* | ||
* type Post @model @versioned(versionField: "version", versionInput: "expectedVersion") { | ||
@@ -44,6 +43,6 @@ * id: ID! | ||
* } | ||
* | ||
* Enabling conflict resolution automatically manages a "version" attribute in | ||
* | ||
* Enabling conflict resolution automatically manages a "version" attribute in | ||
* the @model type's DynamoDB table and injects a conditional expression into | ||
* the types mutations that actually perform the conflict resolutions by | ||
* the types mutations that actually perform the conflict resolutions by | ||
* checking the "version" attribute in the table with the "expectedVersion" passed | ||
@@ -56,3 +55,3 @@ * by the user. | ||
if (!modelDirective) { | ||
throw new InvalidDirectiveError('Types annotated with @auth must also be annotated with @model.') | ||
throw new InvalidDirectiveError('Types annotated with @versioned must also be annotated with @model.') | ||
} | ||
@@ -82,5 +81,5 @@ | ||
* Set the "version" to 1. | ||
* @param ctx | ||
* @param versionField | ||
* @param versionInput | ||
* @param ctx | ||
* @param versionField | ||
* @param versionInput | ||
*/ | ||
@@ -102,5 +101,5 @@ private augmentCreateMutation(ctx: TransformerContext, typeName: string, versionField: string, versionInput: string) { | ||
* the object versions. | ||
* @param ctx | ||
* @param versionField | ||
* @param versionInput | ||
* @param ctx | ||
* @param versionField | ||
* @param versionInput | ||
*/ | ||
@@ -210,3 +209,3 @@ private augmentDeleteMutation(ctx: TransformerContext, typeName: string, versionField: string, versionInput: string) { | ||
...input.fields, | ||
makeArg(versionInput, makeNonNullType(makeNamedType("Int"))) | ||
makeInputValueDefinition(versionInput, makeNonNullType(makeNamedType("Int"))) | ||
] | ||
@@ -220,3 +219,3 @@ const updatedInput = { | ||
} | ||
private enforceVersionedFieldOnType( | ||
@@ -229,2 +228,3 @@ ctx: TransformerContext, | ||
if (type && type.kind === Kind.OBJECT_TYPE_DEFINITION) { | ||
let updatedFields = type.fields | ||
const versionFieldImpl = type.fields.find(f => f.name.value === versionField) | ||
@@ -241,2 +241,5 @@ let updatedField = versionFieldImpl | ||
} | ||
updatedFields = updatedFields.map( | ||
f => f.name.value === versionField ? updatedField : f | ||
) | ||
} | ||
@@ -248,7 +251,7 @@ } else { | ||
updatedField = makeField(versionField, [], makeNonNullType(makeNamedType('Int'))) | ||
updatedFields = [ | ||
...updatedFields, | ||
updatedField | ||
] | ||
} | ||
const updatedFields = [ | ||
...type.fields, | ||
updatedField | ||
] | ||
const updatedType = { | ||
@@ -255,0 +258,0 @@ ...type, |
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
47315
682
2