Skip to content

Latest commit

 

History

History
4453 lines (2746 loc) · 156 KB

API.md

File metadata and controls

4453 lines (2746 loc) · 156 KB

AWS CDK AppSync Utilities

This package contains various utilities for definining GraphQl Apis via AppSync using the aws-cdk.

Code First Schema Definition

CodeFirstSchema offers the ability to generate your schema in a code-first approach. A code-first approach offers a developer workflow with:

  • modularity: organizing schema type definitions into different files
  • reusability: removing boilerplate/repetitive code
  • consistency: resolvers and schema definition will always be synced

The code-first approach allows for dynamic schema generation. You can generate your schema based on variables and templates to reduce code duplication.

import { GraphqlApi } from '@aws-cdk/aws-appsync-alpha';
import { CodeFirstSchema } from 'awscdk-appsync-utils';

const schema = new CodeFirstSchema();
const api = new GraphqlApi(this, 'api', { name: 'myApi', schema });

schema.addType(new ObjectType('demo', {
  definition: { id: GraphqlType.id() },
}));

Code-First Example

To showcase the code-first approach. Let's try to model the following schema segment.

interface Node {
  id: String
}

type Query {
  allFilms(after: String, first: Int, before: String, last: Int): FilmConnection
}

type FilmNode implements Node {
  filmName: String
}

type FilmConnection {
  edges: [FilmEdge]
  films: [Film]
  totalCount: Int
}

type FilmEdge {
  node: Film
  cursor: String
}

Above we see a schema that allows for generating paginated responses. For example, we can query allFilms(first: 100) since FilmConnection acts as an intermediary for holding FilmEdges we can write a resolver to return the first 100 films.

In a separate file, we can declare our object types and related functions. We will call this file object-types.ts and we will have created it in a way that allows us to generate other XxxConnection and XxxEdges in the future.

import { GraphqlType, InterfaceType, ObjectType } from 'awscdk-appsync-utils';
const pluralize = require('pluralize');

export const args = {
  after: GraphqlType.string(),
  first: GraphqlType.int(),
  before: GraphqlType.string(),
  last: GraphqlType.int(),
};

export const Node = new InterfaceType('Node', {
  definition: { id: GraphqlType.string() }
});
export const FilmNode = new ObjectType('FilmNode', {
  interfaceTypes: [Node],
  definition: { filmName: GraphqlType.string() }
});

export function generateEdgeAndConnection(base: ObjectType) {
  const edge = new ObjectType(`${base.name}Edge`, {
    definition: { node: base.attribute(), cursor: GraphqlType.string() }
  });
  const connection = new ObjectType(`${base.name}Connection`, {
    definition: {
      edges: edge.attribute({ isList: true }),
      [pluralize(base.name)]: base.attribute({ isList: true }),
      totalCount: GraphqlType.int(),
    }
  });
  return { edge: edge, connection: connection };
}

Finally, we will go to our cdk-stack and combine everything together to generate our schema.

declare const dummyRequest: appsync.MappingTemplate;
declare const dummyResponse: appsync.MappingTemplate;

const api = new appsync.GraphqlApi(this, 'Api', {
  name: 'demo',
});

const objectTypes = [ Node, FilmNode ];

const filmConnections = generateEdgeAndConnection(FilmNode);

api.addQuery('allFilms', new ResolvableField({
  returnType: filmConnections.connection.attribute(),
  args: args,
  dataSource: api.addNoneDataSource('none'),
  requestMappingTemplate: dummyRequest,
  responseMappingTemplate: dummyResponse,
}));

api.addType(Node);
api.addType(FilmNode);
api.addType(filmConnections.edge);
api.addType(filmConnections.connection);

Notice how we can utilize the generateEdgeAndConnection function to generate Object Types. In the future, if we wanted to create more Object Types, we can simply create the base Object Type (i.e. Film) and from there we can generate its respective Connections and Edges.

Check out a more in-depth example here.

GraphQL Types

One of the benefits of GraphQL is its strongly typed nature. We define the types within an object, query, mutation, interface, etc. as GraphQL Types.

GraphQL Types are the building blocks of types, whether they are scalar, objects, interfaces, etc. GraphQL Types can be:

  • Scalar Types: Id, Int, String, AWSDate, etc.
  • Object Types: types that you generate (i.e. demo from the example above)
  • Interface Types: abstract types that define the base implementation of other Intermediate Types

More concretely, GraphQL Types are simply the types appended to variables. Referencing the object type Demo in the previous example, the GraphQL Types is String! and is applied to both the names id and version.

Directives

Directives are attached to a field or type and affect the execution of queries, mutations, and types. With AppSync, we use Directives to configure authorization. Appsync utils provide static functions to add directives to your CodeFirstSchema.

  • Directive.iam() sets a type or field's authorization to be validated through Iam
  • Directive.apiKey() sets a type or field's authorization to be validated through a Api Key
  • Directive.oidc() sets a type or field's authorization to be validated through OpenID Connect
  • Directive.cognito(...groups: string[]) sets a type or field's authorization to be validated through Cognito User Pools
    • groups the name of the cognito groups to give access

To learn more about authorization and directives, read these docs here.

Field and Resolvable Fields

While GraphqlType is a base implementation for GraphQL fields, we have abstractions on top of GraphqlType that provide finer grain support.

Field

Field extends GraphqlType and will allow you to define arguments. Interface Types are not resolvable and this class will allow you to define arguments, but not its resolvers.

For example, if we want to create the following type:

type Node {
  test(argument: string): String
}

The CDK code required would be:

import { Field, GraphqlType, InterfaceType } from 'awscdk-appsync-utils';

const field = new Field({
  returnType: GraphqlType.string(),
  args: {
    argument: GraphqlType.string(),
  },
});
const type = new InterfaceType('Node', {
  definition: { test: field },
});

Resolvable Fields

ResolvableField extends Field and will allow you to define arguments and its resolvers. Object Types can have fields that resolve and perform operations on your backend.

You can also create resolvable fields for object types.

type Info {
  node(id: String): String
}

The CDK code required would be:

declare const api: appsync.GraphqlApi;
declare const dummyRequest: appsync.MappingTemplate;
declare const dummyResponse: appsync.MappingTemplate;

const info = new ObjectType('Info', {
  definition: {
    node: new ResolvableField({
      returnType: GraphqlType.string(),
      args: {
        id: GraphqlType.string(),
      },
      dataSource: api.addNoneDataSource('none'),
      requestMappingTemplate: dummyRequest,
      responseMappingTemplate: dummyResponse,
    }),
  },
});

To nest resolvers, we can also create top level query types that call upon other types. Building off the previous example, if we want the following graphql type definition:

type Query {
  get(argument: string): Info
}

The CDK code required would be:

declare const api: appsync.GraphqlApi;
declare const dummyRequest: appsync.MappingTemplate;
declare const dummyResponse: appsync.MappingTemplate;

const query = new ObjectType('Query', {
  definition: {
    get: new ResolvableField({
      returnType: GraphqlType.string(),
      args: {
        argument: GraphqlType.string(),
      },
      dataSource: api.addNoneDataSource('none'),
      requestMappingTemplate: dummyRequest,
      responseMappingTemplate: dummyResponse,
    }),
  },
});

Learn more about fields and resolvers here.

Intermediate Types

Intermediate Types are defined by Graphql Types and Fields. They have a set of defined fields, where each field corresponds to another type in the system. Intermediate Types will be the meat of your GraphQL Schema as they are the types defined by you.

Intermediate Types include:

Interface Types

Interface Types are abstract types that define the implementation of other intermediate types. They are useful for eliminating duplication and can be used to generate Object Types with less work.

You can create Interface Types externally.

const node = new InterfaceType('Node', {
  definition: {
    id: GraphqlType.string({ isRequired: true }),
  },
});

To learn more about Interface Types, read the docs here.

Object Types

Object Types are types that you declare. For example, in the code-first example the demo variable is an Object Type. Object Types are defined by GraphQL Types and are only usable when linked to a GraphQL Api.

You can create Object Types in two ways:

  1. Object Types can be created externally.

    const schema = new CodeFirstSchema();
    const api = new appsync.GraphqlApi(this, 'Api', {
      name: 'demo',
      schema,
    });
    const demo = new ObjectType('Demo', {
      definition: {
        id: GraphqlType.string({ isRequired: true }),
        version: GraphqlType.string({ isRequired: true }),
      },
    });
    
    schema.addType(demo);

    This method allows for reusability and modularity, ideal for larger projects. For example, imagine moving all Object Type definition outside the stack.

    object-types.ts - a file for object type definitions

    import { ObjectType, GraphqlType } from 'awscdk-appsync-utils';
    export const demo = new ObjectType('Demo', {
      definition: {
        id: GraphqlType.string({ isRequired: true }),
        version: GraphqlType.string({ isRequired: true }),
      },
    });

    cdk-stack.ts - a file containing our cdk stack

    declare const schema: CodeFirstSchema;
    schema.addType(demo);
  2. Object Types can be created externally from an Interface Type.

    const node = new InterfaceType('Node', {
      definition: {
        id: GraphqlType.string({ isRequired: true }),
      },
    });
    const demo = new ObjectType('Demo', {
      interfaceTypes: [ node ],
      definition: {
        version: GraphqlType.string({ isRequired: true }),
      },
    });

    This method allows for reusability and modularity, ideal for reducing code duplication.

To learn more about Object Types, read the docs here.

Enum Types

Enum Types are a special type of Intermediate Type. They restrict a particular set of allowed values for other Intermediate Types.

enum Episode {
  NEWHOPE
  EMPIRE
  JEDI
}

This means that wherever we use the type Episode in our schema, we expect it to be exactly one of NEWHOPE, EMPIRE, or JEDI.

The above GraphQL Enumeration Type can be expressed in CDK as the following:

declare const api: GraphqlApi;
const episode = new EnumType('Episode', {
  definition: [
    'NEWHOPE',
    'EMPIRE',
    'JEDI',
  ],
});
api.addType(episode);

To learn more about Enum Types, read the docs here.

Input Types

Input Types are special types of Intermediate Types. They give users an easy way to pass complex objects for top level Mutation and Queries.

input Review {
  stars: Int!
  commentary: String
}

The above GraphQL Input Type can be expressed in CDK as the following:

declare const api: appsync.GraphqlApi;
const review = new InputType('Review', {
  definition: {
    stars: GraphqlType.int({ isRequired: true }),
    commentary: GraphqlType.string(),
  },
});
api.addType(review);

To learn more about Input Types, read the docs here.

Union Types

Union Types are a special type of Intermediate Type. They are similar to Interface Types, but they cannot specify any common fields between types.

Note: the fields of a union type need to be Object Types. In other words, you can't create a union type out of interfaces, other unions, or inputs.

union Search = Human | Droid | Starship

The above GraphQL Union Type encompasses the Object Types of Human, Droid and Starship. It can be expressed in CDK as the following:

declare const api: appsync.GraphqlApi;
const string = GraphqlType.string();
const human = new ObjectType('Human', { definition: { name: string } });
const droid = new ObjectType('Droid', { definition: { name: string } });
const starship = new ObjectType('Starship', { definition: { name: string } }););
const search = new UnionType('Search', {
  definition: [ human, droid, starship ],
});
api.addType(search);

To learn more about Union Types, read the docs here.

Query

Every schema requires a top level Query type. By default, the schema will look for the Object Type named Query. The top level Query is the only exposed type that users can access to perform GET operations on your Api.

To add fields for these queries, we can simply run the addQuery function to add to the schema's Query type.

declare const api: appsync.GraphqlApi;
declare const filmConnection: InterfaceType;
declare const dummyRequest: appsync.MappingTemplate;
declare const dummyResponse: appsync.MappingTemplate;

const string = GraphqlType.string();
const int = GraphqlType.int();
api.addQuery('allFilms', new ResolvableField({
  returnType: filmConnection.attribute(),
  args: { after: string, first: int, before: string, last: int},
  dataSource: api.addNoneDataSource('none'),
  requestMappingTemplate: dummyRequest,
  responseMappingTemplate: dummyResponse,
}));

To learn more about top level operations, check out the docs here.

Mutation

Every schema can have a top level Mutation type. By default, the schema will look for the ObjectType named Mutation. The top level Mutation Type is the only exposed type that users can access to perform mutable operations on your Api.

To add fields for these mutations, we can simply run the addMutation function to add to the schema's Mutation type.

declare const api: appsync.GraphqlApi;
declare const filmNode: ObjectType;
declare const dummyRequest: appsync.MappingTemplate;
declare const dummyResponse: appsync.MappingTemplate;

const string = GraphqlType.string();
const int = GraphqlType.int();
api.addMutation('addFilm', new ResolvableField({
  returnType: filmNode.attribute(),
  args: { name: string, film_number: int },
  dataSource: api.addNoneDataSource('none'),
  requestMappingTemplate: dummyRequest,
  responseMappingTemplate: dummyResponse,
}));

To learn more about top level operations, check out the docs here.

Subscription

Every schema can have a top level Subscription type. The top level Subscription Type is the only exposed type that users can access to invoke a response to a mutation. Subscriptions notify users when a mutation specific mutation is called. This means you can make any data source real time by specify a GraphQL Schema directive on a mutation.

Note: The AWS AppSync client SDK automatically handles subscription connection management.

To add fields for these subscriptions, we can simply run the addSubscription function to add to the schema's Subscription type.

declare const api: appsync.GraphqlApi;
declare const film: InterfaceType;

api.addSubscription('addedFilm', new Field({
  returnType: film.attribute(),
  args: { id: GraphqlType.id({ isRequired: true }) },
  directives: [Directive.subscribe('addFilm')],
}));

To learn more about top level operations, check out the docs here.

Merge Source API to Merged API Using A Custom Resource

The SourceApiAssociationMergeOperation construct provides the ability to merge a source api to a Merged Api and invoke a merge within a Cloudformation custom resource. If the merge operation fails with a conflict, the Cloudformation update will fail and rollback the changes to the source API in the stack.

import * as cdk from 'aws-cdk-lib';

const sourceApi1ToMerge = new appsync.GraphqlApi(this, 'FirstSourceAPI', {
  name: 'FirstSourceAPI',
  definition: appsync.Definition.fromFile(path.join(__dirname, 'appsync.merged-api-1.graphql')),
});

const sourceApi2ToMerge = new appsync.GraphqlApi(this, 'SecondSourceAPI', {
  name: 'SecondSourceAPI',
  definition: appsync.Definition.fromFile(path.join(__dirname, 'appsync.merged-api-2.graphql')),
});

const remoteMergedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(this, 'ImportedMergedApi', {
  graphqlApiId: 'MyApiId',
  graphqlApiArn: 'MyApiArn',
});

const remoteExecutionRole = iam.Role.fromRoleArn(this, 'ExecutionRole', 'arn:aws:iam::ACCOUNT:role/MyExistingRole');
const association1 = new appsync.SourceApiAssociation(this, 'SourceApiAssociation1', {
   sourceApi: sourceApi1ToMerge,
   mergedApi: remoteMergedApi,
   mergeType: appsync.MergeType.MANUAL_MERGE,
   mergedApiExecutionRole: remoteExecutionRole,
});

const association2 = new appsync.SourceApiAssociation(this, 'SourceApiAssociation2', {
   sourceApi: sourceApi2ToMerge,
   mergedApi: remoteMergedApi,
   mergeType: appsync.MergeType.MANUAL_MERGE,
   mergedApiExecutionRole: remoteExecutionRole,
});

// The version id can be any identifier defined by the developer. Changing the version identifier allows you to control
// whether a merge operation will take place during deployment.
SourceApiAssociationMergeOperation(this, 'MergeOperation1', {
  sourceApiAssociation: association1,
  versionIdentifier: '1',
});

// Optionally, you can add the alwaysMergeOnStackUpdate flag instead which will ensure that the merge operation occurs
// during every stack update, regardless if there was a change or not. Note that this may lead to merge operations that
//do not actually change the MergedAPI.
SourceApiAssociationMergeOperation(this, 'MergeOperation2', {
  sourceApiAssociation: association2,
  alwaysMergeOnStackUpdate: true,
});

Contributing

This library leans towards high level and experimental features for appsync cdk users. If you have an idea for additional utilities please create an issue describing the feature.

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

API Reference

Constructs

SourceApiAssociationMergeOperation

The SourceApiAssociationMergeOperation triggers a merge of a source API during a Cloudformation stack update.

This can be used to propagate changes from the source API to the Merged API when the association is using type MANUAL_MERGE. If the merge operation fails, it will fail the Cloudformation update and rollback the stack.

Initializers

import { SourceApiAssociationMergeOperation } from 'awscdk-appsync-utils'

new SourceApiAssociationMergeOperation(scope: Construct, id: string, props: SourceApiAssociationMergeOperationProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props SourceApiAssociationMergeOperationProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { SourceApiAssociationMergeOperation } from 'awscdk-appsync-utils'

SourceApiAssociationMergeOperation.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


SourceApiAssociationMergeOperationProvider

SourceApiAssociationMergeProvider class is responsible for constructing the custom resource that will be used for initiating the source API merge during a Cloudformation update.

Initializers

import { SourceApiAssociationMergeOperationProvider } from 'awscdk-appsync-utils'

new SourceApiAssociationMergeOperationProvider(scope: Construct, id: string, props: SourceApiAssociationMergeOperationProviderProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props SourceApiAssociationMergeOperationProviderProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.
associateSourceApiAssociation This function associates a source api association with the provider.

toString
public toString(): string

Returns a string representation of this construct.

associateSourceApiAssociation
public associateSourceApiAssociation(sourceApiAssociation: ISourceApiAssociation): void

This function associates a source api association with the provider.

This method can be used for adding permissions to merge a specific source api association to the custom resource provider.

sourceApiAssociationRequired
  • Type: aws-cdk-lib.aws_appsync.ISourceApiAssociation

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { SourceApiAssociationMergeOperationProvider } from 'awscdk-appsync-utils'

SourceApiAssociationMergeOperationProvider.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
schemaMergeLambda aws-cdk-lib.aws_lambda.SingletonFunction The lambda function responsible for kicking off the merge operation.
serviceToken string Service token for the resource provider.
sourceApiStablizationLambda aws-cdk-lib.aws_lambda.SingletonFunction The lambda function response for ensuring that the merge operation finished.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


schemaMergeLambdaRequired
public readonly schemaMergeLambda: SingletonFunction;
  • Type: aws-cdk-lib.aws_lambda.SingletonFunction

The lambda function responsible for kicking off the merge operation.


serviceTokenRequired
public readonly serviceToken: string;
  • Type: string

Service token for the resource provider.


sourceApiStablizationLambdaRequired
public readonly sourceApiStablizationLambda: SingletonFunction;
  • Type: aws-cdk-lib.aws_lambda.SingletonFunction

The lambda function response for ensuring that the merge operation finished.


Structs

AddFieldOptions

The options to add a field to an Intermediate Type.

Initializer

import { AddFieldOptions } from 'awscdk-appsync-utils'

const addFieldOptions: AddFieldOptions = { ... }

Properties

Name Type Description
field IField The resolvable field to add.
fieldName string The name of the field.

fieldOptional
public readonly field: IField;
  • Type: IField
  • Default: no IField

The resolvable field to add.

This option must be configured for Object, Interface, Input and Union Types.


fieldNameOptional
public readonly fieldName: string;
  • Type: string
  • Default: no fieldName

The name of the field.

This option must be configured for Object, Interface, Input and Enum Types.


BaseTypeOptions

Base options for GraphQL Types.

Initializer

import { BaseTypeOptions } from 'awscdk-appsync-utils'

const baseTypeOptions: BaseTypeOptions = { ... }

Properties

Name Type Description
isList boolean property determining if this attribute is a list i.e. if true, attribute would be [Type].
isRequired boolean property determining if this attribute is non-nullable i.e. if true, attribute would be Type!
isRequiredList boolean property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! or if isRequired true, attribe would be [ Type! ]!

isListOptional
public readonly isList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a list i.e. if true, attribute would be [Type].


isRequiredOptional
public readonly isRequired: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is non-nullable i.e. if true, attribute would be Type!


isRequiredListOptional
public readonly isRequiredList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! or if isRequired true, attribe would be [ Type! ]!


EnumTypeOptions

Properties for configuring an Enum Type.

Initializer

import { EnumTypeOptions } from 'awscdk-appsync-utils'

const enumTypeOptions: EnumTypeOptions = { ... }

Properties

Name Type Description
definition string[] the attributes of this type.

definitionRequired
public readonly definition: string[];
  • Type: string[]

the attributes of this type.


FieldOptions

Properties for configuring a field.

Initializer

import { FieldOptions } from 'awscdk-appsync-utils'

const fieldOptions: FieldOptions = { ... }

Properties

Name Type Description
returnType GraphqlType The return type for this field.
args {[ key: string ]: GraphqlType} The arguments for this field.
directives Directive[] the directives for this field.

returnTypeRequired
public readonly returnType: GraphqlType;

The return type for this field.


argsOptional
public readonly args: {[ key: string ]: GraphqlType};
  • Type: {[ key: string ]: GraphqlType}
  • Default: no arguments

The arguments for this field.

i.e. type Example (first: String second: String) {}

  • where 'first' and 'second' are key values for args and 'String' is the GraphqlType

directivesOptional
public readonly directives: Directive[];

the directives for this field.


GraphqlTypeOptions

Options for GraphQL Types.

Initializer

import { GraphqlTypeOptions } from 'awscdk-appsync-utils'

const graphqlTypeOptions: GraphqlTypeOptions = { ... }

Properties

Name Type Description
isList boolean property determining if this attribute is a list i.e. if true, attribute would be [Type].
isRequired boolean property determining if this attribute is non-nullable i.e. if true, attribute would be Type!
isRequiredList boolean property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! or if isRequired true, attribe would be [ Type! ]!
intermediateType IIntermediateType the intermediate type linked to this attribute.

isListOptional
public readonly isList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a list i.e. if true, attribute would be [Type].


isRequiredOptional
public readonly isRequired: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is non-nullable i.e. if true, attribute would be Type!


isRequiredListOptional
public readonly isRequiredList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! or if isRequired true, attribe would be [ Type! ]!


intermediateTypeOptional
public readonly intermediateType: IIntermediateType;

the intermediate type linked to this attribute.


IntermediateTypeOptions

Properties for configuring an Intermediate Type.

Initializer

import { IntermediateTypeOptions } from 'awscdk-appsync-utils'

const intermediateTypeOptions: IntermediateTypeOptions = { ... }

Properties

Name Type Description
definition {[ key: string ]: IField} the attributes of this type.
directives Directive[] the directives for this object type.

definitionRequired
public readonly definition: {[ key: string ]: IField};
  • Type: {[ key: string ]: IField}

the attributes of this type.


directivesOptional
public readonly directives: Directive[];

the directives for this object type.


ObjectTypeOptions

Properties for configuring an Object Type.

Initializer

import { ObjectTypeOptions } from 'awscdk-appsync-utils'

const objectTypeOptions: ObjectTypeOptions = { ... }

Properties

Name Type Description
definition {[ key: string ]: IField} the attributes of this type.
directives Directive[] the directives for this object type.
interfaceTypes InterfaceType[] The Interface Types this Object Type implements.

definitionRequired
public readonly definition: {[ key: string ]: IField};
  • Type: {[ key: string ]: IField}

the attributes of this type.


directivesOptional
public readonly directives: Directive[];

the directives for this object type.


interfaceTypesOptional
public readonly interfaceTypes: InterfaceType[];

The Interface Types this Object Type implements.


ResolvableFieldOptions

Properties for configuring a resolvable field.

Initializer

import { ResolvableFieldOptions } from 'awscdk-appsync-utils'

const resolvableFieldOptions: ResolvableFieldOptions = { ... }

Properties

Name Type Description
returnType GraphqlType The return type for this field.
args {[ key: string ]: GraphqlType} The arguments for this field.
directives Directive[] the directives for this field.
dataSource aws-cdk-lib.aws_appsync.BaseDataSource The data source creating linked to this resolvable field.
pipelineConfig aws-cdk-lib.aws_appsync.IAppsyncFunction[] configuration of the pipeline resolver.
requestMappingTemplate aws-cdk-lib.aws_appsync.MappingTemplate The request mapping template for this resolver.
responseMappingTemplate aws-cdk-lib.aws_appsync.MappingTemplate The response mapping template for this resolver.

returnTypeRequired
public readonly returnType: GraphqlType;

The return type for this field.


argsOptional
public readonly args: {[ key: string ]: GraphqlType};
  • Type: {[ key: string ]: GraphqlType}
  • Default: no arguments

The arguments for this field.

i.e. type Example (first: String second: String) {}

  • where 'first' and 'second' are key values for args and 'String' is the GraphqlType

directivesOptional
public readonly directives: Directive[];

the directives for this field.


dataSourceOptional
public readonly dataSource: BaseDataSource;
  • Type: aws-cdk-lib.aws_appsync.BaseDataSource
  • Default: no data source

The data source creating linked to this resolvable field.


pipelineConfigOptional
public readonly pipelineConfig: IAppsyncFunction[];
  • Type: aws-cdk-lib.aws_appsync.IAppsyncFunction[]
  • Default: no pipeline resolver configuration An empty array or undefined prop will set resolver to be of type unit

configuration of the pipeline resolver.


requestMappingTemplateOptional
public readonly requestMappingTemplate: MappingTemplate;
  • Type: aws-cdk-lib.aws_appsync.MappingTemplate
  • Default: No mapping template

The request mapping template for this resolver.


responseMappingTemplateOptional
public readonly responseMappingTemplate: MappingTemplate;
  • Type: aws-cdk-lib.aws_appsync.MappingTemplate
  • Default: No mapping template

The response mapping template for this resolver.


SourceApiAssociationMergeOperationProps

Properties for SourceApiAssociationMergeOperation which handles triggering a merge operation as a custom resource during a Cloudformation stack update.

Initializer

import { SourceApiAssociationMergeOperationProps } from 'awscdk-appsync-utils'

const sourceApiAssociationMergeOperationProps: SourceApiAssociationMergeOperationProps = { ... }

Properties

Name Type Description
sourceApiAssociation aws-cdk-lib.aws_appsync.ISourceApiAssociation The source api association resource which will be merged.
alwaysMergeOnStackUpdate boolean Flag indicating whether the source api should be merged on every CFN update or not.
mergeOperationProvider ISourceApiAssociationMergeOperationProvider The merge operation provider construct which is responsible for configuring the Lambda resource that will be invoked during Cloudformation update.
versionIdentifier string The version identifier for the schema merge operation.

sourceApiAssociationRequired
public readonly sourceApiAssociation: ISourceApiAssociation;
  • Type: aws-cdk-lib.aws_appsync.ISourceApiAssociation

The source api association resource which will be merged.


alwaysMergeOnStackUpdateOptional
public readonly alwaysMergeOnStackUpdate: boolean;
  • Type: boolean
  • Default: False

Flag indicating whether the source api should be merged on every CFN update or not.

If set to true and there are no changes to the source API, this will result in a no-op merge operation.


mergeOperationProviderOptional
public readonly mergeOperationProvider: ISourceApiAssociationMergeOperationProvider;

The merge operation provider construct which is responsible for configuring the Lambda resource that will be invoked during Cloudformation update.


versionIdentifierOptional
public readonly versionIdentifier: string;
  • Type: string
  • Default: null

The version identifier for the schema merge operation.

Any change to the version identifier will trigger a merge on the next update. Use the version identifier property to control when the source API metadata is merged.


SourceApiAssociationMergeOperationProviderProps

Properties for SourceApiAssociationMergeOperationProvider.

Initializer

import { SourceApiAssociationMergeOperationProviderProps } from 'awscdk-appsync-utils'

const sourceApiAssociationMergeOperationProviderProps: SourceApiAssociationMergeOperationProviderProps = { ... }

Properties

Name Type Description
pollingInterval aws-cdk-lib.Duration Time between calls to the polling Lambda function which determines whether the merge operation is finished or not.
totalTimeout aws-cdk-lib.Duration Total timeout in waiting for the source api association merge operation to complete.

pollingIntervalOptional
public readonly pollingInterval: Duration;
  • Type: aws-cdk-lib.Duration
  • Default: Duration.seconds(5)

Time between calls to the polling Lambda function which determines whether the merge operation is finished or not.


totalTimeoutOptional
public readonly totalTimeout: Duration;
  • Type: aws-cdk-lib.Duration
  • Default: Duration.minutes(15)

Total timeout in waiting for the source api association merge operation to complete.


UnionTypeOptions

Properties for configuring an Union Type.

Initializer

import { UnionTypeOptions } from 'awscdk-appsync-utils'

const unionTypeOptions: UnionTypeOptions = { ... }

Properties

Name Type Description
definition IIntermediateType[] the object types for this union type.

definitionRequired
public readonly definition: IIntermediateType[];

the object types for this union type.


Classes

CodeFirstSchema

  • Implements: aws-cdk-lib.aws_appsync.ISchema

Initializers

import { CodeFirstSchema } from 'awscdk-appsync-utils'

new CodeFirstSchema()
Name Type Description

Methods

Name Description
addMutation Add a mutation field to the schema's Mutation. CDK will create an Object Type called 'Mutation'. For example,.
addQuery Add a query field to the schema's Query. CDK will create an Object Type called 'Query'. For example,.
addSubscription Add a subscription field to the schema's Subscription. CDK will create an Object Type called 'Subscription'. For example,.
addToSchema Escape hatch to add to Schema as desired.
addType Add type to the schema.
bind Called when the GraphQL Api is initialized to allow this object to bind to the stack.

addMutation
public addMutation(fieldName: string, field: ResolvableField): ObjectType

Add a mutation field to the schema's Mutation. CDK will create an Object Type called 'Mutation'. For example,.

type Mutation { fieldName: Field.returnType }

fieldNameRequired
  • Type: string

the name of the Mutation.


fieldRequired

the resolvable field to for this Mutation.


addQuery
public addQuery(fieldName: string, field: ResolvableField): ObjectType

Add a query field to the schema's Query. CDK will create an Object Type called 'Query'. For example,.

type Query { fieldName: Field.returnType }

fieldNameRequired
  • Type: string

the name of the query.


fieldRequired

the resolvable field to for this query.


addSubscription
public addSubscription(fieldName: string, field: Field): ObjectType

Add a subscription field to the schema's Subscription. CDK will create an Object Type called 'Subscription'. For example,.

type Subscription { fieldName: Field.returnType }

fieldNameRequired
  • Type: string

the name of the Subscription.


fieldRequired

the resolvable field to for this Subscription.


addToSchema
public addToSchema(addition: string, delimiter?: string): void

Escape hatch to add to Schema as desired.

Will always result in a newline.

additionRequired
  • Type: string

the addition to add to schema.


delimiterOptional
  • Type: string

the delimiter between schema and addition.


addType
public addType(type: IIntermediateType): IIntermediateType

Add type to the schema.

typeRequired

the intermediate type to add to the schema.


bind
public bind(api: IGraphqlApi, _options?: SchemaBindOptions): ISchemaConfig

Called when the GraphQL Api is initialized to allow this object to bind to the stack.

apiRequired
  • Type: aws-cdk-lib.aws_appsync.IGraphqlApi

The binding GraphQL Api.


_optionsOptional
  • Type: aws-cdk-lib.aws_appsync.SchemaBindOptions

Properties

Name Type Description
definition string The definition for this schema.

definitionRequired
public readonly definition: string;
  • Type: string

The definition for this schema.


Directive

Directives for types.

i.e. @aws_iam or @aws_subscribe

Methods

Name Description
toString Generate the directive statement.

toString
public toString(): string

Generate the directive statement.

Static Functions

Name Description
apiKey Add the @aws_api_key directive.
cognito Add the @aws_auth or @aws_cognito_user_pools directive.
custom Add a custom directive.
iam Add the @aws_iam directive.
oidc Add the @aws_oidc directive.
subscribe Add the @aws_subscribe directive.

apiKey
import { Directive } from 'awscdk-appsync-utils'

Directive.apiKey()

Add the @aws_api_key directive.

cognito
import { Directive } from 'awscdk-appsync-utils'

Directive.cognito(groups: string)

Add the @aws_auth or @aws_cognito_user_pools directive.

groupsRequired
  • Type: string

the groups to allow access to.


custom
import { Directive } from 'awscdk-appsync-utils'

Directive.custom(statement: string)

Add a custom directive.

statementRequired
  • Type: string

the directive statement to append.


iam
import { Directive } from 'awscdk-appsync-utils'

Directive.iam()

Add the @aws_iam directive.

oidc
import { Directive } from 'awscdk-appsync-utils'

Directive.oidc()

Add the @aws_oidc directive.

subscribe
import { Directive } from 'awscdk-appsync-utils'

Directive.subscribe(mutations: string)

Add the @aws_subscribe directive.

Only use for top level Subscription type.

mutationsRequired
  • Type: string

the mutation fields to link to.


Properties

Name Type Description
mode aws-cdk-lib.aws_appsync.AuthorizationType The authorization type of this directive.
mutationFields string[] Mutation fields for a subscription directive.

modeOptional
public readonly mode: AuthorizationType;
  • Type: aws-cdk-lib.aws_appsync.AuthorizationType
  • Default: not an authorization directive

The authorization type of this directive.


mutationFieldsOptional
public readonly mutationFields: string[];
  • Type: string[]
  • Default: not a subscription directive

Mutation fields for a subscription directive.


EnumType

Enum Types are abstract types that includes a set of fields that represent the strings this type can create.

Initializers

import { EnumType } from 'awscdk-appsync-utils'

new EnumType(name: string, options: EnumTypeOptions)
Name Type Description
name string No description.
options EnumTypeOptions No description.

nameRequired
  • Type: string

optionsRequired

Methods

Name Description
addField Add a field to this Enum Type.
attribute Create an GraphQL Type representing this Enum Type.
toString Generate the string of this enum type.

addField
public addField(options: AddFieldOptions): void

Add a field to this Enum Type.

To add a field to this Enum Type, you must only configure addField with the fieldName options.

optionsRequired

the options to add a field.


attribute
public attribute(options?: BaseTypeOptions): GraphqlType

Create an GraphQL Type representing this Enum Type.

optionsOptional

toString
public toString(): string

Generate the string of this enum type.

Properties

Name Type Description
definition {[ key: string ]: IField} the attributes of this type.
name string the name of this type.

definitionRequired
public readonly definition: {[ key: string ]: IField};
  • Type: {[ key: string ]: IField}

the attributes of this type.


nameRequired
public readonly name: string;
  • Type: string

the name of this type.


Field

Fields build upon Graphql Types and provide typing and arguments.

Initializers

import { Field } from 'awscdk-appsync-utils'

new Field(options: FieldOptions)
Name Type Description
options FieldOptions No description.

optionsRequired

Methods

Name Description
argsToString Generate the args string of this resolvable field.
directivesToString Generate the directives for this field.
toString Generate the string for this attribute.

argsToString
public argsToString(): string

Generate the args string of this resolvable field.

directivesToString
public directivesToString(modes?: AuthorizationType[]): string

Generate the directives for this field.

modesOptional
  • Type: aws-cdk-lib.aws_appsync.AuthorizationType[]

toString
public toString(): string

Generate the string for this attribute.

Static Functions

Name Description
awsDate AWSDate scalar type represents a valid extended ISO 8601 Date string.
awsDateTime AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string.
awsEmail AWSEmail scalar type represents an email address string (i.e.[email protected]).
awsIpAddress AWSIPAddress scalar type respresents a valid IPv4 of IPv6 address string.
awsJson AWSJson scalar type represents a JSON string.
awsPhone AWSPhone scalar type represents a valid phone number. Phone numbers maybe be whitespace delimited or hyphenated.
awsTime AWSTime scalar type represents a valid extended ISO 8601 Time string.
awsTimestamp AWSTimestamp scalar type represents the number of seconds since 1970-01-01T00:00Z.
awsUrl AWSURL scalar type represetns a valid URL string.
boolean Boolean scalar type is a boolean value: true or false.
float Float scalar type is a signed double-precision fractional value.
id ID scalar type is a unique identifier. ID type is serialized similar to String.
int Int scalar type is a signed non-fractional numerical value.
intermediate an intermediate type to be added as an attribute (i.e. an interface or an object type).
string String scalar type is a free-form human-readable text.

awsDate
import { Field } from 'awscdk-appsync-utils'

Field.awsDate(options?: BaseTypeOptions)

AWSDate scalar type represents a valid extended ISO 8601 Date string.

In other words, accepts date strings in the form of YYYY-MM-DD. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsDateTime
import { Field } from 'awscdk-appsync-utils'

Field.awsDateTime(options?: BaseTypeOptions)

AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string.

In other words, accepts date strings in the form of YYYY-MM-DDThh:mm:ss.sssZ. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsEmail
import { Field } from 'awscdk-appsync-utils'

Field.awsEmail(options?: BaseTypeOptions)

AWSEmail scalar type represents an email address string (i.e.[email protected]).

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsIpAddress
import { Field } from 'awscdk-appsync-utils'

Field.awsIpAddress(options?: BaseTypeOptions)

AWSIPAddress scalar type respresents a valid IPv4 of IPv6 address string.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsJson
import { Field } from 'awscdk-appsync-utils'

Field.awsJson(options?: BaseTypeOptions)

AWSJson scalar type represents a JSON string.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsPhone
import { Field } from 'awscdk-appsync-utils'

Field.awsPhone(options?: BaseTypeOptions)

AWSPhone scalar type represents a valid phone number. Phone numbers maybe be whitespace delimited or hyphenated.

The number can specify a country code at the beginning, but is not required for US phone numbers.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsTime
import { Field } from 'awscdk-appsync-utils'

Field.awsTime(options?: BaseTypeOptions)

AWSTime scalar type represents a valid extended ISO 8601 Time string.

In other words, accepts date strings in the form of hh:mm:ss.sss. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsTimestamp
import { Field } from 'awscdk-appsync-utils'

Field.awsTimestamp(options?: BaseTypeOptions)

AWSTimestamp scalar type represents the number of seconds since 1970-01-01T00:00Z.

Timestamps are serialized and deserialized as numbers.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsUrl
import { Field } from 'awscdk-appsync-utils'

Field.awsUrl(options?: BaseTypeOptions)

AWSURL scalar type represetns a valid URL string.

URLs wihtout schemes or contain double slashes are considered invalid.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


boolean
import { Field } from 'awscdk-appsync-utils'

Field.boolean(options?: BaseTypeOptions)

Boolean scalar type is a boolean value: true or false.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


float
import { Field } from 'awscdk-appsync-utils'

Field.float(options?: BaseTypeOptions)

Float scalar type is a signed double-precision fractional value.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


id
import { Field } from 'awscdk-appsync-utils'

Field.id(options?: BaseTypeOptions)

ID scalar type is a unique identifier. ID type is serialized similar to String.

Often used as a key for a cache and not intended to be human-readable.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


int
import { Field } from 'awscdk-appsync-utils'

Field.int(options?: BaseTypeOptions)

Int scalar type is a signed non-fractional numerical value.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


intermediate
import { Field } from 'awscdk-appsync-utils'

Field.intermediate(options?: GraphqlTypeOptions)

an intermediate type to be added as an attribute (i.e. an interface or an object type).

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList - intermediateType.


string
import { Field } from 'awscdk-appsync-utils'

Field.string(options?: BaseTypeOptions)

String scalar type is a free-form human-readable text.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


Properties

Name Type Description
isList boolean property determining if this attribute is a list i.e. if true, attribute would be [Type].
isRequired boolean property determining if this attribute is non-nullable i.e. if true, attribute would be Type! and this attribute must always have a value.
isRequiredList boolean property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! and this attribute's list must always have a value.
type Type the type of attribute.
intermediateType IIntermediateType the intermediate type linked to this attribute (i.e. an interface or an object).
fieldOptions ResolvableFieldOptions The options for this field.

isListRequired
public readonly isList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a list i.e. if true, attribute would be [Type].


isRequiredRequired
public readonly isRequired: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is non-nullable i.e. if true, attribute would be Type! and this attribute must always have a value.


isRequiredListRequired
public readonly isRequiredList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! and this attribute's list must always have a value.


typeRequired
public readonly type: Type;

the type of attribute.


intermediateTypeOptional
public readonly intermediateType: IIntermediateType;

the intermediate type linked to this attribute (i.e. an interface or an object).


fieldOptionsOptional
public readonly fieldOptions: ResolvableFieldOptions;

The options for this field.


GraphqlType

The GraphQL Types in AppSync's GraphQL.

GraphQL Types are the building blocks for object types, queries, mutations, etc. They are types like String, Int, Id or even Object Types you create.

i.e. String, String!, [String], [String!], [String]!

GraphQL Types are used to define the entirety of schema.

Initializers

import { GraphqlType } from 'awscdk-appsync-utils'

new GraphqlType(type: Type, options?: GraphqlTypeOptions)
Name Type Description
type Type No description.
options GraphqlTypeOptions No description.

typeRequired

optionsOptional

Methods

Name Description
argsToString Generate the arguments for this field.
directivesToString Generate the directives for this field.
toString Generate the string for this attribute.

argsToString
public argsToString(): string

Generate the arguments for this field.

directivesToString
public directivesToString(_modes?: AuthorizationType[]): string

Generate the directives for this field.

_modesOptional
  • Type: aws-cdk-lib.aws_appsync.AuthorizationType[]

toString
public toString(): string

Generate the string for this attribute.

Static Functions

Name Description
awsDate AWSDate scalar type represents a valid extended ISO 8601 Date string.
awsDateTime AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string.
awsEmail AWSEmail scalar type represents an email address string (i.e.[email protected]).
awsIpAddress AWSIPAddress scalar type respresents a valid IPv4 of IPv6 address string.
awsJson AWSJson scalar type represents a JSON string.
awsPhone AWSPhone scalar type represents a valid phone number. Phone numbers maybe be whitespace delimited or hyphenated.
awsTime AWSTime scalar type represents a valid extended ISO 8601 Time string.
awsTimestamp AWSTimestamp scalar type represents the number of seconds since 1970-01-01T00:00Z.
awsUrl AWSURL scalar type represetns a valid URL string.
boolean Boolean scalar type is a boolean value: true or false.
float Float scalar type is a signed double-precision fractional value.
id ID scalar type is a unique identifier. ID type is serialized similar to String.
int Int scalar type is a signed non-fractional numerical value.
intermediate an intermediate type to be added as an attribute (i.e. an interface or an object type).
string String scalar type is a free-form human-readable text.

awsDate
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsDate(options?: BaseTypeOptions)

AWSDate scalar type represents a valid extended ISO 8601 Date string.

In other words, accepts date strings in the form of YYYY-MM-DD. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsDateTime
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsDateTime(options?: BaseTypeOptions)

AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string.

In other words, accepts date strings in the form of YYYY-MM-DDThh:mm:ss.sssZ. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsEmail
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsEmail(options?: BaseTypeOptions)

AWSEmail scalar type represents an email address string (i.e.[email protected]).

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsIpAddress
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsIpAddress(options?: BaseTypeOptions)

AWSIPAddress scalar type respresents a valid IPv4 of IPv6 address string.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsJson
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsJson(options?: BaseTypeOptions)

AWSJson scalar type represents a JSON string.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsPhone
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsPhone(options?: BaseTypeOptions)

AWSPhone scalar type represents a valid phone number. Phone numbers maybe be whitespace delimited or hyphenated.

The number can specify a country code at the beginning, but is not required for US phone numbers.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsTime
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsTime(options?: BaseTypeOptions)

AWSTime scalar type represents a valid extended ISO 8601 Time string.

In other words, accepts date strings in the form of hh:mm:ss.sss. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsTimestamp
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsTimestamp(options?: BaseTypeOptions)

AWSTimestamp scalar type represents the number of seconds since 1970-01-01T00:00Z.

Timestamps are serialized and deserialized as numbers.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsUrl
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.awsUrl(options?: BaseTypeOptions)

AWSURL scalar type represetns a valid URL string.

URLs wihtout schemes or contain double slashes are considered invalid.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


boolean
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.boolean(options?: BaseTypeOptions)

Boolean scalar type is a boolean value: true or false.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


float
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.float(options?: BaseTypeOptions)

Float scalar type is a signed double-precision fractional value.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


id
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.id(options?: BaseTypeOptions)

ID scalar type is a unique identifier. ID type is serialized similar to String.

Often used as a key for a cache and not intended to be human-readable.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


int
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.int(options?: BaseTypeOptions)

Int scalar type is a signed non-fractional numerical value.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


intermediate
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.intermediate(options?: GraphqlTypeOptions)

an intermediate type to be added as an attribute (i.e. an interface or an object type).

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList - intermediateType.


string
import { GraphqlType } from 'awscdk-appsync-utils'

GraphqlType.string(options?: BaseTypeOptions)

String scalar type is a free-form human-readable text.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


Properties

Name Type Description
isList boolean property determining if this attribute is a list i.e. if true, attribute would be [Type].
isRequired boolean property determining if this attribute is non-nullable i.e. if true, attribute would be Type! and this attribute must always have a value.
isRequiredList boolean property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! and this attribute's list must always have a value.
type Type the type of attribute.
intermediateType IIntermediateType the intermediate type linked to this attribute (i.e. an interface or an object).

isListRequired
public readonly isList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a list i.e. if true, attribute would be [Type].


isRequiredRequired
public readonly isRequired: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is non-nullable i.e. if true, attribute would be Type! and this attribute must always have a value.


isRequiredListRequired
public readonly isRequiredList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! and this attribute's list must always have a value.


typeRequired
public readonly type: Type;

the type of attribute.


intermediateTypeOptional
public readonly intermediateType: IIntermediateType;

the intermediate type linked to this attribute (i.e. an interface or an object).


InputType

Input Types are abstract types that define complex objects.

They are used in arguments to represent

Initializers

import { InputType } from 'awscdk-appsync-utils'

new InputType(name: string, props: IntermediateTypeOptions)
Name Type Description
name string No description.
props IntermediateTypeOptions No description.

nameRequired
  • Type: string

propsRequired

Methods

Name Description
addField Add a field to this Input Type.
attribute Create a GraphQL Type representing this Input Type.
toString Generate the string of this input type.

addField
public addField(options: AddFieldOptions): void

Add a field to this Input Type.

Input Types must have both fieldName and field options.

optionsRequired

the options to add a field.


attribute
public attribute(options?: BaseTypeOptions): GraphqlType

Create a GraphQL Type representing this Input Type.

optionsOptional

the options to configure this attribute.


toString
public toString(): string

Generate the string of this input type.

Properties

Name Type Description
definition {[ key: string ]: IField} the attributes of this type.
name string the name of this type.

definitionRequired
public readonly definition: {[ key: string ]: IField};
  • Type: {[ key: string ]: IField}

the attributes of this type.


nameRequired
public readonly name: string;
  • Type: string

the name of this type.


InterfaceType

Interface Types are abstract types that includes a certain set of fields that other types must include if they implement the interface.

Initializers

import { InterfaceType } from 'awscdk-appsync-utils'

new InterfaceType(name: string, props: IntermediateTypeOptions)
Name Type Description
name string No description.
props IntermediateTypeOptions No description.

nameRequired
  • Type: string

propsRequired

Methods

Name Description
addField Add a field to this Interface Type.
attribute Create a GraphQL Type representing this Intermediate Type.
toString Generate the string of this object type.

addField
public addField(options: AddFieldOptions): void

Add a field to this Interface Type.

Interface Types must have both fieldName and field options.

optionsRequired

the options to add a field.


attribute
public attribute(options?: BaseTypeOptions): GraphqlType

Create a GraphQL Type representing this Intermediate Type.

optionsOptional

the options to configure this attribute.


toString
public toString(): string

Generate the string of this object type.

Properties

Name Type Description
definition {[ key: string ]: IField} the attributes of this type.
name string the name of this type.
directives Directive[] the directives for this object type.

definitionRequired
public readonly definition: {[ key: string ]: IField};
  • Type: {[ key: string ]: IField}

the attributes of this type.


nameRequired
public readonly name: string;
  • Type: string

the name of this type.


directivesOptional
public readonly directives: Directive[];

the directives for this object type.


ObjectType

Object Types are types declared by you.

Initializers

import { ObjectType } from 'awscdk-appsync-utils'

new ObjectType(name: string, props: ObjectTypeOptions)
Name Type Description
name string No description.
props ObjectTypeOptions No description.

nameRequired
  • Type: string

propsRequired

Methods

Name Description
addField Add a field to this Object Type.
attribute Create a GraphQL Type representing this Intermediate Type.
toString Generate the string of this object type.

addField
public addField(options: AddFieldOptions): void

Add a field to this Object Type.

Object Types must have both fieldName and field options.

optionsRequired

the options to add a field.


attribute
public attribute(options?: BaseTypeOptions): GraphqlType

Create a GraphQL Type representing this Intermediate Type.

optionsOptional

the options to configure this attribute.


toString
public toString(): string

Generate the string of this object type.

Properties

Name Type Description
definition {[ key: string ]: IField} the attributes of this type.
name string the name of this type.
directives Directive[] the directives for this object type.
interfaceTypes InterfaceType[] The Interface Types this Object Type implements.
resolvers aws-cdk-lib.aws_appsync.Resolver[] The resolvers linked to this data source.

definitionRequired
public readonly definition: {[ key: string ]: IField};
  • Type: {[ key: string ]: IField}

the attributes of this type.


nameRequired
public readonly name: string;
  • Type: string

the name of this type.


directivesOptional
public readonly directives: Directive[];

the directives for this object type.


interfaceTypesOptional
public readonly interfaceTypes: InterfaceType[];

The Interface Types this Object Type implements.


resolversOptional
public readonly resolvers: Resolver[];
  • Type: aws-cdk-lib.aws_appsync.Resolver[]

The resolvers linked to this data source.


ResolvableField

Resolvable Fields build upon Graphql Types and provide fields that can resolve into operations on a data source.

Initializers

import { ResolvableField } from 'awscdk-appsync-utils'

new ResolvableField(options: ResolvableFieldOptions)
Name Type Description
options ResolvableFieldOptions No description.

optionsRequired

Methods

Name Description
argsToString Generate the args string of this resolvable field.
directivesToString Generate the directives for this field.
toString Generate the string for this attribute.

argsToString
public argsToString(): string

Generate the args string of this resolvable field.

directivesToString
public directivesToString(modes?: AuthorizationType[]): string

Generate the directives for this field.

modesOptional
  • Type: aws-cdk-lib.aws_appsync.AuthorizationType[]

toString
public toString(): string

Generate the string for this attribute.

Static Functions

Name Description
awsDate AWSDate scalar type represents a valid extended ISO 8601 Date string.
awsDateTime AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string.
awsEmail AWSEmail scalar type represents an email address string (i.e.[email protected]).
awsIpAddress AWSIPAddress scalar type respresents a valid IPv4 of IPv6 address string.
awsJson AWSJson scalar type represents a JSON string.
awsPhone AWSPhone scalar type represents a valid phone number. Phone numbers maybe be whitespace delimited or hyphenated.
awsTime AWSTime scalar type represents a valid extended ISO 8601 Time string.
awsTimestamp AWSTimestamp scalar type represents the number of seconds since 1970-01-01T00:00Z.
awsUrl AWSURL scalar type represetns a valid URL string.
boolean Boolean scalar type is a boolean value: true or false.
float Float scalar type is a signed double-precision fractional value.
id ID scalar type is a unique identifier. ID type is serialized similar to String.
int Int scalar type is a signed non-fractional numerical value.
intermediate an intermediate type to be added as an attribute (i.e. an interface or an object type).
string String scalar type is a free-form human-readable text.

awsDate
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsDate(options?: BaseTypeOptions)

AWSDate scalar type represents a valid extended ISO 8601 Date string.

In other words, accepts date strings in the form of YYYY-MM-DD. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsDateTime
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsDateTime(options?: BaseTypeOptions)

AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string.

In other words, accepts date strings in the form of YYYY-MM-DDThh:mm:ss.sssZ. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsEmail
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsEmail(options?: BaseTypeOptions)

AWSEmail scalar type represents an email address string (i.e.[email protected]).

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsIpAddress
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsIpAddress(options?: BaseTypeOptions)

AWSIPAddress scalar type respresents a valid IPv4 of IPv6 address string.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsJson
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsJson(options?: BaseTypeOptions)

AWSJson scalar type represents a JSON string.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsPhone
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsPhone(options?: BaseTypeOptions)

AWSPhone scalar type represents a valid phone number. Phone numbers maybe be whitespace delimited or hyphenated.

The number can specify a country code at the beginning, but is not required for US phone numbers.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsTime
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsTime(options?: BaseTypeOptions)

AWSTime scalar type represents a valid extended ISO 8601 Time string.

In other words, accepts date strings in the form of hh:mm:ss.sss. It accepts time zone offsets.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsTimestamp
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsTimestamp(options?: BaseTypeOptions)

AWSTimestamp scalar type represents the number of seconds since 1970-01-01T00:00Z.

Timestamps are serialized and deserialized as numbers.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


awsUrl
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.awsUrl(options?: BaseTypeOptions)

AWSURL scalar type represetns a valid URL string.

URLs wihtout schemes or contain double slashes are considered invalid.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


boolean
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.boolean(options?: BaseTypeOptions)

Boolean scalar type is a boolean value: true or false.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


float
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.float(options?: BaseTypeOptions)

Float scalar type is a signed double-precision fractional value.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


id
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.id(options?: BaseTypeOptions)

ID scalar type is a unique identifier. ID type is serialized similar to String.

Often used as a key for a cache and not intended to be human-readable.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


int
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.int(options?: BaseTypeOptions)

Int scalar type is a signed non-fractional numerical value.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


intermediate
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.intermediate(options?: GraphqlTypeOptions)

an intermediate type to be added as an attribute (i.e. an interface or an object type).

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList - intermediateType.


string
import { ResolvableField } from 'awscdk-appsync-utils'

ResolvableField.string(options?: BaseTypeOptions)

String scalar type is a free-form human-readable text.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


Properties

Name Type Description
isList boolean property determining if this attribute is a list i.e. if true, attribute would be [Type].
isRequired boolean property determining if this attribute is non-nullable i.e. if true, attribute would be Type! and this attribute must always have a value.
isRequiredList boolean property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! and this attribute's list must always have a value.
type Type the type of attribute.
intermediateType IIntermediateType the intermediate type linked to this attribute (i.e. an interface or an object).
fieldOptions ResolvableFieldOptions The options to make this field resolvable.

isListRequired
public readonly isList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a list i.e. if true, attribute would be [Type].


isRequiredRequired
public readonly isRequired: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is non-nullable i.e. if true, attribute would be Type! and this attribute must always have a value.


isRequiredListRequired
public readonly isRequiredList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! and this attribute's list must always have a value.


typeRequired
public readonly type: Type;

the type of attribute.


intermediateTypeOptional
public readonly intermediateType: IIntermediateType;

the intermediate type linked to this attribute (i.e. an interface or an object).


fieldOptionsOptional
public readonly fieldOptions: ResolvableFieldOptions;

The options to make this field resolvable.


UnionType

Union Types are abstract types that are similar to Interface Types, but they cannot to specify any common fields between types.

Note that fields of a union type need to be object types. In other words, you can't create a union type out of interfaces, other unions, or inputs.

Initializers

import { UnionType } from 'awscdk-appsync-utils'

new UnionType(name: string, options: UnionTypeOptions)
Name Type Description
name string No description.
options UnionTypeOptions No description.

nameRequired
  • Type: string

optionsRequired

Methods

Name Description
addField Add a field to this Union Type.
attribute Create a GraphQL Type representing this Union Type.
toString Generate the string of this Union type.

addField
public addField(options: AddFieldOptions): void

Add a field to this Union Type.

Input Types must have field options and the IField must be an Object Type.

optionsRequired

the options to add a field.


attribute
public attribute(options?: BaseTypeOptions): GraphqlType

Create a GraphQL Type representing this Union Type.

optionsOptional

the options to configure this attribute.


toString
public toString(): string

Generate the string of this Union type.

Properties

Name Type Description
definition {[ key: string ]: IField} the attributes of this type.
name string the name of this type.

definitionRequired
public readonly definition: {[ key: string ]: IField};
  • Type: {[ key: string ]: IField}

the attributes of this type.


nameRequired
public readonly name: string;
  • Type: string

the name of this type.


Protocols

IField

A Graphql Field.

Methods

Name Description
argsToString Generate the arguments for this field.
directivesToString Generate the directives for this field.
toString Generate the string for this attribute.

argsToString
public argsToString(): string

Generate the arguments for this field.

directivesToString
public directivesToString(modes?: AuthorizationType[]): string

Generate the directives for this field.

modesOptional
  • Type: aws-cdk-lib.aws_appsync.AuthorizationType[]

the authorization modes of the graphql api.


toString
public toString(): string

Generate the string for this attribute.

Properties

Name Type Description
isList boolean property determining if this attribute is a list i.e. if true, attribute would be [Type].
isRequired boolean property determining if this attribute is non-nullable i.e. if true, attribute would be Type! and this attribute must always have a value.
isRequiredList boolean property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! and this attribute's list must always have a value.
type Type the type of attribute.
fieldOptions ResolvableFieldOptions The options to make this field resolvable.
intermediateType IIntermediateType the intermediate type linked to this attribute (i.e. an interface or an object).

isListRequired
public readonly isList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a list i.e. if true, attribute would be [Type].


isRequiredRequired
public readonly isRequired: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is non-nullable i.e. if true, attribute would be Type! and this attribute must always have a value.


isRequiredListRequired
public readonly isRequiredList: boolean;
  • Type: boolean
  • Default: false

property determining if this attribute is a non-nullable list i.e. if true, attribute would be [ Type ]! and this attribute's list must always have a value.


typeRequired
public readonly type: Type;

the type of attribute.


fieldOptionsOptional
public readonly fieldOptions: ResolvableFieldOptions;

The options to make this field resolvable.


intermediateTypeOptional
public readonly intermediateType: IIntermediateType;

the intermediate type linked to this attribute (i.e. an interface or an object).


IIntermediateType

Intermediate Types are types that includes a certain set of fields that define the entirety of your schema.

Methods

Name Description
addField Add a field to this Intermediate Type.
attribute Create an GraphQL Type representing this Intermediate Type.
toString Generate the string of this object type.

addField
public addField(options: AddFieldOptions): void

Add a field to this Intermediate Type.

optionsRequired

attribute
public attribute(options?: BaseTypeOptions): GraphqlType

Create an GraphQL Type representing this Intermediate Type.

optionsOptional

the options to configure this attribute - isList - isRequired - isRequiredList.


toString
public toString(): string

Generate the string of this object type.

Properties

Name Type Description
definition {[ key: string ]: IField} the attributes of this type.
name string the name of this type.
directives Directive[] the directives for this object type.
interfaceTypes InterfaceType[] The Interface Types this Intermediate Type implements.
intermediateType IIntermediateType the intermediate type linked to this attribute (i.e. an interface or an object).
resolvers aws-cdk-lib.aws_appsync.Resolver[] The resolvers linked to this data source.

definitionRequired
public readonly definition: {[ key: string ]: IField};
  • Type: {[ key: string ]: IField}

the attributes of this type.


nameRequired
public readonly name: string;
  • Type: string

the name of this type.


directivesOptional
public readonly directives: Directive[];

the directives for this object type.


interfaceTypesOptional
public readonly interfaceTypes: InterfaceType[];

The Interface Types this Intermediate Type implements.


intermediateTypeOptional
public readonly intermediateType: IIntermediateType;

the intermediate type linked to this attribute (i.e. an interface or an object).


resolversOptional
public readonly resolvers: Resolver[];
  • Type: aws-cdk-lib.aws_appsync.Resolver[]

The resolvers linked to this data source.


ISourceApiAssociationMergeOperationProvider

This interface for the provider of the custom resource that will be used to initiate a merge operation during Cloudformation update.

Methods

Name Description
associateSourceApiAssociation This function associates a source api association with the provider.

associateSourceApiAssociation
public associateSourceApiAssociation(sourceApiAssociation: ISourceApiAssociation): void

This function associates a source api association with the provider.

This method can be used for adding permissions to merge a specific source api association to the custom resource provider.

sourceApiAssociationRequired
  • Type: aws-cdk-lib.aws_appsync.ISourceApiAssociation

The association to associate.


Properties

Name Type Description
node constructs.Node The tree node.
serviceToken string Service token which is used for identifying the handler used for the merge operation custom resource.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


serviceTokenRequired
public readonly serviceToken: string;
  • Type: string

Service token which is used for identifying the handler used for the merge operation custom resource.


Enums

Type

Enum containing the Types that can be used to define ObjectTypes.

Members

Name Description
ID ID scalar type is a unique identifier. ID type is serialized similar to String.
STRING String scalar type is a free-form human-readable text.
INT Int scalar type is a signed non-fractional numerical value.
FLOAT Float scalar type is a signed double-precision fractional value.
BOOLEAN Boolean scalar type is a boolean value: true or false.
AWS_DATE AWSDate scalar type represents a valid extended ISO 8601 Date string.
AWS_TIME AWSTime scalar type represents a valid extended ISO 8601 Time string.
AWS_DATE_TIME AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string.
AWS_TIMESTAMP AWSTimestamp scalar type represents the number of seconds since 1970-01-01T00:00Z.
AWS_EMAIL AWSEmail scalar type represents an email address string (i.e.[email protected]).
AWS_JSON AWSJson scalar type represents a JSON string.
AWS_URL AWSURL scalar type represetns a valid URL string.
AWS_PHONE AWSPhone scalar type represents a valid phone number. Phone numbers maybe be whitespace delimited or hyphenated.
AWS_IP_ADDRESS AWSIPAddress scalar type respresents a valid IPv4 of IPv6 address string.
INTERMEDIATE Type used for Intermediate Types (i.e. an interface or an object type).

ID

ID scalar type is a unique identifier. ID type is serialized similar to String.

Often used as a key for a cache and not intended to be human-readable.


STRING

String scalar type is a free-form human-readable text.


INT

Int scalar type is a signed non-fractional numerical value.


FLOAT

Float scalar type is a signed double-precision fractional value.


BOOLEAN

Boolean scalar type is a boolean value: true or false.


AWS_DATE

AWSDate scalar type represents a valid extended ISO 8601 Date string.

In other words, accepts date strings in the form of YYYY-MM-DD. It accepts time zone offsets.

https://en.wikipedia.org/wiki/ISO_8601#Calendar_dates


AWS_TIME

AWSTime scalar type represents a valid extended ISO 8601 Time string.

In other words, accepts date strings in the form of hh:mm:ss.sss. It accepts time zone offsets.

https://en.wikipedia.org/wiki/ISO_8601#Times


AWS_DATE_TIME

AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string.

In other words, accepts date strings in the form of YYYY-MM-DDThh:mm:ss.sssZ. It accepts time zone offsets.

https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations


AWS_TIMESTAMP

AWSTimestamp scalar type represents the number of seconds since 1970-01-01T00:00Z.

Timestamps are serialized and deserialized as numbers.


AWS_EMAIL

AWSEmail scalar type represents an email address string (i.e.[email protected]).


AWS_JSON

AWSJson scalar type represents a JSON string.


AWS_URL

AWSURL scalar type represetns a valid URL string.

URLs wihtout schemes or contain double slashes are considered invalid.


AWS_PHONE

AWSPhone scalar type represents a valid phone number. Phone numbers maybe be whitespace delimited or hyphenated.

The number can specify a country code at the beginning, but is not required for US phone numbers.


AWS_IP_ADDRESS

AWSIPAddress scalar type respresents a valid IPv4 of IPv6 address string.


INTERMEDIATE

Type used for Intermediate Types (i.e. an interface or an object type).