Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@aws-amplify/data-construct
Advanced tools
AppSync GraphQL Api Construct using Amplify GraphQL Transformer - Aliased to use `Data` name scheme.
This package vends an L3 CDK Construct wrapping the behavior of the Amplify GraphQL Transformer. This enables quick development and interation of AppSync APIs which support the Amplify GraphQL Directives. For more information on schema modeling in GraphQL, please refer to the amplify developer docs.
The primary way to use this construct is to invoke it with a provided schema (either as an inline graphql string, or as one or more appsync.SchemaFile
) objects, and with authorization config provided. There are 5 supported methods for authorization of an AppSync API, all of which are supported by this construct. For more information on authorization rule definitions in Amplify, refer to the authorization docs. Note: currently at least one authorization rule is required, and if multiple are specified, a defaultAuthorizationMode
must be specified on the api as well. Specified authorization modes must be a superset of those configured in the graphql schema.
In this example, we create a single model, which will use user pool
auth in order to allow logged in users to create and manage their own todos
privately.
We create a cdk App and Stack, though you may be deploying this to a custom stack, this is purely illustrative for a concise demo.
We then wire this through to import a user pool which was already deployed (creating and deploying is out of scope for this example).
import { App, Stack } from 'aws-cdk-lib';
import { UserPool } from 'aws-cdk-lib/aws-cognito';
import { AmplifyData, AmplifyDataDefinition } from '@aws-amplify/data-construct';
const app = new App();
const stack = new Stack(app, 'TodoStack');
new AmplifyData(stack, 'TodoApp', {
definition: AmplifyDataDefinition.fromString(/* GraphQL */ `
type Todo @model @auth(rules: [{ allow: owner }]) {
description: String!
completed: Boolean
}
`),
authorizationModes: {
userPoolConfig: {
userPool: UserPool.fromUserPoolId(stack, 'ImportedUserPool', '<YOUR_USER_POOL_ID>'),
},
},
});
In this example, we create a two related models, which will use which logged in users in the 'Author' and 'Admin' user groups will have full access to, and customers requesting with api key will only have read permissions on.
import { App, Stack } from 'aws-cdk-lib';
import { UserPool } from 'aws-cdk-lib/aws-cognito';
import { AmplifyData, AmplifyDataDefinition } from '@aws-amplify/data-construct';
const app = new App();
const stack = new Stack(app, 'BlogStack');
new AmplifyData(stack, 'BlogApp', {
definition: AmplifyDataDefinition.fromString(/* GraphQL */ `
type Blog @model @auth(rules: [{ allow: public, operations: [read] }, { allow: groups, groups: ["Author", "Admin"] }]) {
title: String!
description: String
posts: [Post] @hasMany
}
type Post @model @auth(rules: [{ allow: public, operations: [read] }, { allow: groups, groups: ["Author", "Admin"] }]) {
title: String!
content: [String]
blog: Blog @belongsTo
}
`),
authorizationModes: {
defaultAuthorizationMode: 'API_KEY',
apiKeyConfig: {
description: 'Api Key for public access',
expires: cdk.Duration.days(7),
},
userPoolConfig: {
userPool: UserPool.fromUserPoolId(stack, 'ImportedUserPool', '<YOUR_USER_POOL_ID>'),
},
},
});
In this example, we import the schema definition itself from one or more local file, rather than an inline graphql string.
# todo.graphql
type Todo @model @auth(rules: [{ allow: owner }]) {
content: String!
done: Boolean
}
# blog.graphql
type Blog @model @auth(rules: [{ allow: owner }, { allow: public, operations: [read] }]) {
title: String!
description: String
posts: [Post] @hasMany
}
type Post @model @auth(rules: [{ allow: owner }, { allow: public, operations: [read] }]) {
title: String!
content: [String]
blog: Blog @belongsTo
}
// app.ts
import { App, Stack } from 'aws-cdk-lib';
import { UserPool } from 'aws-cdk-lib/aws-cognito';
import { AmplifyData, AmplifyDataDefinition } from '@aws-amplify/data-construct';
const app = new App();
const stack = new Stack(app, 'MultiFileStack');
new AmplifyData(stack, 'MultiFileDefinition', {
definition: AmplifyDataDefinition.fromFiles(path.join(__dirname, 'todo.graphql'), path.join(__dirname, 'blog.graphql')),
authorizationModes: {
defaultAuthorizationMode: 'API_KEY',
apiKeyConfig: {
description: 'Api Key for public access',
expires: cdk.Duration.days(7),
},
userPoolConfig: {
userPool: UserPool.fromUserPoolId(stack, 'ImportedUserPool', '<YOUR_USER_POOL_ID>'),
},
},
});
FAQs
AppSync GraphQL Api Construct using Amplify GraphQL Transformer - Aliased to use `Data` name scheme.
The npm package @aws-amplify/data-construct receives a total of 46,660 weekly downloads. As such, @aws-amplify/data-construct popularity was classified as popular.
We found that @aws-amplify/data-construct demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.