Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-amplify/graphql-default-value-transformer

Package Overview
Dependencies
Maintainers
7
Versions
378
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-amplify/graphql-default-value-transformer - npm Package Compare versions

Comparing version 0.5.4-beta.0 to 0.5.4

13

CHANGELOG.md

@@ -6,19 +6,16 @@ # Change Log

## [0.5.4-beta.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-default-value-transformer@0.5.1...@aws-amplify/graphql-default-value-transformer@0.5.4-beta.0) (2021-11-17)
## [0.5.4](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-default-value-transformer@0.5.3...@aws-amplify/graphql-default-value-transformer@0.5.4) (2021-11-21)
**Note:** Version bump only for package @aws-amplify/graphql-default-value-transformer
### Bug Fixes
* **graphql-default-value-transformer:** handle null same way as undefined with [@default](https://github.com/default) ([#8836](https://github.com/aws-amplify/amplify-cli/issues/8836)) ([7e3f491](https://github.com/aws-amplify/amplify-cli/commit/7e3f491094850b44a5ce788b01d1ac694c6b2766))
## [0.5.3](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-default-value-transformer@0.5.2...@aws-amplify/graphql-default-value-transformer@0.5.3) (2021-11-19)
## [0.5.3-beta.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-default-value-transformer@0.5.1...@aws-amplify/graphql-default-value-transformer@0.5.3-beta.0) (2021-11-17)
### Bug Fixes
* **graphql-default-value-transformer:** handle null same way as undefined with [@default](https://github.com/default) ([#8836](https://github.com/aws-amplify/amplify-cli/issues/8836)) ([7e3f491](https://github.com/aws-amplify/amplify-cli/commit/7e3f491094850b44a5ce788b01d1ac694c6b2766))
* **graphql-default-value-transformer:** support for [@default](https://github.com/default) directive for required fields ([#8906](https://github.com/aws-amplify/amplify-cli/issues/8906)) ([dc0179d](https://github.com/aws-amplify/amplify-cli/commit/dc0179d69433db0f838d21ebc849b595f4c60c82))

@@ -29,3 +26,3 @@

## [0.5.2-beta.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-default-value-transformer@0.5.1...@aws-amplify/graphql-default-value-transformer@0.5.2-beta.0) (2021-11-17)
## [0.5.2](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-default-value-transformer@0.5.1...@aws-amplify/graphql-default-value-transformer@0.5.2) (2021-11-17)

@@ -32,0 +29,0 @@

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

@@ -8,2 +8,3 @@ export declare class DefaultValueTransformer extends TransformerPluginBase {

field: (parent: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode, definition: FieldDefinitionNode, directive: DirectiveNode, ctx: TransformerSchemaVisitStepContextProvider) => void;
transformSchema: (ctx: TransformerTransformSchemaStepContextProvider) => void;
generateResolvers: (ctx: TransformerContextProvider) => void;

@@ -10,0 +11,0 @@ private makeDefaultValueSnippet;

@@ -31,2 +31,12 @@ "use strict";

};
this.transformSchema = (ctx) => {
for (const typeName of this.directiveMap.keys()) {
const name = graphql_transformer_common_1.ModelResourceIDs.ModelCreateInputObjectName(typeName);
for (const config of this.directiveMap.get(typeName)) {
const input = graphql_transformer_core_1.InputObjectDefinitionWrapper.fromObject(name, config.object, ctx.inputDocument);
const fieldWrapper = input.fields.find(f => f.name === config.field.name.value);
fieldWrapper === null || fieldWrapper === void 0 ? void 0 : fieldWrapper.makeNullable();
}
}
};
this.generateResolvers = (ctx) => {

@@ -80,5 +90,2 @@ const context = ctx;

}
if (graphql_transformer_common_1.isNonNullType(type)) {
throw new graphql_transformer_core_1.InvalidDirectiveError('The @default directive cannot be added to required fields.');
}
}

@@ -85,0 +92,0 @@ function validateDirectiveArguments(directive) {

{
"name": "@aws-amplify/graphql-default-value-transformer",
"version": "0.5.4-beta.0",
"version": "0.5.4",
"description": "Amplify GraphQL default value transformer",

@@ -31,7 +31,7 @@ "repository": {

"dependencies": {
"@aws-amplify/graphql-transformer-core": "0.13.2-beta.0",
"@aws-amplify/graphql-transformer-interfaces": "1.12.4-beta.0",
"@aws-amplify/graphql-transformer-core": "0.13.2",
"@aws-amplify/graphql-transformer-interfaces": "1.12.3",
"graphql": "^14.5.8",
"graphql-mapping-template": "4.20.1",
"graphql-transformer-common": "4.22.4-beta.0",
"graphql-transformer-common": "4.22.2",
"libphonenumber-js": "^1.7.31"

@@ -58,3 +58,3 @@ },

},
"gitHead": "c6a97a5a6512e8c723a500ae7288be6af6afe6d5"
"gitHead": "8a18fcbdf12deeaf4f6d11c6b0baef8b9011167d"
}

@@ -253,7 +253,7 @@ import { ModelTransformer } from '@aws-amplify/graphql-model-transformer';

it('throws if @default is used on a required field.', () => {
const schema = `
it('should be supported on a required field.', () => {
const inputSchema = `
type Test @model {
id: ID!
value: AWSIPAddress! @default(value: "text")
stringValue: String! @default(value: "hello world")
}

@@ -266,5 +266,8 @@ `;

expect(() => {
transformer.transform(schema);
}).toThrow('The @default directive cannot be added to required fields.');
const out = transformer.transform(inputSchema);
expect(out).toBeDefined();
expect(out.schema).toMatchSnapshot();
const schema = parse(out.schema);
validateModelSchema(schema);
});

@@ -271,0 +274,0 @@

@@ -1,6 +0,13 @@

import { DirectiveWrapper, InvalidDirectiveError, MappingTemplate, TransformerPluginBase } from '@aws-amplify/graphql-transformer-core';
import {
DirectiveWrapper,
InvalidDirectiveError,
MappingTemplate,
TransformerPluginBase,
InputObjectDefinitionWrapper,
} from '@aws-amplify/graphql-transformer-core';
import {
TransformerContextProvider,
TransformerResolverProvider,
TransformerSchemaVisitStepContextProvider,
TransformerTransformSchemaStepContextProvider,
} from '@aws-amplify/graphql-transformer-interfaces';

@@ -18,3 +25,3 @@ import {

import { methodCall, printBlock, qref, raw, ref, str } from 'graphql-mapping-template';
import { getBaseType, isEnum, isListType, isNonNullType, isScalarOrEnum } from 'graphql-transformer-common';
import { getBaseType, isEnum, isListType, isScalarOrEnum, ModelResourceIDs } from 'graphql-transformer-common';
import { DefaultValueDirectiveConfiguration } from './types';

@@ -31,3 +38,3 @@ import { TypeValidators } from './validators';

export class DefaultValueTransformer extends TransformerPluginBase {
private directiveMap = new Map<String, DefaultValueDirectiveConfiguration[]>();
private directiveMap = new Map<string, DefaultValueDirectiveConfiguration[]>();

@@ -59,2 +66,13 @@ constructor() {

transformSchema = (ctx: TransformerTransformSchemaStepContextProvider) => {
for (const typeName of this.directiveMap.keys()) {
const name = ModelResourceIDs.ModelCreateInputObjectName(typeName);
for (const config of this.directiveMap.get(typeName)!) {
const input = InputObjectDefinitionWrapper.fromObject(name, config.object, ctx.inputDocument);
const fieldWrapper = input.fields.find(f => f.name === config.field.name.value);
fieldWrapper?.makeNullable();
}
}
};
generateResolvers = (ctx: TransformerContextProvider): void => {

@@ -129,6 +147,2 @@ const context = ctx as TransformerContextProvider;

}
if (isNonNullType(type)) {
throw new InvalidDirectiveError('The @default directive cannot be added to required fields.');
}
}

@@ -135,0 +149,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc