GraphQL - can it be used with the Web API?

I setup Hasura and created the databases, GraphQL works great and returns all data and user related data in <25ms

What I need to know is if I can use the WebAPI to get this data as I seem to have some missing information where obviously I can’t use GraphQL in place of JSON in a API query (at least it won’t work that way on Postman and I know Postman has GraphQL features, but as Thunkable has the WebAPI, I need to submit GraphQL as one would a normal API.

Anyone know how?


1 Like

Technically, you can.
You need to use POST. In the header assign application/json to the Content-Type. Your data query should go in the body.

Hi thanks, I was actually aware of that part, the issue I’m having is how to wrap the GraphQL in the standard JSON query?

okay update I found it, the GraphQL is:

query MyQuery {
  lb_users(where: {email: {_eq: ""}}) {

Which becomes:

    "query" : "MyQuery { users(where: {email: {_eq: \"\"}}) {email first_name last_name}}"

Basically it can’t be JSON it has to be text with a backslash for any quotes

What I’m struggling now with is the mutations (updates) I use the same process as above to create:

{"mutation" : "MyMutation {update_users(where: {email: {_eq: \"\"}}, _set: {password: 12345678}){returning {updated_at}affected_rows}}"

But I get:

    "errors": [
            "extensions": {
                "path": "$",
                "code": "parse-failed"
            "message": "the key 'query' was not present"

I’m just not sure where to add the key ‘query’.

I appreciate this is somewhat off topic for the Thunkable forums, but I think these kinds of self-host super-fast databases would be very useful for people if we could make sense of them enough to create tutorials on this forum.

So I have also found the answer for Mutations.

One would simply wrap the mutation in a query:

{"query" : "mutation {update_users(where: {email: {_eq: \"\"}}, _set: {password: 12345678}){returning {updated_at}affected_rows}}"
1 Like

I wish that APIs were more standardized. The tricky thing is that each one is so different from every other. There are definitely things you can learn and then apply to other APIs but it’s almost never the case – at least for me – that you get to a place where you feel like an expert on APIs.

Even with the tutorial I made (and I’m a teacher and specifically tried to make it as broadly applicable as possible), it probably would barely have even helped you with this.

That being said, this forum is a great place to grow our knowledge and hey, maybe you’ll contribute a tutorial on this specific issue and people will benefit from that info.