class UnionType
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.AppSync.UnionType |
Java | software.amazon.awscdk.services.appsync.UnionType |
Python | aws_cdk.aws_appsync.UnionType |
TypeScript (source) | @aws-cdk/aws-appsync » UnionType |
Implements
IIntermediate
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.
Example
declare const api: appsync.GraphqlApi;
const string = appsync.GraphqlType.string();
const human = new appsync.ObjectType('Human', { definition: { name: string } });
const droid = new appsync.ObjectType('Droid', { definition: { name: string } });
const starship = new appsync.ObjectType('Starship', { definition: { name: string } }););
const search = new appsync.UnionType('Search', {
definition: [ human, droid, starship ],
});
api.addType(search);
Initializer
new UnionType(name: string, options: UnionTypeOptions)
Parameters
- name
string - options
UnionType Options
Properties
| Name | Type | Description |
|---|---|---|
| definition | { [string]: IField } | the attributes of this type. |
| name | string | the name of this type. |
| modes? | Authorization[] | the authorization modes supported by this intermediate type. |
definition
Type:
{ [string]: IField }
the attributes of this type.
name
Type:
string
the name of this type.
modes?
Type:
Authorization[]
(optional)
the authorization modes supported by this intermediate type.
Methods
| Name | Description |
|---|---|
| add | Add a field to this Union Type. |
| attribute(options?) | Create a GraphQL Type representing this Union Type. |
| to | Generate the string of this Union type. |
addField(options)
public addField(options: AddFieldOptions): void
Parameters
- options
Add— the options to add a field.Field Options
Add a field to this Union Type.
Input Types must have field options and the IField must be an Object Type.
attribute(options?)
public attribute(options?: BaseTypeOptions): GraphqlType
Parameters
- options
Base— the options to configure this attribute.Type Options
Returns
Create a GraphQL Type representing this Union Type.
toString()
public toString(): string
Returns
string
Generate the string of this Union type.

.NET
Java
Python
TypeScript (