How to access GraphQL
# umh-support
n
I enabled GraphQL in the instance YAML configuration file. Since the instance is a container, do i need to do any mapping from container to host? I can't access it yet via localhost:8090/graphql.
r
Hey Nils! Thank you for reaching out! This is going to be a bit of a longer reply, so I'll create separate messages per topic. 1: Reaching the gql api: The
8090
port needs to be published. Judging by your question, it sounds like you have a
docker-compose.yml
file that you run with
docker compose up
. If that's the case, you can open the port by adding it to the yaml file:
Copy code
yaml
services:
  umh:
    # image / env / restart / etc
    ports:
      - "8090:8090"
I noticed that our [documentation](https://docs.umh.app/reference/http-api/topic-browser-graphql#configuration) doesn't state that, so I took a note to add it. Edit: If you're running your container + config in a single
docker run
command instead of a
docker-compose
file, you can expose the
8090
port as such:
Copy code
bash
$ docker run -d \
  -- name umh-core
  # etc
  -p 8090:8090 \ # this opens port 8090
  # etc
You can try curling using this:
Copy code
bash
curl -s -X POST http://localhost:8090/graphql \
  -H 'Content-Type: application/json' \
  -d '{"query":"{ topics(limit: 3) { topic } }"}'
2: GraphQL API may not work on the latest umh-core releases While looking into your request, I noticed that
v0.37.0
is potentially the only version of umh-core that properly supports the gql API. In my case, I was getting
null
from the API when using versions later than
v.0.37.0
. Important to note: This was an experimental feature, and it hasn't been on our roadmap since the initial MVP release. Edit: I set up a
0.37.0
instance, which was a bit troublesome in it self (e.g. incompatible with new implementation of our data models), but: I was able to confirm that the gql API works on that version. Example call from outside of container:
Copy code
bash
docker exec YOUR_CONTAINER_NAME curl -s http://localhost:8090/graphql -H 'Content-Type: application/json' -d '{"query":"{ topics(limit: 1000) { topic metadata { key value } lastEvent { producedAt headers { key value } ... on TimeSeriesEvent { sourceTs scalarType numericValue stringValue booleanValue } ... on RelationalEvent { json } } } }"}'
You can omit the
docker exec
bit and curl if you're already inside the container.
3: Check potential alternatives & my next steps Depending on what you're trying to achieve, there may be other ways to reach your goal. - Can you tell me a bit more about your use case? 🙂 BTW: I'll take these findings about the gql API, and check if it's worth documenting this feature in the first place, if it doesn't really work.
4 Views