Last active
March 14, 2017 09:59
-
-
Save Humoud/e4dc84a67f5fa42485548a9069df03e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create user type | |
UserType = GraphQL::ObjectType.define do | |
name 'User' | |
description 'Our user model/type for GraphQL' | |
# specify what fields this type has | |
field :id, !types.ID | |
field :email, !types.String | |
field :username, !types.String | |
end | |
# Specify what queries our graphQL end point has | |
QueryType = GraphQL::ObjectType.define do | |
name 'Query' | |
description 'The root of all queries' | |
# query 1 | |
# take an ID and return a user | |
field :user do | |
type UserType | |
argument :id, !types.ID | |
description 'The user with a given ID' | |
resolve -> (obj, args, ctx) { User.find(args[:id]) } | |
end | |
# query 2 | |
# return all users | |
field :allUsers do | |
type types[UserType] | |
description 'All users in the DB' | |
resolve -> (obj, args, ctx) { User.all } | |
end | |
end | |
# setup Schema | |
Schema = GraphQL::Schema.define do | |
query QueryType | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment