How to use the graphql-transformer-core.uploadAPIProject function in graphql-transformer-core

To help you get started, we’ve selected a few graphql-transformer-core examples, based on popular ways it is used in public projects.

github aws-amplify / amplify-cli / packages / amplify-provider-awscloudformation / lib / upload-appsync-files.js View on Github external
// There can only be one appsync resource
  if (allApiResourceToUpdate.length > 0) {
    const resource = allApiResourceToUpdate[0];
    const { category, resourceName } = resource;
    const resourceDir = path.normalize(path.join(backEndDir, category, resourceName));
    const resourceBuildDir = path.normalize(path.join(resourceDir, 'build'));

    const deploymentRootKey = await getDeploymentRootKey(resourceDir);
    writeUpdatedParametersJson(resource, deploymentRootKey);

    // Upload build/* to S3.
    const s3Client = await new S3(context);
    if (!fs.existsSync(resourceBuildDir)) {
      return;
    }
    await TransformPackage.uploadAPIProject({
      directory: resourceBuildDir,
      upload: async blob => {
        const { Key, Body } = blob;
        const fullKey = `${deploymentRootKey}/${Key}`;

        return await s3Client.uploadFile({
          Key: fullKey,
          Body,
        });
      },
    });
  } else if (allApiResources.length > 0) {
    // We need to update the parameters file even when we are not deploying the API
    // category to fix a bug around deployments on CI/CD platforms. Basically if a
    // build has not run on this machine before and we are updating a non-api category,
    // the params will not have the S3DeploymentRootKey parameter and will fail.