api changes related to server implementation
This commit is contained in:
parent
10a55a04e0
commit
d35ea043dc
|
@ -9,15 +9,17 @@
|
|||
|
||||
import
|
||||
faststreams/inputs,
|
||||
graphql/[server, client, parser, api],
|
||||
graphql/[parser, api],
|
||||
graphql/builtin/json_respstream as jrs
|
||||
|
||||
export server, client, parser
|
||||
|
||||
export
|
||||
# faststreams inputs
|
||||
inputs,
|
||||
|
||||
# query_parser, schema_parser
|
||||
# and full_parser
|
||||
parser,
|
||||
|
||||
# ast helper types
|
||||
api.ast_helper,
|
||||
|
||||
|
|
|
@ -20,9 +20,6 @@ export
|
|||
validator, graphql, ast_helper, executor,
|
||||
response, results, types, names, errors, ast
|
||||
|
||||
type
|
||||
ParseResult* = Result[void, ErrorDesc]
|
||||
|
||||
const
|
||||
builtinSchema = staticRead("builtin" / "schema.ql")
|
||||
|
||||
|
@ -50,9 +47,10 @@ proc customScalar*(ctx: GraphqlRef, nameStr: string, scalarProc: ScalarProc) =
|
|||
parseLit: scalarProc
|
||||
)
|
||||
|
||||
proc customScalars*(ctx: GraphqlRef, procs: openArray[(string, ScalarProc)]) =
|
||||
proc customScalars*(ctx: GraphqlRef,
|
||||
procs: openArray[tuple[name: string, scalarProc: ScalarProc]]) =
|
||||
for c in procs:
|
||||
ctx.customScalar(c[0], c[1])
|
||||
ctx.customScalar(c.name, c.scalarProc)
|
||||
|
||||
proc addVar*(ctx: GraphqlRef, name: string, val: int) =
|
||||
let name = ctx.names.insert(name)
|
||||
|
@ -103,19 +101,19 @@ proc parseVar*(ctx: GraphqlRef, name: string,
|
|||
value: openArray[byte]): ParseResult =
|
||||
parseVariableImpl(name, value)
|
||||
|
||||
proc addResolvers*(ctx: GraphqlRef, ud: RootRef,
|
||||
typeName: Name, resolvers: openArray[(string, ResolverProc)]) =
|
||||
proc addResolvers*(ctx: GraphqlRef, ud: RootRef, typeName: Name,
|
||||
resolvers: openArray[tuple[name: string, resolver: ResolverProc]]) =
|
||||
var res = ctx.resolver.getOrDefault(typeName)
|
||||
if res.isNil:
|
||||
res = ResolverRef(ud: ud)
|
||||
ctx.resolver[typeName] = res
|
||||
|
||||
for v in resolvers:
|
||||
let field = ctx.names.insert(v[0])
|
||||
res.resolvers[field] = v[1]
|
||||
let field = ctx.names.insert(v.name)
|
||||
res.resolvers[field] = v.resolver
|
||||
|
||||
proc addResolvers*(ctx: GraphqlRef, ud: RootRef,
|
||||
typeName: string, resolvers: openArray[(string, ResolverProc)]) =
|
||||
proc addResolvers*(ctx: GraphqlRef, ud: RootRef, typeName: string,
|
||||
resolvers: openArray[tuple[name: string, resolver: ResolverProc]]) =
|
||||
let name = ctx.names.insert(typeName)
|
||||
ctx.addResolvers(ud, name, resolvers)
|
||||
|
||||
|
|
|
@ -151,16 +151,24 @@ proc executeQuery(ctx: GraphqlRef, exec: ExecRef, resp: RespStream) =
|
|||
serialize(res, resp)
|
||||
|
||||
proc executeMutation(ctx: GraphqlRef, exec: ExecRef, resp: RespStream) =
|
||||
discard
|
||||
res := executeSelectionSet(exec.fieldSet, exec.opType, exec.opType, nil)
|
||||
serialize(res, resp)
|
||||
|
||||
proc executeSubscription(ctx: GraphqlRef, exec: ExecRef, resp: RespStream) =
|
||||
discard
|
||||
|
||||
proc executeRequest*(ctx: GraphqlRef, resp: RespStream, opName = "") =
|
||||
proc executeRequestImpl(ctx: GraphqlRef, resp: RespStream, opName = "") =
|
||||
exec := getOperation(opName)
|
||||
case exec.opSym.sym.kind
|
||||
of skQuery: visit executeQuery(exec, resp)
|
||||
of skMutation: visit executeMutation(exec, resp)
|
||||
of skSubscription: visit executeSubscription(exec, resp)
|
||||
of skQuery: visit executeQuery(exec, resp)
|
||||
of skMutation: visit executeMutation(exec, resp)
|
||||
of skSubscription: visit executeSubscription(exec, resp)
|
||||
else:
|
||||
unreachable()
|
||||
|
||||
proc executeRequest*(ctx: GraphqlRef, resp: RespStream, opName = ""): ParseResult =
|
||||
ctx.executeRequestImpl(resp, opName)
|
||||
if ctx.errKind == ErrNone:
|
||||
ok()
|
||||
else:
|
||||
err(ctx.err)
|
||||
|
|
|
@ -75,6 +75,7 @@ type
|
|||
opSym* : Node
|
||||
fieldSet* : FieldSet
|
||||
|
||||
ParseResult* = Result[void, ErrorDesc]
|
||||
RespResult* = Result[Node, string]
|
||||
|
||||
ResolverProc* = proc(ud: RootRef, params: Args,
|
||||
|
|
Loading…
Reference in New Issue