npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-graphql-adapter

v1.1.5

Published

An Ember CLI adapter for GraphQL

Downloads

82

Readme

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