Expand my Community achievements bar.

Can't connect Star Wars REST API to API Mesh

Avatar

Level 1

I want to connect a REST API https://swapi.dev/api/ to API Mesh. My mesh.json looks like this:

 

{
  "meshConfig": {
    "sources": [
      {
        "name": "RESTSWAPI",
        "handler": {
          "openapi": {
            "source": "https://swapi.dev/api/"
          }
        }
      }
    ]
  }
}

 




But I get this error message:

Your mesh errored out with the following error.  Building Mesh with config: /usr/src/node-app/8ab88e57-f4dd-42a2-b6b1-c82e5b219704

  Mesh Cleaning existing artifacts

  Mesh Reading the configuration

  Mesh Generating the unified schema

  Mesh - RESTSWAPI Dereferencing the bundle

  Mesh - RESTSWAPI Creating the GraphQL Schema from dereferenced schema

  Mesh - RESTSWAPI Failed to generate the schema Error: The visitor result should be a SchemaComposer instance.

    at getGraphQLSchemaFromDereferencedJSONSchema (/usr/src/node-app/node_modules/@omnigraph/json-schema/index.js:2317:15)

    at async OpenAPIHandler.getMeshSource (/usr/src/node-app/node_modules/@graphql-mesh/openapi/index.js:49:24)

    at async /usr/src/node-app/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:133:28

    at async Promise.allSettled (index 0)

    at async getMesh (/usr/src/node-app/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:128:5)

    at async Object.handler (/usr/src/node-app/node_modules/@graphql-mesh/cli/cjs/index.js:311:53)

  Mesh Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh with DEBUG=1 environmental variable to get more verbose output.

    at getMesh (/usr/src/node-app/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:167:15)

    at async Object.handler (/usr/src/node-app/node_modules/@graphql-mesh/cli/cjs/index.js:311:53)

Is Star Wars API not a Open API / Swagger API? 

Thank you for your help

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Reply

Avatar

Level 2

Hey @JanTa1,

 

The error you're encountering while trying to connect the Star Wars API (SWAPI) to API Mesh suggests a few potential issues, particularly with how the OpenAPI handler is being used in your mesh.json configuration.

The SWAPI, as available at https://swapi.dev/api/, is a RESTful API but it doesn't natively provide an OpenAPI (formerly known as Swagger) specification. The OpenAPI handler in GraphQL Mesh expects an OpenAPI specification to generate a GraphQL schema. Since SWAPI doesn't provide this, the process fails with the error message you're seeing.

Possible Solutions:

  1. Manual OpenAPI Specification:

    • If you really need to use GraphQL Mesh with SWAPI, one approach would be to manually create an OpenAPI specification for SWAPI. This involves defining all the endpoints, request/response structures, etc., in an OpenAPI format. This can be time-consuming and requires maintenance if the API changes.
  2. Use a Different Handler:

    • Since SWAPI does not provide an OpenAPI specification, consider using a different handler in GraphQL Mesh that is more suitable for generic REST APIs. For example, the JSON Schema handler might be a more appropriate choice.
  3. Use GraphQL Mesh with Other APIs:

    • Alternatively, you might want to connect GraphQL Mesh with APIs that already provide an OpenAPI specification.
  4. Check Community Resources:

    • Sometimes, community-driven OpenAPI specifications for popular APIs are available. Check if there's an existing OpenAPI spec for SWAPI created by the community.
  5. Debugging and Logging:

    • Run GraphQL Mesh with the DEBUG=1 environment variable as suggested in the error message. This might provide more detailed logs that can help in troubleshooting.
  6. Consult Documentation:

    • Review the GraphQL Mesh documentation and SWAPI documentation to ensure that all configurations and usage align with the expected standards.

In summary, the primary issue here is the absence of an OpenAPI specification for SWAPI, which is required for the OpenAPI handler in GraphQL Mesh to function correctly. Exploring alternative handlers or creating a custom OpenAPI specification for SWAPI are potential ways to resolve this.

 

Regards,

Eugene