Skip to content

Commit a937b2d

Browse files
committed
execute query-schema
1 parent 67df2d1 commit a937b2d

File tree

6 files changed

+98
-18
lines changed

6 files changed

+98
-18
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Roadmap
3434
+ graphql client
3535

3636
#### Version 0.1.0
37-
+ Update to julia 0.7
37+
+ Update to julia 1.0
3838
+ Creation of schemas / types
3939
+ Validator
4040
+ Schemas / Types
@@ -47,7 +47,7 @@ Roadmap
4747
- [x] Query validation
4848
- [x] Schemas / Types
4949
- [ ]Schemas validation
50-
- [WIP] Query execution
50+
- [x] Query execution
5151
- [x] Arguments
5252
- [ ] Scalar types
5353
- [ ] Multiple forms of resolution
@@ -416,11 +416,13 @@ schema {
416416
"""
417417

418418
resolvers=Dict(
419-
"Query_neomatrix" => (ctx)->(return Dict("nombre"=>"josue","edad"=>5) )
420-
,"Query_persona" => (ctx)->(return Dict("nombre"=>"Diana","edad"=>15))
421-
,"Persona_nombre" => (ctx)->(return ctx["nombre"])
422-
,"Persona_edad" => (ctx)->(return ctx["edad"])
423-
)
419+
"Query_neomatrix" => (obj,args,ctx,info)->(return Dict("nombre"=>"josue","edad"=>5) )
420+
,"Query_persona" => (obj,args,ctx,info)->begin
421+
return Dict("nombre"=>"Diana","edad"=>15)
422+
end
423+
,"Persona_nombre" => (obj,args,ctx,info)->(return ctx["nombre"])
424+
,"Persona_edad" => (obj,args,ctx,info)->(return ctx["edad"])
425+
)
424426

425427
my_schema = Schema(schema, resolvers)
426428

src/Schema.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ mutable struct schema
55
end
66

77
function Schema(_schema, resolvers)
8-
#my_schema = Parse(_schema)
9-
8+
my_schema = Parse(_schema)
9+
tnb = gettypes(my_schema)
1010
function execute(query::String)
1111
myquery = Parse(query)
1212
Validatequery(myquery)
13-
return JSON.json(ExecuteQuery(myquery, resolvers))
13+
return JSON.json(ExecuteQuery(myquery, resolvers, tnb))
1414
#=Validatequery(Parse(query))
1515
validatelosdos()
1616
operationName = GetOperation(document, operationName)

src/Validate.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include("Visitor.jl")
22
include("rules/consultas.jl")
3+
include("rules/schema.jl")
34

45
import Base.length
56
function length(x::Node)
@@ -14,6 +15,12 @@ function Base.iterate(l::Node, isdone::Any)
1415
return l
1516
end
1617

18+
function deepquery(documentAST)
19+
gd =getdeep()
20+
visitante(documentAST,gd)
21+
return gd.valordeep()
22+
end
23+
1724
function Validatequery(documentAST)
1825
queryRules=[NotExtensionOnOperation(),NotTypeOnOperation(),NotSchemaOnOperation(),FragmentSubscription(),FragmentNames(),OperationNames(),OperationAnonymous(),SubscriptionFields(),FragmentUnknowNotUsed(),FragmentCycles()]
1926

@@ -33,3 +40,10 @@ function Validatequery(documentAST)
3340
}"""
3441
end
3542
end
43+
44+
function gettypes(schema)
45+
gt=getfield_types()
46+
visitante(schema,gt)
47+
return gt.notbasic_types
48+
end
49+

src/execute.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ struct resol
22
exec_root
33
exec_foil
44
argstodict
5-
function resol(resolvers)
6-
n_campos=["query","persona","neomatrix"]
7-
tipos =["Query","Persona","Persona"]
5+
function resol(resolvers,tipos)
6+
n_campos= tipos[1]
7+
tipos = tipos[2]
88
ctx = Dict()
99
args = Dict()
1010
obj= ""
@@ -41,14 +41,14 @@ struct executor
4141
enter
4242
leave
4343
salida
44-
function executor(exec_resol)
44+
function executor(exec_resol,deep)
4545
nivel=1
4646
salida=Dict()
4747
salida["datos"]=Dict()
4848
ex= :($salida["datos"])
49-
expresiones = Array{Expr}(undef, 4)
49+
expresiones = Array{Expr}(undef, deep)
5050
expresiones[1]= ex
51-
nombres=Array{String}(undef, 4)
51+
nombres=Array{String}(undef, deep)
5252
nombres[1]="query"
5353
function enter(node)
5454
if (node.kind=="Field")
@@ -86,8 +86,9 @@ struct executor
8686
end
8787
end
8888

89-
function ExecuteQuery(query, myresolvers)
90-
exec= executor(resol(myresolvers))
89+
function ExecuteQuery(query, myresolvers, types_nb)
90+
r = deepquery(query)
91+
exec= executor(resol(myresolvers,types_nb),r)
9192
visitante(query,exec)
9293
return exec.salida
9394
end

src/rules/consultas.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,39 @@ struct GraphqlError <: Exception
33
msg
44
end
55

6+
7+
struct getdeep
8+
enter
9+
leave
10+
valordeep
11+
function getdeep()
12+
valor=1
13+
nivel=1
14+
function valordeep()
15+
return valor
16+
end
17+
function enter(node)
18+
if (node.kind=="Field")
19+
if (typeof(node.selectionSet)<:Node)
20+
nivel = nivel+1
21+
if(nivel>valor)
22+
valor = nivel
23+
end
24+
end
25+
end
26+
27+
end
28+
function leave(node)
29+
if (node.kind=="Field")
30+
if (typeof(node.selectionSet)<:Node)
31+
nivel = nivel-1
32+
end
33+
end
34+
end
35+
new(enter,leave,valordeep)
36+
end
37+
end
38+
639
struct NotExtensionOnOperation
740
enter
841
leave

src/rules/schema.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
struct getfield_types
2+
enter
3+
leave
4+
basic_types
5+
notbasic_types
6+
function getfield_types()
7+
scalars_types=["String", "Int", "Float", "Boolean"]
8+
basic_types=[[],[]]
9+
notbasic_types=[[],[]]
10+
function enter(node)
11+
if (node.kind == "FieldDefinition")
12+
type = node.tipe.name.value
13+
if(type in scalars_types)
14+
push!(basic_types[1],node.name.value)
15+
push!(basic_types[2],type)
16+
else
17+
push!(notbasic_types[1],node.name.value)
18+
push!(notbasic_types[2],type)
19+
end
20+
end
21+
if (node.kind == "OperationTypeDefinition")
22+
push!(notbasic_types[1],node.operation)
23+
push!(notbasic_types[2],node.tipe.name.value)
24+
end
25+
end
26+
function leave(node)
27+
end
28+
new(enter,leave,basic_types,notbasic_types)
29+
end
30+
end

0 commit comments

Comments
 (0)