Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 7b5b35d

Browse files
author
Josh Price
committed
Improve README
- Mention `plug_graphql` - More appropriate Usage instructions
1 parent 962527c commit 7b5b35d

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

README.md

+34-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
An Elixir implementation of Facebook's GraphQL.
77

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+
815
## Installation
916

1017
First, add GraphQL to your `mix.exs` dependencies:
@@ -23,21 +30,35 @@ $ mix deps.get
2330

2431
## Usage
2532

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
2758

2859
```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!"}}
4162
```
4263

4364
## Status

0 commit comments

Comments
 (0)