Question
· Oct 11

How can I create a hybrid REST and GraphQL API layer over IRIS data using ObjectScript?

We want to expose both REST and GraphQL endpoints over the same data models. Is there a way to implement or integrate GraphQL with ObjectScript and map to class methods?

Discussion (1)2
Log in or sign up to continue

To create a hybrid REST and GraphQL API layer over InterSystems IRIS data using ObjectScript:

  1. REST API:

    • IRIS provides native support for REST APIs using ObjectScript and the %CSP.REST framework. You can define routes with methods like GET, POST, etc., using the UrlMap XData block. Business logic can be linked to each route via methods in your ObjectScript class [1][2].
  2. GraphQL Integration:

    • InterSystems IRIS supports GraphQL via the open-source package GraphQL. This allows you to define a GraphQL schema and resolver functions to interact with IRIS data. You can create a GraphQL schema for your object models and expose them as APIs.
    • Two common methods include:
      • Using the GraphQL package on the Open Exchange, with modules for defining and exposing your schemas.
      • Running a GraphQL server connected to IRIS using Python frameworks like Graphene and SQLAlchemy. The setup involves creating database models and defining the GraphQL schema [3][4][5].
  3. Best Practices for Hybrid Approach:

    • Both endpoints (REST and GraphQL) can share the same data models by mapping ObjectScript methods and persistent classes into the GraphQL schema and REST handlers.
    • Use GraphQL to expose flexible query endpoints where clients can specify their desired fields and operations.
    • Use REST for simpler, predefined resources or operations such as CRUD services [1][3].
  4. Documentation and Tools:

    • You can find step-by-step guides for implementing GraphQL over IRIS on open GitHub repositories or Open Exchange projects, some including Flask-based setups as entry points.
    • Review and configure permissions for these APIs on the IRIS instance for security [3][4][5].

For full implementation details, consider looking into available open-source GraphQL projects like iris-graphql-demo or using InterSystems GraphQL resources. Though REST and GraphQL serve distinct needs, setting up both in IRIS provides a comprehensive API system.

Sources: