ember-graphql-adapter icon indicating copy to clipboard operation
ember-graphql-adapter copied to clipboard

README Show graphql syntax used

Open jrock2004 opened this issue 8 years ago • 4 comments

In your readme, it would be helpful to see the graphql sybtax that the adapters are trying to use. This will help out understand how to use for our needs.

Something like this

query
{
  Media(search: "Dragonball") {
    title {
      userPreferred
    },
    description
  }
} 

jrock2004 avatar Aug 14 '17 03:08 jrock2004

Hey @jrock2004 Sounds good. Do you mean incoming or outgoing? Or both?

willrax avatar Aug 14 '17 08:08 willrax

I am just confused how I would create my models and adapters to match the graphql syntax like above

jrock2004 avatar Aug 15 '17 00:08 jrock2004

Also, is this only supported for ruby? All your docs are in ruby code

jrock2004 avatar Aug 15 '17 00:08 jrock2004

I am just confused how I would create my models and adapters to match the graphql syntax like above.

You can set up your ember models as normal and just make sure that both your adapter and serializer are exporting the grapqhl versions. From there the addon will auto generate the correct graph query to send to the backend and parse the response to feed it in the ember-data.

Also, is this only supported for ruby? All your docs are in ruby code.

It should support any graphql backend.

Here's an example from our code base.

models/comment.js

import DS from 'ember-data';

const { attr, belongsTo } = DS;

export default DS.Model.extend({
  body: attr('string'),
  createdAt: attr('date'),
  important: attr('boolean', { defaultValue: false }),

  advisor: belongsTo('advisor', { async: true }),
  user: belongsTo('user', { async: true }),
});

adapters/application.js

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

export default Adapter.extend();

serializers/application.js

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

export default Serializer.extend();

and this is the query that goes out:

query
  comments { 
    comments(ids: ["1","2","3"]) {
      id
      body
      created_at
      important 
      advisor_id
      user_id
    }
  }

willrax avatar Aug 15 '17 08:08 willrax