@@ -9,13 +9,19 @@ Allows you to easily mount a GraphQL endpoint in Phoenix.
9
9
10
10
## Installation
11
11
12
- 1 . Make a new Phoenix app
12
+ 1 . Make a new Phoenix app, or add it to your existing app.
13
13
14
14
``` sh
15
15
mix phoenix.new hello_graphql --no-ecto
16
16
cd hello_graphql
17
17
```
18
18
19
+ Alternatively you could clone the [Phoenix GraphQL example project](https://github.com/joshprice/hello_graphql_phoenix) repo
20
+
21
+ ` ` ` sh
22
+ git clone https://github.com/joshprice/hello_graphql_phoenix
23
+ ` ` `
24
+
19
25
2. Add ` plug_graphql` to your list of dependencies in ` mix.exs` and install the package with ` mix deps.get` .
20
26
21
27
` ` ` elixir
@@ -26,10 +32,9 @@ Allows you to easily mount a GraphQL endpoint in Phoenix.
26
32
27
33
# # Usage
28
34
29
- 1. Define a Schema. Here ' s a simple one to try out :
35
+ 1. Define a simple schema in ` web/graphql/test_schema.ex ` :
30
36
31
37
` ` ` elixir
32
- # The GraphQL schema we' re going to use
33
38
defmodule TestSchema do
34
39
def schema do
35
40
%GraphQL.Schema{
@@ -50,22 +55,21 @@ Allows you to easily mount a GraphQL endpoint in Phoenix.
50
55
end
51
56
` ` `
52
57
53
- 2. Add the plug to your ` api` pipeline:
58
+ 2. Your ` api` pipeline should have this as a minimum :
54
59
55
60
` ` ` elixir
56
61
pipeline :api do
57
62
plug :accepts, [" json" ]
58
-
59
- plug GraphQL.Plug.Endpoint, schema: TestSchema.schema
60
63
end
61
64
` ` `
62
65
63
- 3. Add an endpoint so this route fires
66
+ 3. Mount the GraphQL endpoint as follows:
64
67
65
68
` ` ` elixir
66
- scope " /api" , HelloGraphql do
69
+ scope " /api" do
67
70
pipe_through :api
68
- get " /" , PageController, :index
71
+
72
+ forward " /" , GraphQL.Plug.Endpoint, schema: {TestSchema, :schema}
69
73
end
70
74
` ` `
71
75
@@ -91,3 +95,12 @@ This is pretty early days, the graphql execution engine needs a lot more work to
91
95
92
96
However we can' t get there without your help, so any questions, bug reports, feedback,
93
97
feature requests and/or PRs are most welcome!
98
+
99
+ ## Acknowledgements
100
+
101
+ Thanks and appreciation goes to the following contributors for answering many questions and providing helpful feedback:
102
+
103
+ * Daniel Neighman (https://github.com/hassox)
104
+ * Chris McCord (https://github.com/chrismccord)
105
+
106
+ Thanks also to everyone who has submitted PRs, logged issues, given feedback or asked questions.
0 commit comments