Comments (3)
OK, the files are published and the demo is up and running:
Enjoy!
from axios-actions.
I don't know enough about GQL to comment!
Have you tried the lib out yourself and have any ideas about how it could be done?
from axios-actions.
Whatdya know - it can!
You need to extend ApiGroup
then do a bit of overriding.
The code below runs on my machine - but I've exposed replaceTokens
in the source. If you want it to run for you, you'll need to copy that function locally and update the import, or cobble together your own replace tokens function.
import axios from 'axios'
import { ApiGroup, utils } from 'axios-actions'
class ApiGraphQL extends ApiGroup {
constructor (axios, actions) {
super(axios, actions)
}
add (action, config, callback) {
config = {
url: '/',
method: 'post',
headers: {
'content-type': 'application/json'
},
params: {
query: config
}
}
return super.add(action, config, callback)
}
request (config, data) {
data = {
query: utils.replaceTokens(config.params.query, data),
}
return super.request(config, data)
}
}
const client = axios.create({
baseURL: 'https://countries.trevorblades.com'
})
const actions = {
country: `query {
country(code: "{id}") {
name
native
emoji
currency
languages {
code
name
}
}
}`,
}
const endpoint = new ApiGraphQL(client, actions)
.endpoint
.country({ id: 'BR' })
.then(res => {
console.log(res.data)
})
I can update the demo and core code in the next couple of days.
Cheers,
Dave
from axios-actions.
Related Issues (17)
- circular reference? HOT 3
- Adding custom endpoints to every instance of ApiEndpoint HOT 3
- Allow placeholders which are not POSTed as data HOT 18
- simple configuration causes weird doubletting og req params HOT 3
- How do you send body data with post requests using ApiGroup? HOT 10
- HOWTO: have dynamic routes in ApiGroup HOT 1
- fix(VuexResource): add missing `error` to data
- custom Plugins blocked
- Cannot compile the widgets fie
- array.map requests causes error HOT 2
- Path template syntax should accept object-style placeholders HOT 1
- How do we specify additional headers in ApiGroup HOT 6
- GET payloads not being converted to query strings HOT 1
- Add support for HAL placeholders HOT 1
- Allow passing of additional headers in calls
- ApiGroup.add() breaks when adding a Request Config object HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axios-actions.