Skip to content

Instantly share code, notes, and snippets.

View bruce's full-sized avatar
🤝
Here to help!

Bruce Williams bruce

🤝
Here to help!
View GitHub Profile
@bruce
bruce / types.ex
Created April 27, 2017 15:36
Node interface type guessing
defmodule MyApp.Web.Schema.Types do
use Absinthe.Schema.Notation
use Absinthe.Relay.Schema.Notation
node interface do
resolve_type fn
# Guess type from struct name:
# Example: MyApp.Model.Foo -> :foo
%{__struct__: str}, _ ->
str
@bruce
bruce / info.graphql
Last active March 28, 2017 23:07
Silly FS GraphQL Executable
{
cwd {
basename
... on Directory {
entries {
basename
... on Directory {
basename
stat {
size
@bruce
bruce / query.graphql
Created March 27, 2017 21:37
Adding a count to an absinthe_relay Connection
{
items(first: 5) {
count
edges {
node {
name
}
}
}
}
@bruce
bruce / schema.ex
Created February 18, 2017 05:48
Simplistic viewer example
defmodule MyApp.Schema do
use Absinthe.Schema
object :user do
# Define your user type
end
query do
field :viewer, :user do
resolve &resolve_viewer/3
object :user do
field :id, :id
field :email, :string
field :password, :string # if you really want to make it available
field :enabled, :boolean
end
@bruce
bruce / color.ex
Created February 8, 2017 17:35
Extending an Absinthe schema using custom, app-specific macros
defmodule MyApp.Color do
@moduledoc """
Just an example source of the values
"""
def list do
~w(red green blue)a
end
@bruce
bruce / Login.js
Last active August 5, 2021 16:25
React + Redux + localStorage Login example
// components/Login/Login.js
class Login extends Component {
// ...
handleSubmit(evt) {
evt.preventDefault();
this.props.mutate(this.state)
.then(({ data }) => {
@bruce
bruce / schema.ex
Created January 10, 2017 17:15
Example resolver helper for pulling data from another source field
defmodule ExampleSchema do
use Absinthe.Schema
# rest of schema
object :message do
field :date, :datetime do
resolve source_field(:inserted_at)
end
end
@bruce
bruce / float_output.exs
Created January 9, 2017 08:49
Showing float serialization to non-string
defmodule TestSchema do
use Absinthe.Schema
query do
field :hello, :float do
resolve fn _, _, _ -> {:ok, 1.3} end
end
end
end
@bruce
bruce / schema.ex
Created January 9, 2017 05:45
Example creation/update
defmodule MyApp.Schema do
use Absinthe.Schema
mutation do
field :create_user, :user do
arg :input, :user_creation
resolve fn
_, %{input: input}, _ ->
# create from `input`, assign `user`
{:ok, user}