Skip to content

Commit

Permalink
refactor: move directive definitions to a single source of truth (#2342)
Browse files Browse the repository at this point in the history
Create new package @aws-amplify/graphql-directives
  • Loading branch information
dpilch authored Mar 27, 2024
1 parent ef6f53c commit 3346677
Show file tree
Hide file tree
Showing 118 changed files with 1,936 additions and 430 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"@aws-amplify/graphql-api-construct/zod",
"@aws-amplify/graphql-api-construct/@aws-amplify/graphql-auth-transformer",
"@aws-amplify/graphql-api-construct/@aws-amplify/graphql-default-value-transformer",
"@aws-amplify/graphql-api-construct/@aws-amplify/graphql-directives",
"@aws-amplify/graphql-api-construct/@aws-amplify/graphql-function-transformer",
"@aws-amplify/graphql-api-construct/@aws-amplify/graphql-http-transformer",
"@aws-amplify/graphql-api-construct/@aws-amplify/graphql-index-transformer",
Expand Down Expand Up @@ -143,6 +144,7 @@
"@aws-amplify/data-construct/zod",
"@aws-amplify/data-construct/@aws-amplify/graphql-auth-transformer",
"@aws-amplify/data-construct/@aws-amplify/graphql-default-value-transformer",
"@aws-amplify/data-construct/@aws-amplify/graphql-directives",
"@aws-amplify/data-construct/@aws-amplify/graphql-function-transformer",
"@aws-amplify/data-construct/@aws-amplify/graphql-http-transformer",
"@aws-amplify/data-construct/@aws-amplify/graphql-index-transformer",
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-data-construct/.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@aws-amplify/backend-output-storage": "^0.2.2",
"@aws-amplify/graphql-auth-transformer": "3.4.1",
"@aws-amplify/graphql-default-value-transformer": "2.3.1",
"@aws-amplify/graphql-directives": "1.0.0",
"@aws-amplify/graphql-function-transformer": "2.1.18",
"@aws-amplify/graphql-http-transformer": "2.1.18",
"@aws-amplify/graphql-index-transformer": "2.3.7",
Expand Down Expand Up @@ -3534,5 +3535,5 @@
},
"types": {},
"version": "1.6.0",
"fingerprint": "bltwvDHncl6fGB0rcExcJfIVQhpCm6cS02qM4TBqm0U="
"fingerprint": "wAUmFljef6wr5+hst88y7j8MkILf+dkTlVPYMpcG9GU="
}
1 change: 1 addition & 0 deletions packages/amplify-data-construct/nonJsiiDependencies.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
"@aws-amplify/backend-output-storage",
"@aws-amplify/backend-output-schemas",
"@aws-amplify/graphql-directives",
"@aws-amplify/graphql-transformer",
"@aws-amplify/graphql-transformer-core",
"@aws-amplify/graphql-transformer-interfaces",
Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-data-construct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"zod",
"@aws-amplify/graphql-auth-transformer",
"@aws-amplify/graphql-default-value-transformer",
"@aws-amplify/graphql-directives",
"@aws-amplify/graphql-function-transformer",
"@aws-amplify/graphql-http-transformer",
"@aws-amplify/graphql-index-transformer",
Expand Down Expand Up @@ -77,6 +78,7 @@
"@aws-amplify/graphql-api-construct": "1.6.0",
"@aws-amplify/graphql-auth-transformer": "3.4.1",
"@aws-amplify/graphql-default-value-transformer": "2.3.1",
"@aws-amplify/graphql-directives": "1.0.0",
"@aws-amplify/graphql-function-transformer": "2.1.18",
"@aws-amplify/graphql-http-transformer": "2.1.18",
"@aws-amplify/graphql-index-transformer": "2.3.7",
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-graphql-api-construct/.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@aws-amplify/backend-output-storage": "^0.2.2",
"@aws-amplify/graphql-auth-transformer": "3.4.1",
"@aws-amplify/graphql-default-value-transformer": "2.3.1",
"@aws-amplify/graphql-directives": "1.0.0",
"@aws-amplify/graphql-function-transformer": "2.1.18",
"@aws-amplify/graphql-http-transformer": "2.1.18",
"@aws-amplify/graphql-index-transformer": "2.3.7",
Expand Down Expand Up @@ -8132,5 +8133,5 @@
}
},
"version": "1.6.0",
"fingerprint": "C0VXkxPFCBh6W1H9yfqkeGmab7zndoRgpNOmXR6IjoM="
"fingerprint": "FjoH8icW+tbFrS9JKLZc/+5mZIGwfLRkRZUx4VizFKI="
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
"@aws-amplify/backend-output-storage",
"@aws-amplify/backend-output-schemas",
"@aws-amplify/graphql-directives",
"@aws-amplify/graphql-transformer",
"@aws-amplify/graphql-transformer-core",
"@aws-amplify/graphql-transformer-interfaces",
Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-graphql-api-construct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@aws-amplify/backend-output-storage",
"@aws-amplify/graphql-auth-transformer",
"@aws-amplify/graphql-default-value-transformer",
"@aws-amplify/graphql-directives",
"@aws-amplify/graphql-function-transformer",
"@aws-amplify/graphql-http-transformer",
"@aws-amplify/graphql-index-transformer",
Expand Down Expand Up @@ -77,6 +78,7 @@
"@aws-amplify/backend-output-storage": "^0.2.2",
"@aws-amplify/graphql-auth-transformer": "3.4.1",
"@aws-amplify/graphql-default-value-transformer": "2.3.1",
"@aws-amplify/graphql-directives": "1.0.0",
"@aws-amplify/graphql-function-transformer": "2.1.18",
"@aws-amplify/graphql-http-transformer": "2.1.18",
"@aws-amplify/graphql-index-transformer": "2.3.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-graphql-auth-transformer/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface AuthDirective {
}

// @public (undocumented)
export const authDirectiveDefinition = "\n directive @auth(rules: [AuthRule!]!) on OBJECT | FIELD_DEFINITION\n input AuthRule {\n allow: AuthStrategy!\n provider: AuthProvider\n identityClaim: String\n groupClaim: String\n ownerField: String\n groupsField: String\n groups: [String]\n operations: [ModelOperation]\n }\n enum AuthStrategy {\n owner\n groups\n private\n public\n custom\n }\n enum AuthProvider {\n apiKey\n iam\n oidc\n userPools\n function\n }\n enum ModelOperation {\n create\n update\n delete\n read\n list\n get\n sync\n listen\n search\n }\n";
export const authDirectiveDefinition: string;

// @public (undocumented)
export type AuthProvider = 'apiKey' | 'iam' | 'oidc' | 'userPools' | 'function';
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-graphql-auth-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"extract-api": "ts-node ../../scripts/extract-api.ts"
},
"dependencies": {
"@aws-amplify/graphql-directives": "1.0.0",
"@aws-amplify/graphql-model-transformer": "2.6.0",
"@aws-amplify/graphql-relational-transformer": "2.4.1",
"@aws-amplify/graphql-transformer-core": "2.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
getSortKeyConnectionAttributeName,
getObjectPrimaryKey,
} from '@aws-amplify/graphql-relational-transformer';
import { AuthDirective } from '@aws-amplify/graphql-directives';
import { AccessControlMatrix } from './accesscontrol';
import {
AUTH_PROVIDER_DIRECTIVE_MAP,
Expand All @@ -75,7 +76,6 @@ import {
MODEL_OPERATIONS,
SEARCHABLE_AGGREGATE_TYPES,
AuthRule,
authDirectiveDefinition,
ConfiguredAuthProviders,
getConfiguredAuthProviders,
collectFieldNames,
Expand Down Expand Up @@ -181,7 +181,7 @@ export class AuthTransformer extends TransformerAuthBase implements TransformerA
* constructor for creating AuthTransformer
*/
constructor() {
super('amplify-auth-transformer', authDirectiveDefinition);
super('amplify-auth-transformer', AuthDirective.definition);
this.modelDirectiveConfig = new Map();
this.seenNonModelTypes = new Map();
this.authModelConfig = new Map();
Expand Down
40 changes: 2 additions & 38 deletions packages/amplify-graphql-auth-transformer/src/utils/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GetArgumentsOptions } from '@aws-amplify/graphql-transformer-core';
import { AuthDirective } from '@aws-amplify/graphql-directives';

/**
* AuthStrategy
Expand Down Expand Up @@ -104,41 +105,4 @@ export interface ConfiguredAuthProviders {
shouldAddDefaultServiceDirective: boolean;
}

export const authDirectiveDefinition = `
directive @auth(rules: [AuthRule!]!) on OBJECT | FIELD_DEFINITION
input AuthRule {
allow: AuthStrategy!
provider: AuthProvider
identityClaim: String
groupClaim: String
ownerField: String
groupsField: String
groups: [String]
operations: [ModelOperation]
}
enum AuthStrategy {
owner
groups
private
public
custom
}
enum AuthProvider {
apiKey
iam
oidc
userPools
function
}
enum ModelOperation {
create
update
delete
read
list
get
sync
listen
search
}
`;
export const authDirectiveDefinition = AuthDirective.definition;
1 change: 1 addition & 0 deletions packages/amplify-graphql-auth-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"outDir": "lib"
},
"references": [
{ "path": "../amplify-graphql-directives" },
{ "path": "../amplify-graphql-transformer-interfaces" },
{ "path": "../amplify-graphql-transformer-core" },
{ "path": "../amplify-graphql-model-transformer" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"extract-api": "ts-node ../../scripts/extract-api.ts"
},
"dependencies": {
"@aws-amplify/graphql-directives": "1.0.0",
"@aws-amplify/graphql-transformer-core": "2.5.0",
"@aws-amplify/graphql-transformer-interfaces": "3.4.0",
"graphql": "^15.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
TransformerSchemaVisitStepContextProvider,
TransformerTransformSchemaStepContextProvider,
} from '@aws-amplify/graphql-transformer-interfaces';
import { DefaultDirective } from '@aws-amplify/graphql-directives';
import {
DirectiveNode,
EnumTypeDefinitionNode,
Expand All @@ -28,11 +29,6 @@ import { getBaseType, isEnum, isListType, isScalarOrEnum, ModelResourceIDs, toCa
import { DefaultValueDirectiveConfiguration } from './types';
import { TypeValidators } from './validators';

const directiveName = 'default';
const directiveDefinition = `
directive @${directiveName}(value: String!) on FIELD_DEFINITION
`;

const nonStringTypes = ['Int', 'Float', 'Boolean', 'AWSTimestamp', 'AWSJSON'];

const validateFieldType = (ctx: TransformerSchemaVisitStepContextProvider, type: TypeNode): void => {
Expand Down Expand Up @@ -93,7 +89,7 @@ export class DefaultValueTransformer extends TransformerPluginBase {
private directiveMap = new Map<string, DefaultValueDirectiveConfiguration[]>();

constructor() {
super('amplify-default-value-transformer', directiveDefinition);
super('amplify-default-value-transformer', DefaultDirective.definition);
}

field = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"rootDir": "src",
"outDir": "lib"
},
"references": [{ "path": "../amplify-graphql-transformer-interfaces" }, { "path": "../graphql-mapping-template" }]
"references": [
{ "path": "../amplify-graphql-directives" },
{ "path": "../amplify-graphql-transformer-interfaces" },
{ "path": "../graphql-mapping-template" }
]
}
5 changes: 5 additions & 0 deletions packages/amplify-graphql-directives/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/__mocks__/**
**/__tests__/**
src
tsconfig.json
tsconfig.tsbuildinfo
Loading

0 comments on commit 3346677

Please sign in to comment.