JSON Schema
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:
Now, you can use it directly in your Mesh config file:
#
Dynamic ValuesMesh can take dynamic values from the GraphQL Context or the environmental variables. If you use mesh serve
, GraphQL Context will be the incoming HTTP request.
The expression inside dynamic values should be as in JS.
mesh serve
)#
From Context (HTTP Header for And for mesh serve
, you can pass the value using x-my-graphql-api-token
HTTP header.
#
From Environmental VariableMY_API_TOKEN
is the name of the environmental variable you have the value.
#
From ArgumentsMesh automatically generates arguments for operations if needed;
This example operation definition will generate a root field with id: ID
argument, then Mesh will interpolate the expression in path
to get id
value from args
.
#
Codesandbox ExampleYou can check out our example that uses JSON Schema handler with mock data.
#
Config API ReferencebaseUrl
(type:String
)operationHeaders
(type:JSON
)schemaHeaders
(type:JSON
)operations
(type:Array of Object
, required):field
(type:String
, required)path
(type:String
)pubsubTopic
(type:String
)description
(type:String
)type
(type:String (Query | Mutation | Subscription)
, required)method
(type:String (GET | DELETE | POST | PUT | PATCH)
)requestSchema
(type:Any
)requestSample
(type:Any
)requestTypeName
(type:String
)responseSample
(type:Any
)responseSchema
(type:Any
)responseTypeName
(type:String
)argTypeMap
(type:JSON
)headers
(type:JSON
)
disableTimestampScalar
(type:Boolean
)baseSchema
(type:Any
)errorMessageField
(type:String
) - Field name of your custom error object (default: 'message')