Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .crystal-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.35.0
1 change: 1 addition & 0 deletions __logs.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"time":"Sep 4 22:57:21","hostName":"localhost","userName":"Alice","process":{"name":"crystal_graphql_server","pid":1},"message":"something occured that need to be logged"},{"time":"now","hostName":"docker host","userName":"Anon","process":{"name":"crystal spec","pid":42},"message":"in a bottle"}]
6 changes: 6 additions & 0 deletions benchmark/lib/libragphqlparserC.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ lib GraphQLParser
_pos : LibC::Int
end

# ameba:disable Style/TypeNames
alias X__OffT = LibC::Long
# ameba:enable Style/TypeNames
# ameba:disable Style/TypeNames
alias X_IoLockT = Void
# ameba:enable Style/TypeNames
# ameba:disable Style/TypeNames
alias X__Off64T = LibC::Long
# ameba:enable Style/TypeNames
fun parse_file_with_experimental_schema_support = graphql_parse_file_with_experimental_schema_support(file : File*, error : LibC::Char**) : GraphQlAstNode*
fun error_free = graphql_error_free(error : LibC::Char*)
end
26 changes: 13 additions & 13 deletions example/simple_blog_example.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
require "../src/graphql-crystal"
require "secure_random"
require "uuid"
require "benchmark"

module BlogExample
Expand Down Expand Up @@ -55,21 +55,21 @@ module BlogExample
# and create some fixtures to work with
#
USERS = [
{id: SecureRandom.uuid, first_name: "Bob", last_name: "Bobson", role: UserRole::Author},
{id: SecureRandom.uuid, first_name: "Alice", last_name: "Alicen", role: UserRole::Admin},
{id: SecureRandom.uuid, first_name: "Grace", last_name: "Graham", role: UserRole::Reader},
{id: UUID.random.to_s, first_name: "Bob", last_name: "Bobson", role: UserRole::Author},
{id: UUID.random.to_s, first_name: "Alice", last_name: "Alicen", role: UserRole::Admin},
{id: UUID.random.to_s, first_name: "Grace", last_name: "Graham", role: UserRole::Reader},
].map { |args| User.new **args }

POSTS = [
{id: SecureRandom.uuid, author: USERS[0], title: "GraphQL for Dummies", body: "GraphQL is pretty simple."},
{id: SecureRandom.uuid, author: USERS[0], title: "REST vs. GraphQL", body: "GraphQL has certain advantages over REST."},
{id: SecureRandom.uuid, author: USERS[1], title: "The Crystal Programming Language ", body: "The nicest syntax on the planet now comes with typesafety, performance and parallelisation support(ójala!)"},
{id: UUID.random.to_s, author: USERS[0], title: "GraphQL for Dummies", body: "GraphQL is pretty simple."},
{id: UUID.random.to_s, author: USERS[0], title: "REST vs. GraphQL", body: "GraphQL has certain advantages over REST."},
{id: UUID.random.to_s, author: USERS[1], title: "The Crystal Programming Language ", body: "The nicest syntax on the planet now comes with typesafety, performance and parallelisation support(ójala!)"},
].map { |args| Post.new **args }

COMMENTS = [
{id: SecureRandom.uuid, author: USERS[2], post: POSTS[1], body: "I like rest more!"},
{id: SecureRandom.uuid, author: USERS[2], post: POSTS[1], body: "But think of all the possibilities with GraphQL!"},
{id: SecureRandom.uuid, author: USERS[1], post: POSTS[2], body: "When will I finally have static compilation support?"},
{id: UUID.random.to_s, author: USERS[2], post: POSTS[1], body: "I like rest more!"},
{id: UUID.random.to_s, author: USERS[2], post: POSTS[1], body: "But think of all the possibilities with GraphQL!"},
{id: UUID.random.to_s, author: USERS[1], post: POSTS[2], body: "When will I finally have static compilation support?"},
].map { |args| Comment.new **args }

#
Expand Down Expand Up @@ -228,7 +228,7 @@ module BlogExample
field :lastName { last_name }
field :fullName { "#{@first_name} #{@last_name}" }
field :posts { POSTS.select &.author.==(self) }
field :postsCount { POSTS.select(&.author.==(self)).size }
field :postsCount { POSTS.count &.author.==(self) }
field :role
end

Expand Down Expand Up @@ -258,7 +258,7 @@ module BlogExample
raise "authorId doesn't exist!" unless author

post = Post.new(
id: SecureRandom.uuid, author: author,
id: UUID.random.to_s, author: author,
title: payload["title"].as(String), body: payload["body"].as(String)
)

Expand All @@ -276,7 +276,7 @@ module BlogExample
raise "postId doesn't exist!" unless post

comment = Comment.new(
id: SecureRandom.uuid, author: author,
id: UUID.random.to_s, author: author,
post: post, body: payload["body"].as(String)
)
COMMENTS << comment
Expand Down
108 changes: 54 additions & 54 deletions example/simple_example.cr
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,20 @@ schema.mutation_resolver = MutationType
describe "my graphql schema" do
it "does queries" do
schema.execute("{ users { name posts } }")
.should eq ({
"data" => {
"users" => [
{
"name" => "Alice",
"posts" => [] of String,
},
{
"name" => "Bob",
"posts" => [] of String,
},
],
},
})
.should eq ({
"data" => {
"users" => [
{
"name" => "Alice",
"posts" => [] of String,
},
{
"name" => "Bob",
"posts" => [] of String,
},
],
},
})
end

it "does mutations" do
Expand All @@ -180,22 +180,22 @@ describe "my graphql schema" do
}

schema.execute(mutation_string, payload)
.should eq ({
"data" => {
"post" => {
"title" => "the long and windy road",
"body" => "that leads to your door",
"author" => {
"name" => "Alice",
"posts" => [
{
"title" => "the long and windy road",
},
],
.should eq ({
"data" => {
"post" => {
"title" => "the long and windy road",
"body" => "that leads to your door",
"author" => {
"name" => "Alice",
"posts" => [
{
"title" => "the long and windy road",
},
],
},
},
},
},
})
})
end

it "does introspection" do
Expand All @@ -210,32 +210,32 @@ describe "my graphql schema" do
}

schema.execute(query_string)
.should eq ({
"data" => {
"__schema" => {
"types" => [
{"name" => "String"},
{"name" => "Boolean"},
{"name" => "Int"},
{"name" => "Float"},
{"name" => "ID"},
{"name" => "QueryType"},
{"name" => "MutationType"},
{"name" => "PostInput"},
{"name" => "UserType"},
{"name" => "PostType"},
{"name" => "__Schema"},
{"name" => "__Type"},
{"name" => "__Field"},
{"name" => "__InputValue"},
{"name" => "__EnumValue"},
{"name" => "__Directive"},
{"name" => "__TypeKind"},
{"name" => "__DirectiveLocation"},
],
.should eq ({
"data" => {
"__schema" => {
"types" => [
{"name" => "String"},
{"name" => "Boolean"},
{"name" => "Int"},
{"name" => "Float"},
{"name" => "ID"},
{"name" => "QueryType"},
{"name" => "MutationType"},
{"name" => "PostInput"},
{"name" => "UserType"},
{"name" => "PostType"},
{"name" => "__Schema"},
{"name" => "__Type"},
{"name" => "__Field"},
{"name" => "__InputValue"},
{"name" => "__EnumValue"},
{"name" => "__Directive"},
{"name" => "__TypeKind"},
{"name" => "__DirectiveLocation"},
],
},
},
},
}
)
}
)
end
end
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version: 0.1.6
authors:
- ziprandom - <ziprandom@gmail.com>

crystal: 0.33.0
crystal: 0.35.0

license: MIT
Loading