GraphQL
Even though Trux was originally designed with REST in mind, it will work just as well out of the box with GraphQL served over HTTP.
GET and POST only
Since GraphQL server only supports GET
and POST
requests, some of the Trux methods for interacting with remote data won't really work as intended.
For requesting model and collection data, you will still be able to use the fetch
method, simply pass your prepared query
as an argument.
For example:
user.fetch(encodeURI('?query=user(id: "1")');
For model mutations, you'll need to use the update
method with the method
option set to POST
like so
user.update({
data: {
"query": "...",
"operationName": "...",
"variables": { "myVariable": "someValue", ... }
},
method: 'POST'
});