DataApiBuilderException while trying to run swa start

278 Views Asked by At

I'm trying to follow the instructions present in this tutorial but I'm getting an error when trying to run swa start

swa start src --api-location api --data-api-location swa-db-connections

Everything was working fine before I tried to implement Cosmos DB, so, if I run the command without the --data-api-location swa-db-connections part, everything works fine.

I'm getting the following output:

Welcome to Azure Static Web Apps CLI (1.1.4)

***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

[dataApi] Information: Microsoft.DataApiBuilder 0.9.6-rc+529471ba3b50e617439c57548891fdff7ec1c3fa
[dataApi] Information: User provided config file: staticwebapp.database.config.json
[dataApi] Loading config file from staticwebapp.database.config.json.
[dataApi] Information: Loaded config file: staticwebapp.database.config.json
[dataApi] Information: Setting default minimum LogLevel: Error for Production mode.
[dataApi] Starting the runtime engine...
[dataApi] Redirecting to https is disabled.
[dataApi] Loading config file from staticwebapp.database.config.json.
[swa]
[swa] Using workflow file:
[swa]   C:\Users\alexa\source\repos\az-lead\.github\workflows\azure-static-web-apps-icy-pebble-0c3175610.yml
[dataApi] info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63]
[dataApi]       User profile is available. Using 'C:\Users\alexa\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
[dataApi] fail: Azure.DataApiBuilder.Service.Startup[0]
[dataApi]       OpenAPI Documentor initialization failed.
[dataApi]       Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: OpenAPI description document can't be created when the REST endpoint is disabled globally.
[dataApi]          at Azure.DataApiBuilder.Core.Services.OpenApiDocumentor.CreateDocument() in /_/src/Core/Services/OpenAPI/OpenApiDocumentor.cs:line 108
[dataApi]          at Azure.DataApiBuilder.Service.Startup.PerformOnConfigChangeAsync(IApplicationBuilder app) in /_/src/Service/Startup.cs:line 687
[dataApi] Unable to launch the runtime due to an error.
[dataApi] Error: Failed to start the engine.
[dataApi] cd "C:\Users\alexa\source\repos\az-lead\swa-db-connections" && "C:\Users\alexa\.swa\dataApiBuilder\0.9.6-rc\Microsoft.DataApiBuilder.exe" start -c staticwebapp.database.config.json --no-https-redirect exited with code 0
--> Sending SIGTERM to other processes..
[swa] node "C:\Users\alexa\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 1
✖ SWA emulator stoped because SWA emulator exited with code 1.

staticwebapp.database.config.json

{
  "$schema": "https://github.com/Azure/data-api-builder/releases/latest/download/dab.draft.schema.json",
  "data-source": {
    "database-type": "cosmosdb_nosql",
    "options": {
      "database": "MyTestPersonDatabase",
      "schema": "staticwebapp.database.schema.gql"
    },
    "connection-string": "@env('DATABASE_CONNECTION_STRING')"
  },
  "runtime": {
    "graphql": {
      "allow-introspection": true,
      "enabled": true,
      "path": "/graphql"
    },
    "host": {
      "mode": "production",
      "cors": {
        "origins": ["http://localhost:4280"],
        "allow-credentials": false
      },
      "authentication": {
        "provider": "StaticWebApps"
      }
    }
  },
  "entities": {
    "Person": {
      "source": "MyTestPersonContainer",
      "permissions": [
        {
          "actions": ["*"],
          "role": "anonymous"
        }
      ]
    }
  }
}

staticwebapp.database.schema.gql

type Person @model {
  id: ID
  Name: String
}

staticwebapp.config.json

{
    "responseOverrides": {
      "404": {
        "rewrite": "/404.html"
      },
      "401": {
        "redirect": "/.auth/login/aad?post_login_redirect_uri=.referrer",
        "statusCode": 302
      }
    },
    "routes": [
      {
        "route": "/admin*",
        "allowedRoles": ["administrator"]
      },
      {
        "route": "/company*",
        "allowedRoles": ["operator", "manager"]
      },
      {
        "route": "/api/postLogin",
        "allowedRoles": ["authenticated"]
      },
      {
        "route": "/.auth/login/twitter",
        "statusCode": 404
      },
      {
        "route": "/.auth/login/github",
        "statusCode": 404
      },
      {
        "route": "/.auth/login/google",
        "statusCode": 404
      },
      {
        "route": "/.auth/login/facebook",
        "statusCode": 404
      }
    ]
  }

I've already tryed:

  • deleting everything from my database and creating again
  • deleting every file associated with the tutorial and creating again
1

There are 1 best solutions below

2
On

I followed this Document for creating this project and I got the output when I run this command

swa start ./src --data-api-location swa-db-connections

enter image description here

Output : enter image description here

Azure Cosmosdb : enter image description here

Make sure Cosmosdb Connectionstring is present in
.env file :

DATABASE_CONNECTION_STRING='AccountEndpoint=https://AzureCosmosDBaccount.documents.azure.com:443/;AccountKey=accountkey'

staticwebapp.database.config.json :

{
"$schema": "https://github.com/Azure/data-api-builder/releases/latest/download/dab.draft.schema.json",
"data-source": {
"database-type": "cosmosdb_nosql",
"options": {
"database": "DatabaseName",
"schema": "staticwebapp.database.schema.gql"
},
"connection-string": "@env('DATABASE_CONNECTION_STRING')"
},
"runtime": {
"graphql": {
"allow-introspection": true,
"enabled": true,
"path": "/graphql"
},
"host": {
"mode": "production",
"cors": {
"origins": ["http://localhost:4280"],
"allow-credentials": false
},
"authentication": {
"provider": "StaticWebApps"
}
}
},
"entities": {
"Person": {
"source": "ContainerName",
"permissions": [
{
"actions": ["*"],
"role": "anonymous"
}
]
}
}
}

staticwebapp.database.schema.gql :

type Person @model {
  id: ID
  Name: String
}