Skip to content

Commit 6827766

Browse files
committed
update client
1 parent a6a0540 commit 6827766

File tree

3 files changed

+19
-42
lines changed

3 files changed

+19
-42
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ query = """
4747
}
4848
"""
4949

50-
Query("https://neomatrix.herokuapp.com/graphql",query)
50+
r = Query("https://neomatrix.herokuapp.com/graphql",query)
51+
if (r.Info.status == 200) println(r.Data) end
5152

5253
```
5354
```julia
@@ -66,7 +67,8 @@ query(\$number_of_repos:Int!) {
6667
}
6768
"""
6869

69-
Query("https://api.github.com/graphql",query,vars= Dict("number_of_repos" => 3),auth="Bearer 7fe6d7e40cc191101b4708b078a5fcea35ee7280")
70+
r = Query("https://api.github.com/graphql",query,vars= Dict("number_of_repos" => 3),auth="Bearer 7fe6d7e40cc191101b4708b078a5fcea35ee7280")
71+
if (r.Info.status == 200) println(r.Data) end
7072

7173
```
7274

@@ -94,7 +96,8 @@ query = """
9496
}
9597
"""
9698

97-
client.Query(query)
99+
r = client.Query(query)
100+
if (r.Info.status == 200) println(r.Data) end
98101
```
99102
```julia
100103
query = """
@@ -107,7 +110,8 @@ query getMovie(\$title: String!) {
107110
}
108111
}
109112
"""
110-
client.Query(query,vars= Dict("title" => "Inception"))
113+
r = client.Query(query,vars= Dict("title" => "Inception"))
114+
if (r.Info.status == 200) println(r.Data) end
111115
```
112116
### Change server
113117
```julia

src/Diana.jl

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,6 @@ import Requests: post
55

66
export Query, GraphQLClient
77

8-
type Client
9-
Query::Function
10-
serverUrl::Function
11-
serverAuth::Function
12-
end
13-
14-
function Query(url::String,data::String; vars::Dict=Dict(),auth::String="Bearer 0000")
15-
r=post(url; json = Dict("query"=>data,"variables" => vars),headers = Dict("Accept" => "application/json","Content-Type" => "application/json" ,"Authorization" => auth))
16-
content=""
17-
r.status == 200 ? map(x -> (content*="$(Char(x))"), r.data): println(r)
18-
content
19-
end
20-
21-
function GraphQLClient(url::String,auth::String="Bearer 0000")
22-
23-
my_url::String= url
24-
my_auth::String= auth
25-
26-
function serverUrl(url::String)
27-
my_url = url
28-
end
29-
30-
function serverAuth(auth::String)
31-
my_auth= auth
32-
end
33-
34-
function Query(data::String;vars::Dict=Dict())
35-
r=post(my_url; json = Dict("query"=>data,"variables" => vars),headers = Dict("Accept" => "application/json","Content-Type" => "application/json" ,"Authorization" => my_auth))
36-
content=""
37-
r.status == 200 ? map(x -> (content*="$(Char(x))"), r.data): println(r)
38-
content
39-
end
40-
41-
return Client(Query,serverUrl,serverAuth)
42-
end
8+
include("client.jl")
439

4410
end # module

test/runtests.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ query = """
1111
}
1212
"""
1313

14+
r = Query("https://neomatrix.herokuapp.com/graphql",query)
15+
16+
@test r.Info.status == 200
17+
@test r.Data == "{\"data\":{\"neomatrix\":{\"nombre\":\"Acevedo Maldonado Josue\",\"linkedin\":\"https://www.linkedin.com/in/acevedo-maldonado-josue/\"}}}"
1418

15-
@test Query("https://neomatrix.herokuapp.com/graphql",query) == "{\"data\":{\"neomatrix\":{\"nombre\":\"Acevedo Maldonado Josue\",\"linkedin\":\"https://www.linkedin.com/in/acevedo-maldonado-josue/\"}}}"
1619

1720
client = GraphQLClient("https://api.graph.cool/simple/v1/movies","Bearer my-jwt-token")
1821

@@ -26,8 +29,10 @@ query getMovie(\$title: String!) {
2629
}
2730
}
2831
"""
32+
r = client.Query(query2,vars=Dict("title" => "Inception"))
2933

30-
@test client.Query(query2,vars=Dict("title" => "Inception")) == "{\"data\":{\"Movie\":{\"releaseDate\":\"2010-08-28T20:00:00.000Z\",\"actors\":[{\"name\":\"Leonardo DiCaprio\"},{\"name\":\"Ellen Page\"},{\"name\":\"Tom Hardy\"},{\"name\":\"Joseph Gordon-Levitt\"},{\"name\":\"Marion Cotillard\"}]}}}"
34+
@test r.Info.status == 200
35+
@test r.Data == "{\"data\":{\"Movie\":{\"releaseDate\":\"2010-08-28T20:00:00.000Z\",\"actors\":[{\"name\":\"Leonardo DiCaprio\"},{\"name\":\"Ellen Page\"},{\"name\":\"Tom Hardy\"},{\"name\":\"Joseph Gordon-Levitt\"},{\"name\":\"Marion Cotillard\"}]}}}"
3136

3237
query2 = """
3338
{
@@ -38,5 +43,7 @@ query2 = """
3843
}
3944
}
4045
"""
46+
r = client.Query(query2)
4147

42-
@test client.Query(query2) == "{\"data\":{\"Movie\":{\"actors\":[{\"name\":\"Leonardo DiCaprio\"},{\"name\":\"Ellen Page\"},{\"name\":\"Tom Hardy\"},{\"name\":\"Joseph Gordon-Levitt\"},{\"name\":\"Marion Cotillard\"}]}}}"
48+
@test r.Info.status == 200
49+
@test r.Data == "{\"data\":{\"Movie\":{\"actors\":[{\"name\":\"Leonardo DiCaprio\"},{\"name\":\"Ellen Page\"},{\"name\":\"Tom Hardy\"},{\"name\":\"Joseph Gordon-Levitt\"},{\"name\":\"Marion Cotillard\"}]}}}"

0 commit comments

Comments
 (0)