• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

graphql-elixir/graphql: GraphQL Elixir

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

graphql-elixir/graphql

开源软件地址(OpenSource Url):

https://github.com/graphql-elixir/graphql

开源编程语言(OpenSource Language):

Elixir 95.5%

开源软件介绍(OpenSource Introduction):

GraphQL Elixir

Build Status Public Slack Discussion

An Elixir implementation of Facebook's GraphQL.

This is the core GraphQL query parsing and execution engine whose goal is to be transport, server and datastore agnostic.

In order to setup an HTTP server (ie Phoenix) to handle GraphQL queries you will need plug_graphql. Examples for Phoenix can be found at hello_graphql_phoenix, so look here for a starting point for writing your own schemas.

Other ways of handling queries will be added in due course.

Installation

First, add GraphQL to your mix.exs dependencies:

defp deps do
  [{:graphql, "~> 0.3"}]
end

Add GraphQL to your mix.exs applications:

def application do
  # Add the application to your list of applications.
  # This will ensure that it will be included in a release.
  [applications: [:logger, :graphql]]
end

Then, update your dependencies:

$ mix deps.get

Usage

First setup your schema

defmodule TestSchema do
  def schema do
    %GraphQL.Schema{
      query: %GraphQL.Type.ObjectType{
        name: "RootQueryType",
        fields: %{
          greeting: %{
            type: %GraphQL.Type.String{},
            resolve: &TestSchema.greeting/3,
            description: "Greeting",
            args: %{
              name: %{type: %GraphQL.Type.String{}, description: "The name of who you'd like to greet."},
            }
          }
        }
      }
    }
  end

  def greeting(_, %{name: name}, _), do: "Hello, #{name}!"
  def greeting(_, _, _), do: "Hello, world!"
end

Execute a simple GraphQL query

iex> GraphQL.execute(TestSchema.schema, "{greeting}")
{:ok, %{data: %{"greeting" => "Hello, world!"}}}

Status

This is a work in progress, right now here's what is done:

  • Parser for GraphQL (including Type definitions)
  • AST matching the graphql-js types as closely as possible
  • Schema definition
  • Query execution
    • Scalar types
    • Arguments
    • Multiple forms of resolution
    • Complex types (List, Object, etc)
    • Fragments in queries
    • Extract variable values
  • Introspection
  • [WIP] Query validation
  • Directives

Resources

Implementation

Tokenisation is done with leex and parsing with yecc. Both very useful Erlang tools for parsing. Yecc in particular is used by Elixir itself.

Some resources on using leex and yecc:

The Execution logic follows the GraphQL JS Reference Implementation pretty closely, as does the module structure of the project. Not to mention the naming of files and concepts.

If you spot anything that isn't following Elixir conventions though, that's a mistake. Please let us know by opening an issue or a PR and we'll fix it.

Developers

Getting Started

Clone the repo and fetch its dependencies:

$ git clone https://github.com/graphql-elixir/graphql.git
$ cd graphql
$ mix deps.get
$ mix test

Atom Editor Support

Using the language-erlang package? .xrl and .yrl files not syntax highlighting?

Syntax highlighting in Atom for leex (.xrl) and yecc (yrl) can be added by modifying grammars/erlang.cson.

Just open the atom-language-erlang package code in Atom and make the change described here:

jonathanmarvens/atom-language-erlang#11

however if that PR has been merged then just grab the latest version of the plugin!

Contributing

We actively welcome pull requests, bug reports, feedback, issues, questions. Come and chat in the #erlang channel on Slack

If you're planning to implement anything major, please let us know before you get too far so we can make sure your PR will be as mergable as possible. Oh, and don't forget to write tests.

License

BSD.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap