JSON Schema

image

This handler allows you to load any remote REST service, and describe it's request/response using the YAML config.

With this handler, you can easily customize and control the built GraphQL schema.

To get started, install the handler library from NPM:

$ yarn add @graphql-mesh/json-schema

Now, you can use it directly in your Mesh config file:

sources:
- name: MyApi
handler:
jsonSchema:
baseUrl: https://some-service-url/endpoint-path/
operations:
- type: Query
field: users
path: /users
method: GET
responseSchema: ./json-schemas/users.json

Codesandbox Example

You can check out our example that uses JSON Schema handler with mock data.

Config API Reference

  • baseUrl (type: String, required)
  • operationHeaders (type: JSON)
  • schemaHeaders (type: JSON)
  • operations (type: Array of Object, required):
    • field (type: String, required)
    • path (type: String, required)
    • description (type: String)
    • type (type: String (Query | Mutation), required)
    • method (type: String (GET | DELETE | POST | PUT), required)
    • requestSchema (type: String)
    • responseSchema (type: String)
    • requestSample (type: String)
    • responseSample (type: String)
    • headers (type: JSON)