Comments (4)
You can set a headers
property in the adapter which will be added to the request.
For example,
import Ember from 'ember';
import Adapter from 'ember-graphql-adapter';
const { computed, get, inject: { service }} = Ember;
export default Adapter.extend({
currentUser: service(),
endpoint: 'https://api.github.com/graphql',
httpMethod: 'POST',
headers: computed('currentUser.oauthToken', function() {
let headers = {};
const authToken = get(this, 'currentUser.oauthToken');
if (authToken) {
headers['Authorization'] = authToken;
}
return headers;
})
});
or more simply,
import Adapter from 'ember-graphql-adapter';
export default Adapter.extend({
endpoint: 'https://api.github.com/graphql',
httpMethod: 'POST',
headers: { 'Authorization': oauthToken }
});
from ember-graphql-adapter.
Awesome! That works except that it urlencodes the request body to the server (also I need to set Content-Type': "application/json; charset=utf-8"
in the headers to get it not not send as form data)
If I change line 260 of the request
function to JSON.stringify
the request it works. Like this:
let ajaxOpts = this.ajaxOptions(url, JSON.stringify({ query: compiledQuery }));
Also, AFAIK I need to replace the compile
function to specify my own query. Any better ideas are definitely appreciated ;)
from ember-graphql-adapter.
It's already sending it as JSON:
ember-graphql-adapter/addon/adapter.js
Line 340 in 6deca9a
from ember-graphql-adapter.
It was sending JSON, but it the data was urlencoded for some reason, not sure why. It might have something to do with jQuery.
My need was really simple so I just made my own adaptor to get my data, so I'll close for now. Thanks for the help!
from ember-graphql-adapter.
Related Issues (20)
- README Show graphql syntax used HOT 4
- Post request format for queries HOT 4
- Parser does not respect primaryKey attribute in serializer
- Compiler should use normalizeCase function from Serializer HOT 1
- Update to latset ember-cli-babel (support node 8) HOT 1
- Can't Identify Input type from server
- Request only fetches ID HOT 3
- Support for aliases?
- GET supports only query operation HOT 2
- An in-range update of ember-ajax is breaking the build 🚨 HOT 3
- Is it possible to push data into the store using pushPayload?
- Readme issue HOT 1
- Constructs incorrect query when gathering a collection that contains a single object. HOT 2
- Release new version with latest commit HOT 1
- Error Handling HOT 5
- Full object graph always requested? HOT 14
- Question regarding added alias for relationships HOT 1
- inline fragments support?
- Multiple hasMany relationships generate wrong (nested) query HOT 4
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 ember-graphql-adapter.