Class AppSyncClient

A tiny, fully-typed AWS AppSync GraphQL client.

import { AppSyncClient } from 'aws-appsync-js';

const client = new AppSyncClient({
url: 'https://abc.appsync-api.us-east-1.amazonaws.com/graphql',
auth: { type: 'apiKey', apiKey: 'da2-...' },
});

const { events } = await client.request<{ events: Event[] }>(`
query { events { id name } }
`);

Constructors

Methods

  • Send a GraphQL operation (query or mutation) to AppSync.

    Type Parameters

    Parameters

    Returns Promise<TData>

    The data payload, not the full response envelope. Pass { throwOnGraphQLError: false } if you need the raw response.

    AppSyncGraphQLError when the server returns errors.

    AppSyncHttpError on a non-2xx HTTP response.

    AppSyncNetworkError when fetch itself rejects.

    AppSyncAbortError when the request is aborted or times out.

    const data = await client.request<{ me: { id: string } }>(`query { me { id } }`);
    
    import { GetUserDocument } from './generated/graphql';
    const data = await client.request(GetUserDocument, { id: '1' });
    // ^? GetUserQuery
  • Send a GraphQL operation (query or mutation) to AppSync.

    Type Parameters

    Parameters

    Returns Promise<TData>

    The data payload, not the full response envelope. Pass { throwOnGraphQLError: false } if you need the raw response.

    AppSyncGraphQLError when the server returns errors.

    AppSyncHttpError on a non-2xx HTTP response.

    AppSyncNetworkError when fetch itself rejects.

    AppSyncAbortError when the request is aborted or times out.

    const data = await client.request<{ me: { id: string } }>(`query { me { id } }`);
    
    import { GetUserDocument } from './generated/graphql';
    const data = await client.request(GetUserDocument, { id: '1' });
    // ^? GetUserQuery
  • Send a GraphQL operation (query or mutation) to AppSync.

    Type Parameters

    Parameters

    Returns Promise<TData>

    The data payload, not the full response envelope. Pass { throwOnGraphQLError: false } if you need the raw response.

    AppSyncGraphQLError when the server returns errors.

    AppSyncHttpError on a non-2xx HTTP response.

    AppSyncNetworkError when fetch itself rejects.

    AppSyncAbortError when the request is aborted or times out.

    const data = await client.request<{ me: { id: string } }>(`query { me { id } }`);
    
    import { GetUserDocument } from './generated/graphql';
    const data = await client.request(GetUserDocument, { id: '1' });
    // ^? GetUserQuery