GithubHelp home page GithubHelp logo

Comments (4)

delkopiso avatar delkopiso commented on May 22, 2024

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.

cheerfulstoic avatar cheerfulstoic commented on May 22, 2024

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.

delkopiso avatar delkopiso commented on May 22, 2024

It's already sending it as JSON:

'dataType': 'json',

from ember-graphql-adapter.

cheerfulstoic avatar cheerfulstoic commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.