Giter VIP home page Giter VIP logo

Comments (4)

nickrobinson avatar nickrobinson commented on May 18, 2024 1

A little late to the party here, but here is what works for me with Hasura:

ajaxOptions: function (data) {
    let opts = {
      'dataType': 'json',
      'data': data,
      'type': this.httpMethod,
      'context': this,
      'contentType': 'application/json'
    };

    let headers = get(this, 'headers');
    if (headers !== undefined) {
      opts.beforeSend = function (xhr) {
        Object.keys(headers).forEach(key => xhr.setRequestHeader(key, headers[key]));
      };
    }

    return opts;
  },

The key is passing along a content type to force ember-ajax to correctly encode the request body as json.

from ember-graphql-adapter.

willrax avatar willrax commented on May 18, 2024

Yep, in your adapter.js you can set the option for POST.

import { Adapter } from 'ember-graphql-adapter';

export default Adapter.extend({
  httpMethod: 'POST'
});

from ember-graphql-adapter.

jhliberty avatar jhliberty commented on May 18, 2024

This indeed causes it to make a post request however the body is then sent as a serialized string which is not within the spec.

Following the workaround @cheerfulstoic mentioned in this issue I was able to get it working.

#52 (comment)

from ember-graphql-adapter.

cwhittl avatar cwhittl commented on May 18, 2024

`import GraphQLAdapter from 'ember-graphql-adapter';

export default GraphQLAdapter.extend({
endpoint: 'https://fakerql.com/graphql',
httpMethod: 'POST',
dataType: 'json',
request: function (store, type, options) {
let compiledQuery = this.compile(store, type, options);
let url = this.endpoint;
let ajaxOpts = this.ajaxOptions({ query: compiledQuery });
ajaxOpts.contentType = 'application/json; charset=utf-8';
return this.ajax(url, ajaxOpts);
},
});`

I got this almost working, just thought it might 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.