graphql-mesh: why odata handler throws error when serving my local endpoint

764 views Asked by At

I am trying to follow the example in the GraphQL-Mesh and replace the endpoint with my own to see how it works. Default github example works however when I try to server the mesh for my example, it throws the following error:

$ "C:\Kiran\example\GraphQLMesh\node_modules\.bin\graphql-mesh" serve
Debugger listening on ws://127.0.0.1:64627/889629dc-8f00-446e-8927-5bdcd2791e10
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
(node:13408) ExperimentalWarning: The fs.promises API is experimental
error: Unable to serve mesh:  Cannot read property 'concat' of undefined {"stack":"TypeError: Cannot read property 'concat' of undefined\n    at schemas.forEach (C:\\Kiran\\example\\GraphQLMesh\\node_modules\\@graphql-mesh\\odata\\index.cjs.js:493:51)\n    at Array.forEach (<anonymous>)\n    at ODataHandler.getMeshSource (C:\\Kiran\\example\\GraphQLMesh\\node_modules\\@graphql-mesh\\odata\\index.cjs.js:471:67)\n    at process._tickCallback (internal/process/next_tick.js:68:7)"}
Waiting for the debugger to disconnect...
Done in 9.93s.
Waiting for the debugger to disconnect...

my .meshrc.yaml is very simple as shown below

sources:
  - name: Mytest
    handler:
      odata:
        baseUrl: http://localhost:6001/odata/v1/
        batch: multipart
        expandNavProps: true

serve:
  exampleQuery: northwind-example.graphql

and package.json also is just copy of what is in the github

{
  "name": "odata-example",
  "version": "0.7.30",
  "license": "MIT",
  "private": true,
  "scripts": {
    "start": "graphql-mesh serve"
  },
  "dependencies": {
    "@graphql-mesh/cli": "^0.12.1",
    "@graphql-mesh/odata": "0.7.1",
    "graphql": "^15.4.0"
  }
}

When I hit the odata endpoint (http://localhost:6001/odata/v1/) on Postman, I see the following response:

Header

Status Code: 200 OK
content-type: application/json; odata.metadata=minimal; odata.streaming=true; charset=utf-8
date: Sat, 05 Dec 2020 06:52:51 GMT
odata-version: 4.0
server: Kestrel
transfer-encoding: chunked

Response

{
  "@odata.context": "http://localhost:6001/odata/v1/$metadata",
  "value": [{
    "name": "Products",
    "kind": "EntitySet",
    "url": "Products"
  }, {
    "name": "Categories",
    "kind": "EntitySet",
    "url": "Categories"
  }, {
    "name": "Suppliers",
    "kind": "EntitySet",
    "url": "Suppliers"
  }]
}

My example query is also very simple as shown below:

query fetchCatagories {
  myCatagories {
    CategoryId
    CategoryName
      Description
    Products {
      ProductName
        OrderDetails {
            OrderId
        }
    }
    Catagories(queryOptions: { top: 1 }) {
      Description
    }
  }
}

What am I missing in my example to get the mesh working and generating the GraphQL endpoint?

Also do I really need an example.graphql for OData as any OData service will have /$metadata endpoint that exposes the schema?

Update 1

Also I cannot get this to work with public odata endpoint like https://services.odata.org/V3/OData/OData.svc/

only the default example endpoints work

https://graph.microsoft.com/${GRAPH_VERSION:v1.0}

https://services.odata.org/TripPinRESTierService/(S(qzsyox3345c15qeq305pblvw))/

What is going on here?

1

There are 1 answers

0
Kiran On

if you run in to this issue, its a bug in the odata module and PR fix is available here