Giter Club home page Giter Club logo

phoenix-hipster-stack's 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.

phoenix-hipster-stack's People

Contributors

note89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phoenix-hipster-stack's Issues

BadFunctionError on submission of new link

I cloned the project installed the dependencies as instructed. When I add a link through the 'Add New Resource' form there is a server error from the POST request on /graphql.

** (BadFunctionError) expected a function, got: {App.PublicSchema, :mutate_and_get_payload}

    lib/graphql/relay/mutation.ex:48: anonymous fn/4 in GraphQL.Relay.Mutation.new/1

    (graphql) lib/graphql/execution/executor.ex:168: GraphQL.Execution.Executor.resolve_field/4

    (graphql) lib/graphql/execution/executor.ex:127: anonymous fn/5 in GraphQL.Execution.Executor.execute_fields/4

    (stdlib) lists.erl:1262: :lists.foldl/3

    (graphql) lib/graphql/execution/executor.ex:86: GraphQL.Execution.Executor.execute_operation/3

    (graphql) lib/graphql.ex:25: GraphQL.execute/5

    (plug_graphql) lib/graphql/plug/endpoint.ex:85: GraphQL.Plug.Endpoint.execute/2

    (plug_graphql) lib/graphql/plug.ex:54: GraphQL.Plug.call/2

Any ideas on something i've got mixed up here? Can you reproduce this on a clean build?

setup error

amazing work !

follow the README.md:

Compiled lib/app/repo.ex
[info] Running App.Endpoint with Cowboy using http on port 4000
dev server running on localhost:4001
babel-relay-plugin-loader: using schema at [/Users/xieyiming/code/elixir_playground/phoenix-hipster-stack/lib/babel-relay/schema.json]
webpack built 6ccfc1800d5b58fddc6a in 4879ms
Hash: 6ccfc1800d5b58fddc6a
Version: webpack 1.12.14
Time: 4879ms
          Asset    Size  Chunks       Chunk Names
index.bundle.js  222 kB       0       main
chunk    {0} index.bundle.js (main) 77.8 kB [rendered]
    [0] multi main 40 bytes {0} [built] [1 error]
    [1] (webpack)-hot-middleware/~/html-entities/lib/html5-entities.js 49 kB {0} [built]
    [2] (webpack)-hot-middleware/client-overlay.js 1.73 kB {0} [built]
    [3] (webpack)-hot-middleware/client.js?path=http://localhost:4001/__webpack_hmr 4.18 kB {0} [built]
    [4] (webpack)-hot-middleware/~/ansi-html/index.js 4.02 kB {0} [built]
    [5] (webpack)-hot-middleware/~/html-entities/index.js 231 bytes {0} [built]
    [6] (webpack)-hot-middleware/~/html-entities/lib/html4-entities.js 6.57 kB {0} [built]
    [7] (webpack)-hot-middleware/~/html-entities/lib/xml-entities.js 2.98 kB {0} [built]
    [8] (webpack)-hot-middleware/~/querystring/decode.js 2.4 kB {0} [built]
    [9] (webpack)-hot-middleware/~/querystring/encode.js 2.09 kB {0} [built]
   [10] (webpack)-hot-middleware/~/querystring/index.js 127 bytes {0} [built]
   [11] (webpack)-hot-middleware/~/strip-ansi/index.js 161 bytes {0} [built]
   [12] (webpack)-hot-middleware/~/strip-ansi/~/ansi-regex/index.js 135 bytes {0} [built]
   [13] (webpack)-hot-middleware/process-update.js 3.88 kB {0} [built]
   [14] (webpack)/buildin/module.js 251 bytes {0} [built]

ERROR in ./web/static/js/app.js
Module build failed: TypeError: Path must be a string. Received { __esModule: true,
  Plugin: [Function: Plugin],
  transformFile: [Function: transformFile],
  transformFileSync: [Function: transformFileSync],
  File: [Function: File],
  options: 
   { filename: 
      { type: 'filename',
        description: 'filename to use when reading from stdin - this will be used in source-maps, errors etc',
        default: 'unknown',
        shorthand: 'f' },
     filenameRelative: { hidden: true, type: 'string' },
     inputSourceMap: { hidden: true },
     env: { hidden: true, default: {} },
     mode: { description: '', hidden: true },
     retainLines: 

Get 100 % test coverage with jest

Write tests for everything present in the app at this point.
Also, put the tests right next to the files instead of in a separate folder.

add new resource warning

thanks for the work!
a error msg shows in the console when i add a new resource

image

warning.js?8a56:44 Warning: writeRelayUpdatePayload(): Expected response payload to include the newly created edge `linkEdge` and its `node` field. Did you forget to update the `RANGE_ADD` mutation config?

Query example in Readme

The query example says the following but these are not the fields in the linkConnection (title, url, etc.)

query myQuery{
store{
authors {
id
name
}
}
}

I think the right query would be more like this, but it doesn't return anything. What am I missing?

query myQuery{
store{
id,
linkConnection(first:5) {
edges {
cursor,
node {
id,
title,
url,
createdAt
}
}
pageInfo {
hasNextPage
}
}
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.