Skip to content

Commit 1999f74

Browse files
committed
multiple operations
1 parent a937b2d commit 1999f74

File tree

3 files changed

+132
-5
lines changed

3 files changed

+132
-5
lines changed

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Roadmap
5656
- [ ] Extract variable values
5757
- [ ] Introspection
5858
- [ ] Directives
59+
- [ ] Depth of the query7
60+
- [ ] Middleware
5961

6062
## Contributing
6163
## Your pull requests are more than welcome!!!
@@ -195,6 +197,52 @@ else
195197
println(r.Data)
196198
end
197199
```
200+
```julia
201+
query = """
202+
query consulta{
203+
neomatrix{
204+
nombre
205+
linkedin
206+
}
207+
}
208+
209+
query hola{
210+
neomatrix{
211+
nombre
212+
}
213+
}
214+
"""
215+
r = Queryclient("https://neomatrix.herokuapp.com/graphql",query,operationName="hola")
216+
if (r.Info.status == 200) println(r.Data) end
217+
```
218+
result:
219+
```
220+
{"data":{"neomatrix":{"nombre":"Acevedo Maldonado Josue"}}}
221+
```
222+
```julia
223+
query = """
224+
query consulta{
225+
Movie(title: "Inception"){
226+
actors{
227+
name
228+
}
229+
}
230+
}
231+
query hola{
232+
Movie(title: "Inception"){
233+
actors{
234+
name
235+
}
236+
}
237+
}
238+
"""
239+
r = client.Query(query,operationName="consulta")
240+
if (r.Info.status == 200) println(r.Data) end
241+
```
242+
result:
243+
```
244+
{"data":{"Movie":{"actors":[{"name":"Leonardo DiCaprio"},{"name":"Ellen Page"},{"name":"Tom Hardy"},{"name":"Joseph Gordon-Levitt"},{"name":"Marion Cotillard"}]}}}
245+
```
198246
### Change serverUrl
199247
```julia
200248
client.serverUrl("https://api.graph.cool/simple/v1/movies")
@@ -241,6 +289,26 @@ result:
241289
```
242290
"https://api.graph.cool/simple/v1/movies?query=%7B%0A%20%20Movie%28title%3A%20%22Inception%22%29%7B%0A%20%20%20%20actors%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A"
243291
```
292+
```julia
293+
query = """
294+
query consulta{
295+
neomatrix{
296+
nombre
297+
}
298+
}
299+
query hola{
300+
neomatrix{
301+
nombre
302+
linkedin
303+
}
304+
}
305+
"""
306+
r = Queryclient("https://neomatrix.herokuapp.com/graphql",query,getlink=true,operationName="consulta")
307+
```
308+
result:
309+
```
310+
"https://neomatrix.herokuapp.com/graphql?query=query%20consulta%7B%0A%20%20neomatrix%7B%0A%20%20%20%20%20%20nombre%0A%20%20%20%7D%0A%7D%0Aquery%20hola%7B%0A%20%20neomatrix%7B%0A%20%20%20%20%20%20nombre%0A%20%20%20%20%20%20linkedin%0A%20%20%20%20%7D%0A%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&operationName=consulta"
311+
```
244312

245313
### validating query
246314
It is possible to validate the query locally before sending the request, only basic validations are carried out.

src/client.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ function Queryclient(data::String,check::Bool)
1919
end
2020
end
2121

22-
function Queryclient(url::String,data::String; vars::Dict=Dict(),auth::String="Bearer 0000", headers::Dict=Dict(),getlink::Bool=false,check::Bool=false)
22+
function Queryclient(url::String,data::String; vars::Dict=Dict(),auth::String="Bearer 0000", headers::Dict=Dict(),getlink::Bool=false,check::Bool=false,operationName::String="")
2323

2424
if (getlink == true)
2525
#------------
2626
link =url*"?query="*HTTP.escapeuri(data)
2727

28+
if length(operationName)>0
29+
link=link*"&operationName="*operationName
30+
end
31+
2832
if length(vars)>0
2933
link=link*"&variables="*HTTP.escapeuri(JSON.json(vars))
3034
end
3135
return link
3236
#------------
3337
else
3438

35-
myjson = Dict("query"=>data,"variables" => vars,"operationName" => Dict())
39+
myjson = Dict("query"=>data,"variables" => vars,"operationName" => operationName)
3640
my_headers = HTTP.mkheaders(["Accept" => "application/json","Content-Type" => "application/json" ,"Authorization" => auth])
3741
for (key, value) in headers
3842
HTTP.setheader(my_headers,key => value )
@@ -68,11 +72,11 @@ function GraphQLClient(url::String; auth::String="Bearer 0000", headers::Dict=Di
6872
my_auth= auth
6973
end
7074

71-
function Query(data::String; vars::Dict=Dict(),getlink::Bool=false,check::Bool=false)
75+
function Query(data::String; vars::Dict=Dict(),getlink::Bool=false,check::Bool=false,operationName::String="")
7276
if (check)
7377
return Queryclient(data,check)
7478
end
75-
return Queryclient(my_url,data,vars=vars,auth=my_auth,headers=my_headersextras,getlink=getlink)
79+
return Queryclient(my_url,data,vars=vars,auth=my_auth,headers=my_headersextras,getlink=getlink,operationName=operationName)
7680

7781
end
7882

test/cliente.jl

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,59 @@ query = """
8585
"""
8686

8787
r = Queryclient("https://neomatrix.herokuapp.com/graphql",query,getlink=true)
88-
@test r == "https://neomatrix.herokuapp.com/graphql?query=%7B%0A%20%20neomatrix%7B%0A%20%20%20%20nombre%0A%20%20%20%20linkedin%0A%20%20%7D%0A%7D%0A"
88+
@test r == "https://neomatrix.herokuapp.com/graphql?query=%7B%0A%20%20neomatrix%7B%0A%20%20%20%20nombre%0A%20%20%20%20linkedin%0A%20%20%7D%0A%7D%0A"
89+
90+
91+
query = """
92+
query consulta{
93+
neomatrix{
94+
nombre
95+
linkedin
96+
}
97+
}
98+
99+
query hola{
100+
neomatrix{
101+
nombre
102+
}
103+
}
104+
"""
105+
r = Queryclient("https://neomatrix.herokuapp.com/graphql",query,operationName="hola")
106+
@test r.Data == "{\"data\":{\"neomatrix\":{\"nombre\":\"Acevedo Maldonado Josue\"}}}"
107+
108+
query = """
109+
query consulta{
110+
Movie(title: "Inception"){
111+
actors{
112+
name
113+
}
114+
}
115+
}
116+
query hola{
117+
Movie(title: "Inception"){
118+
actors{
119+
name
120+
}
121+
}
122+
}
123+
"""
124+
r = client.Query(query,operationName="consulta")
125+
126+
@test r.Data == "{\"data\":{\"Movie\":{\"actors\":[{\"name\":\"Leonardo DiCaprio\"},{\"name\":\"Ellen Page\"},{\"name\":\"Tom Hardy\"},{\"name\":\"Joseph Gordon-Levitt\"},{\"name\":\"Marion Cotillard\"}]}}}"
127+
128+
query = """
129+
query consulta{
130+
neomatrix{
131+
nombre
132+
}
133+
}
134+
query hola{
135+
neomatrix{
136+
nombre
137+
linkedin
138+
}
139+
}
140+
"""
141+
r = Queryclient("https://neomatrix.herokuapp.com/graphql",query,getlink=true,operationName="consulta")
142+
143+
@test r == "https://neomatrix.herokuapp.com/graphql?query=query%20consulta%7B%0A%20%20neomatrix%7B%0A%20%20%20%20nombre%0A%20%20%7D%0A%7D%0Aquery%20hola%7B%0A%20%20neomatrix%7B%0A%20%20%20%20nombre%0A%20%20%20%20linkedin%0A%20%20%7D%0A%7D%0A&operationName=consulta"

0 commit comments

Comments
 (0)