• Stars
    star
    245
  • Rank 165,304 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GraphQL adapter for Ember Data

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

More Repositories

1

ember-calendar

An awesome Ember calendar, designed with composability and reusability in mind.
JavaScript
157
star
2

paint

CSS framework like Bootstrap but more modern and delivered through SCSS mixins
SCSS
44
star
3

walnut

Lightweight, simplistic dashboard to monitor web services, CI and applications
JavaScript
36
star
4

sneakers_handlers

Retries with exponential backoff for sneakers
Ruby
33
star
5

ember-scrollable

A simple Ember wrapper around Trackpad Scroll Emulator
JavaScript
24
star
6

doofenshmirtz

Make your legacy code self destruct in Rails
Ruby
10
star
7

ember-cli-paint

Ember-cli wrapper for paint
JavaScript
7
star
8

take-home-assessment

A take home assessment designed for Full-stack or Backend developers
5
star
9

ember-style-guide

A beautiful, hand-crafted guide for building ambitious Ember apps, with love.
5
star
10

crawl

Crawl pages within a domain, reporting any page that returns a bad response code
Ruby
5
star
11

buildpack-migrations

Runs migrations on a deployment
Shell
5
star
12

tech-assessments

4
star
13

as_UIAutomation_QA

QA Test Automation Project
Java
3
star
14

ember-cli-mirage-example

An example usage of ember-cli-mirage to test an application.
JavaScript
3
star
15

hiring-challenges

Our hiring challenges for potential new team members
Ruby
3
star
16

paint-app-switcher

AppSwitcher Component styles and assets
CSS
2
star
17

fraud-detection

1
star
18

select2-capybara

Capybara helpers for select2
Ruby
1
star
19

docker-logstash

A logstash in Docker
Shell
1
star
20

github-shipit

A Chrome extension to make it easier to approve Github pull requests.
JavaScript
1
star
21

filbert

A utility to download backups of heroku followers
Ruby
1
star
22

tap

Homebrew repository for alphasights dependencies
Ruby
1
star
23

ember-cli-alphasights

JavaScript
1
star
24

dataclipper

Moves dataclips from one source to another
Elixir
1
star
25

ember-histo-slider

An Ember addon for a histo-slider component
JavaScript
1
star
26

paint-rails

Rails integration for Paint gem
Ruby
1
star
27

netprospex

NetProspex Ruby API wrapper
Ruby
1
star
28

sneakers_toolbox

Various helpers and convenience classes/modules/methods to help simplify working with Sneakers and get around common issues
Ruby
1
star
29

lean_stamper

A stripped down version of original userstamp plugin. References the stamper object itself, not the id. Only creator and updater.
Ruby
1
star