All Projects → alphasights → Ember Graphql Adapter

alphasights / Ember Graphql Adapter

Licence: mit
GraphQL adapter for Ember Data

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ember Graphql Adapter

Ember Apollo Client
🚀 An ember-cli addon for Apollo Client and GraphQL
Stars: ✭ 257 (+5.33%)
Mutual labels:  graphql, ember, ember-addon
Ember Form For
Stars: ✭ 136 (-44.26%)
Mutual labels:  ember, ember-addon
Ember Impagination
An Ember Addon that puts the fun back in asynchronous, paginated datasets
Stars: ✭ 123 (-49.59%)
Mutual labels:  ember, ember-addon
Ember Lifeline
An Ember addon for managing the lifecyle of asynchronous behavior in your objects
Stars: ✭ 241 (-1.23%)
Mutual labels:  ember, ember-addon
Ember Cli Postcss
🔥 A Postcss integration for ember-cli
Stars: ✭ 97 (-60.25%)
Mutual labels:  ember, ember-addon
Ember Toggle
Checkbox based Toggle Switches for Ember
Stars: ✭ 111 (-54.51%)
Mutual labels:  ember, ember-addon
Ember Service Worker
A pluggable approach to Service Workers for Ember.js
Stars: ✭ 227 (-6.97%)
Mutual labels:  ember, ember-addon
Ember Drag Sort
A sortable list component with support for multiple and nested lists
Stars: ✭ 82 (-66.39%)
Mutual labels:  ember, ember-addon
Ember Cli Notifications
⚛ Atom inspired notification messages for ember-cli
Stars: ✭ 168 (-31.15%)
Mutual labels:  ember, ember-addon
Emberx Select
Select component for Ember based on the native html select element.
Stars: ✭ 202 (-17.21%)
Mutual labels:  ember, ember-addon
Ember Tooltips
Easy and extendible tooltips for Ember components - http://sir-dunxalot.github.io/ember-tooltips/
Stars: ✭ 205 (-15.98%)
Mutual labels:  ember, ember-addon
Ember Wordpress
The bridge between Ember.js and Wordpress
Stars: ✭ 94 (-61.48%)
Mutual labels:  ember, ember-addon
Ember Cli Stripe
Stripe checkout for Ember
Stars: ✭ 84 (-65.57%)
Mutual labels:  ember, ember-addon
Ember Content Placeholders
Composable components for rendering fake (progressive) content like facebook
Stars: ✭ 121 (-50.41%)
Mutual labels:  ember, ember-addon
Ember Steps
Declaratively create wizards, tabbed UIs, and more
Stars: ✭ 84 (-65.57%)
Mutual labels:  ember, ember-addon
Ember Table
opensource.addepar.com/ember-table/
Stars: ✭ 1,695 (+594.67%)
Mutual labels:  ember, ember-addon
Ember Cli Document Title
Adding document title behaviour to your ember app
Stars: ✭ 220 (-9.84%)
Mutual labels:  ember, ember-addon
Ember Cli Bundle Analyzer
Analyze the size and contents of your Ember app's bundles
Stars: ✭ 78 (-68.03%)
Mutual labels:  ember, ember-addon
Ember Cli Sentry
Error tracking via Sentry for Ember.js apps
Stars: ✭ 81 (-66.8%)
Mutual labels:  ember, ember-addon
Ember Cli Addon Docs
Easy, beautiful docs for your OSS Ember addons
Stars: ✭ 162 (-33.61%)
Mutual labels:  ember, ember-addon

Ember Data GraphQL Adapter

Npm Version Code Climate Circle CI Ember Observer Score Greenkeeper badge

A Ember CLI adapter for using GraphQL with Ember Data.

Installation

ember install ember-graphql-adapter

Usage

Create your adapter first

// app/adapters/post.js
import GraphQLAdapter from 'ember-graphql-adapter';

export default GraphQLAdapter.extend({
  endpoint: 'http://localhost:3000/graph'
});

Now define your serializer

// app/serializers/post.js
import { Serializer } from 'ember-graphql-adapter';

export default Serializer.extend({});

And you're done!

Features

  • Queries and mutations are automatically generated for you
  • Field aliases are supported
  • Belongs to relationships are fully supported
  • Has many relationships are fully supported
  • Async relationships and request coalescing is supported with coalesceFindRequests: true

Rails Example

By using the fantastic graphql gem, you can expose your relational database as a GraphQL endpoint.

We start by creating a new type

# app/models/graph/post_type.rb
module Graph
  PostType = GraphQL::ObjectType.define do
    name "Post"
    description "A post"

    field :id, types.ID
    field :name, types.String
  end
end

Then we create the query type

# app/models/graph/query_type.rb
module Graph
  QueryType = GraphQL::ObjectType.define do
    name "Query"
    description "The query root of this schema"

    field :post, PostType do
      argument :id, !types.ID, "The ID of the post"
      resolve -> (_object, arguments, _context) do
        Post.find(arguments[:id])
      end
    end
  end
end

After that, it's time for the mutation type

# app/models/graph/mutation_type.rb
module Graph
  MutationType = GraphQL::ObjectType.define do
    name "Mutation"
    description "Mutations"

    field :postCreate, PostType do
      argument :name, !types.String, "The post name"
      resolve -> (_object, arguments, _context) do
        Post.create(name: arguments[:name])
      end
    end
  end
end

Now, we can build the whole schema

# app/models/graph/schema.rb
module Graph
  Schema = GraphQL::Schema.define do
    query Graph::QueryType
    mutation Graph::MutationType
  end
end

In the controller we just delegate to the GraphQL schema

# app/controllers/graph_controller.rb
class GraphController < ApplicationController
  def execute
    render json: ::Graph::Schema.execute(
      params.fetch("query"),
      context: {} # you can pass the current_user here
    )
  end
end

Finally, we just expose the GraphQL endpoint in the route

# config/routes.rb
get 'graph', to: 'graph#execute'

And that's it!

Developing

Installation

  • git clone https://github.com/alphasights/ember-graphql-adapter.git
  • yarn install

Running

  • yarn start

Running Tests

  • yarn run ember test -- --server

Building

  • yarn build
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].