Skip to main content

OData / Microsoft Graph

image

This handler allows you to load remote OData metadata/schema as GraphQL Schema.

To get started, install the handler library from NPM:

$ yarn add @graphql-mesh/odata

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

sources:
- name: TripPin
handler:
odata:
baseUrl: https://services.odata.org/TripPinRESTierService/

Dynamic Header Values#

Mesh 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.

From Context (HTTP Header for mesh serve)#

sources:
- name: MyGraphQLApi
handler:
odata:
baseUrl: https://graph.microsoft.com/v1.0
operationHeaders:
# Please do not use capital letters while getting the headers
Authorization: Bearer {context.headers['x-my-api-token']}
# You can also access to the cookies like below;
# Authorization: Bearer {context.cookies.myApiToken}

And for mesh serve, you can pass the value using x-my-graphql-api-token HTTP header.

From Environmental Variable#

MY_API_TOKEN is the name of the environmental variable you have the value.

sources:
- name: MyGraphQLApi
handler:
odata:
baseUrl: https://graph.microsoft.com/v1.0
operationHeaders:
Authorization: Bearer ${MY_API_TOKEN}

Codesandbox Example#

You can check out our TripPin example that uses OData handler.

Config API Reference#

  • baseUrl (type: String, required) - Base URL for OData API
  • metadata (type: String) - Custom $metadata File or URL
  • operationHeaders (type: JSON) - Headers to be used with the operation requests
  • schemaHeaders (type: JSON) - Headers to be used with the $metadata requests
  • batch (type: String (multipart | json)) - Enable batching
  • expandNavProps (type: Boolean) - Use $expand for navigation props instead of seperate HTTP requests (Default: false)
  • customFetch (type: Any) - Custom Fetch