GraphQL client tutorial
GraphQL provides a rich client and tooling experience for consuming data from a compliant service. RAPID makes it easy to build rich, interoperable, enterprise-ready, standards-based services.
Since RAPID services comply with the OData protocol, they can be used with tooling that targets OData services, such as GraphQL Mesh.
In this tutorial we'll see how easy it is to take advantage of GraphQL's client and tooling experiences with your RAPID service using the GraphQL Mesh OData Handler.
Create a node.js project
To create a new node.js project:
- Install node.js and npm package manager from the Node.js website
- For a new project, run "npm init" to create a new package.json file
Install the GraphQL Mesh OData Handler
To install GraphQL Mesh to work with your RAPID service, first, install the GraphQL Mesh framework as follows:
npm install graphql @graphql-mesh/cli
Next, add the OData Handler:
npm install @graphql-mesh/odata
Configure the OData Handler
Create a GraphQL Mesh Configuration file named .meshrc.yaml
at the root of your project, with a pointer to your RAPID service. The following configuration references our Jetsons Sample Service, but you can replace the name and baseUrl with a pointer to your own RAPID service.
sources:
- name: Jetsons
handler:
odata:
endpoint: https://jetsons.azurewebsites.net/
schemaHeaders: { "accept": "application/xml" }
Note the schemaHeaders line. GraphQL Mesh currently supports only the XML CSDL metadata format. Since the Jetsons service defaults to the JSON format, the accept
header is required in order to force the service to return metadata in the application/xml
format.
More information on configuring the Handler can be found in the OData Handler Documentation.
Preview your service with GraphQL
To test using GraphQL against your service, execute the following command:
npx mesh dev
You can now use GraphiQL to try out a dynamically generated client at http://localhost:4000
Build your client
To build a stand-alone GraphQL Client for your service, run the following commands:
npx mesh build
You can now explore the artifacts, such as the generated GraphQL schema: schema.graphql
, from the .mesh folder.
Deploy a GraphQL SDK for your client
Once you have built your GraphQL client, you can deploy it as a Gateway or Generate an SDK to call it directly from within your applications.