AppSync client

This page contains examples with the AppSync client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.

The AppSync package could be installed with Composer.

composer require async-aws/app-sync

A new client object may be instantiated by:

use AsyncAws\AppSync\AppSyncClient; $appSync = new AppSyncClient();

The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:

use AsyncAws\AppSync\AppSyncClient; $appSync = new AppSyncClient([ 'accessKeyId' => 'my_access_key', 'accessKeySecret' => 'my_access_secret', 'region' => 'eu-central-1', ]);

For all available options, see the configuration reference.

Usage

Create resolver

use AsyncAws\AppSync\AppSyncClient; use AsyncAws\AppSync\Enum\ResolverKind; $appSync = new AppSyncClient(); $requestMapping = file_get_contents('/mappings/echo.req.vtl'); $responseMapping = file_get_contents('/mappings/echo.res.vtl'); $appSync->createResolver([ 'apiId' => 'my-api', 'typeName' => 'Query', 'fieldName' => 'echo', 'dataSourceName' => 'EchoApi', 'requestMappingTemplate' => $requestMapping, 'responseMappingTemplate' => $responseMapping, 'kind' => ResolverKind::UNIT, ]);

List resolvers

use AsyncAws\AppSync\AppSyncClient; $appSync= new AppSyncClient(); $appSync->listResolvers([ 'apiId' => 'my-api', 'typeName' => 'Query', 'maxResults' => 100, ]);

Start schema creation

use AsyncAws\AppSync\AppSyncClient; $appSync= new AppSyncClient(); $schemaDefinition = file_get_contents('/schema.graphql'); $appSync->startSchemaCreation([ 'apiId' => 'my-api', 'definition' => $schemaDefinition, ]);

List API keys

use AsyncAws\AppSync\AppSyncClient; $appSync= new AppSyncClient(); $appSync->listApiKeys([ 'apiId' => 'my-api', 'maxResults' => 10, ]);

The source code to this page is found on GitHub.