5
5
6
6
An Elixir implementation of Facebook's GraphQL.
7
7
8
+ This is the core GraphQL query parsing and execution engine whose goal is to be
9
+ transport, server and datastore agnostic.
10
+
11
+ In order to setup an HTTP server (ie Phoenix) to handle GraphQL queries you will need (plug_graphql)[ https://github.com/joshprice/plug_graphql ] .
12
+
13
+ Other ways of handling queries will be added in due course.
14
+
8
15
## Installation
9
16
10
17
First, add GraphQL to your ` mix.exs ` dependencies:
@@ -23,21 +30,35 @@ $ mix deps.get
23
30
24
31
## Usage
25
32
26
- Parse a simple GraphQL query
33
+ First setup your schema
34
+
35
+ ``` elixir
36
+ defmodule TestSchema do
37
+ def schema do
38
+ %GraphQL .Schema {
39
+ query: %GraphQL .ObjectType {
40
+ name: " RootQueryType" ,
41
+ fields: [
42
+ %GraphQL .FieldDefinition {
43
+ name: " greeting" ,
44
+ type: " String" ,
45
+ resolve: & greeting/ 1 ,
46
+ }
47
+ ]
48
+ }
49
+ }
50
+ end
51
+
52
+ def greeting (name: name), do: " Hello, #{ name } !"
53
+ def greeting (_ ), do: greeting (name: " world" )
54
+ end
55
+ ```
56
+
57
+ Execute a simple GraphQL query
27
58
28
59
``` elixir
29
- iex> GraphQL .parse " { hello }"
30
- {:ok , %{definitions: [
31
- %{kind: :OperationDefinition , loc: %{start: 0 },
32
- operation: :query ,
33
- selectionSet: %{kind: :SelectionSet , loc: %{start: 0 },
34
- selections: [
35
- %{kind: :Field , loc: %{start: 0 }, name: " hello" }
36
- ]
37
- }}
38
- ],
39
- kind: :Document , loc: %{start: 0 }
40
- }}
60
+ iex> GraphQL .execute (TestSchema .schema , " {greeting}" )
61
+ {:ok , %{greeting: " Hello, world!" }}
41
62
```
42
63
43
64
## Status
0 commit comments