Standard library · Web and services

graphql

A GraphQL server: schemas, resolvers, query execution and HTTP handling.

import graphql

GraphQL is a language for asking an API for data: the client asks for exactly the fields it needs and the server sends back just those. This package is a complete server side implementation of the specification. Write the schema as SDL text and pass it to ParseSchema, or build it with the Add... functions, register resolvers for the fields and run a query with ExecuteSource.

A resolver is a function that takes a slot number; it reads the arguments and the parent object with ArgStr, ParentField and their siblings, and answers with one of the Resolve... functions or with Fail. A field without a resolver takes the value of the same name from the parent object. For a web server, call HandleHttpSimple inside a net/http handler.

Types

GqlHttpRequest

struct GqlHttpRequest
A GraphQL request over HTTP.
NameTypeDescription
querystr = ""The query text.
operationNamestr = ""The operation name.
variablesvalue.ValueThe variables.
extensionsvalue.ValueThe extensions.
okbool = trueIt was read correctly.
errorstr = ""If not, the reason.
graphql-Http.salam
import graphql
import encoding.value
import net.http
import net.router

mut schema := graphql.NewSchema()

func me(slot: i64):
    ctx := graphql.Context(slot)
    mut name := "guest"
    if value.ObjectHas(ctx, "user"):
        name = value.AsString(value.ObjectGet(ctx, "user"))
    end
    graphql.ResolveStr(slot, name + " (" + graphql.ParentTypeName(slot) + "." + graphql.FieldName(slot) + ")")
end

func add(slot: i64):
    graphql.ResolveInt(slot, graphql.ArgInt(slot, "a") + graphql.ArgInt(slot, "b"))
end

func endpoint(ctx: i64):
    res := graphql.HandleHttpSimple(schema, http.Ctx_method(ctx), http.Ctx_header(ctx, "Content-Type"), http.Ctx_body(ctx), http.Ctx_raw_query(ctx))
    http.Ctx_status(ctx, res.status)
    http.Ctx_set_header(ctx, "Content-Type", res.contentType)
    http.Ctx_text(ctx, res.body)
end

func main:
    mut err := graphql.NewError(graphql.ERR_SYNTAX, "")
    graphql.ParseSchemaInto(schema, "type Query { me: String! add(a: Int!, b: Int!): Int! }", err)
    _ := graphql.SetResolver(schema, "Query", "me", me)
    _ := graphql.SetResolver(schema, "Query", "add", add)

    mut r := router.NewRouter()
    router.Post(r, "/graphql", endpoint)
    router.Get(r, "/graphql", endpoint)
    mut srv := http.NewServer(19640)
    http.Use(srv, r)
    _ := http.RunBackground(srv)

    mut vars := value.NewValueObject()
    value.ObjectSet(vars, "x", value.ValueInt(40))
    body := graphql.BuildRequestBody("query Sum($x: Int!) { add(a: $x, b: 2) }", "Sum", vars)
    println body
    mut headers := http.NewHeaders()
    headers.insert("Content-Type", "application/json")
    resp := http.PostWith("http://127.0.0.1:19640/graphql", body, headers)
    println http.Status(resp), http.Body(resp)
    mut cr := graphql.ParseResponse(http.Body(resp))
    println graphql.ResponseOk(cr), cr.hasData, value.AsInt(graphql.ResponseField(cr, "add"))
    graphql.FreeClientResponse(cr)

    qs := graphql.BuildRequestQueryString("{ me }", "", value.ValueNull())
    resp2 := http.Get("http://127.0.0.1:19640/graphql?" + qs)
    println http.Body(resp2)
    resp3 := http.PostWith("http://127.0.0.1:19640/graphql", graphql.BuildQueryBody("{ nope }"), headers)
    mut cr3 := graphql.ParseResponse(http.Body(resp3))
    println http.Status(resp3), graphql.ResponseOk(cr3), graphql.ResponseErrorMessage(cr3)
    graphql.FreeClientResponse(cr3)

    mut req := graphql.ParseHttpRequestJSON(`{"query":"{ me }"}`)
    mut context := value.NewValueObject()
    value.ObjectSet(context, "user", value.ValueString("Maryam"))
    mut res := graphql.HandleRequest(schema, req, value.ValueNull(), context)
    println graphql.ResultToJSON(res)
    graphql.FreeResult(res)
    graphql.FreeHttpRequest(req)
    bad := graphql.ParseHttpRequest("PUT", "application/json", "{}", "")
    println bad.ok, bad.error
    resp4 := graphql.HandleHttp(schema, "POST", "application/json", "not json", "", value.ValueNull(), value.ValueNull())
    println resp4.status
end
Output{"operationName": "Sum", "variables": {"x": 40}, "query": "query Sum($x: Int!) { add(a: $x, b: 2) }"} 200 {"data": {"add": 42}} true true 42 {"data": {"me": "guest (Query.me)"}} 400 false cannot query field "nope" on type "Query" (line 1, column 3) {"data": {"me": "Maryam (Query.me)"}} false only GET and POST are supported 400

GqlHttpResponse

struct GqlHttpResponse
An HTTP response.
NameTypeDescription
statusint = 200The status code.
contentTypestr = "application/json"The content type.
bodystr = ""The body.

The example for this item is shown with the ones above: graphql-Http.salam

GqlError

struct GqlError
One error.
NameTypeDescription
categoryintThe category.
messagestr = ""The message.
lineint = 0The line.
colint = 0The column.
hasLocationbool = falseIt has a location.
pathKeysVectorThe keys of the path in the response.
pathIndexVectorThe indexes of the path; -1 for a key.
codestr = ""An optional code in extensions.
graphql-Document.salam
import graphql
import encoding.value

func main:
    source := `query Books($limit: Int = 5) { books(limit: $limit, tags: ["a", "b"]) @include(if: true) { ...Info alias: title } }
fragment Info on Book { id year }`
    println graphql.ParseOk(source), graphql.ParseOk("{ a "), graphql.LexOk("{ a }")
    mut err := graphql.NewError(graphql.ERR_SYNTAX, "")
    mut doc := graphql.Parse(source, err)
    println doc.ops.len(), doc.frags.len()
    print graphql.Print(doc)
    i := graphql.FindOperation(doc, "Books")
    op := doc.ops.get(i)
    println op.name, graphql.OperationTypeName(op.optype), op.shorthand, op.varDefs.len(), op.line
    sel := graphql.SelectionAt(doc, op.selections.get(0))
    println sel.kind == graphql.SEL_FIELD, sel.name, graphql.ResponseKey(sel), sel.args.len(), sel.directives.len(), sel.selections.len(), sel.line, sel.col
    arg := sel.args.get(1)
    println arg.name, graphql.PrintValue(doc, arg.value), graphql.ValueAt(doc, arg.value).kind == graphql.VAL_LIST
    vdef := op.varDefs.get(0)
    println vdef.name, graphql.PrintTypeRef(doc, vdef.typeRef), graphql.TypeRefName(doc, vdef.typeRef)
    println graphql.TypeRefIsNonNull(doc, vdef.typeRef), graphql.TypeRefIsList(doc, vdef.typeRef), graphql.TypeRefAt(doc, vdef.typeRef).name
    frag := doc.frags.get(graphql.FindFragment(doc, "Info"))
    println frag.name, frag.typeCondition, frag.selections.len()
    println graphql.PrintStringValue("hello \"world\"")
    graphql.FreeDocument(doc)

    mut ok := false
    stream := graphql.Tokenize(`{ a(x: 1.5, y: "s") }`, ok)
    println ok, stream.toks.len()
    tok := stream.toks.get(5)
    println graphql.TokenKindName(tok.kind), tok.lexeme, tok.fval, tok.line, tok.col
    println graphql.IsStringToken(graphql.TOK_STRING), graphql.TokenKindName(graphql.TOK_LBRACE)

    _ := graphql.Parse("{ a(", err)
    println err.category == graphql.ERR_SYNTAX, err.line, err.col, err.hasLocation
    println graphql.ErrorString(err)

    mut e := graphql.NewError(graphql.ERR_EXECUTION, "failed")
    graphql.PathPushKey(e, "books")
    graphql.PathPushIndex(e, 2)
    graphql.PathPushKey(e, "title")
    println graphql.PathLen(e), graphql.PathString(e)
    mut errs := graphql.GqlErrorList {}
    graphql.AddError(errs, e)
    graphql.AddError(errs, graphql.NewErrorAt(graphql.ERR_VALIDATION, "bad", 3, 7))
    graphql.AddError(errs, graphql.SyntaxError("unclosed parenthesis", 1, 4))
    println graphql.HasErrors(errs), graphql.ErrorCount(errs), graphql.ErrorAt(errs, 1).line
    println value.ArrayLen(graphql.ErrorsToValue(errs)), value.IsObject(graphql.ErrorToValue(e))
    graphql.FreeError(err)
    graphql.FreeErrorList(errs)
    println graphql.ERR_REQUEST, graphql.SpecEdition

    mut s := graphql.ParseSchema("type Query { n(x: Int!): Int e: Color } enum Color { RED }", err)
    println graphql.ValidateSource(s, "{ n(x: \"a\") }").items.len() > 0
    mut doc2 := graphql.Parse("{ n(x: 1) e }", err)
    println graphql.ValidateOk(s, doc2), graphql.Validate(s, doc2).items.len()
    c := graphql.CoerceLeafResult(s, "Color", value.ValueString("RED"))
    println c.ok, value.AsString(c.value)
    c2 := graphql.CoerceLeafResult(s, "Int", value.ValueString("x"))
    println c2.ok, c2.message.len() > 0
    graphql.FreeDocument(doc2)
    graphql.FreeSchema(s)
end
Outputtrue false true 1 1 query Books($limit: Int = 5) { books(limit: $limit, tags: ["a", "b"]) @include(if: true) { ...Info alias: title } } fragment Info on Book { id year } Books query false 1 1 true books books 2 1 2 1 32 tags ["a", "b"] true limit Int Int false false Int Info Book 2 "hello \"world\"" true 12 Float 1.5 1.5 1 8 true { true 1 5 true unterminated argument list (line 1, column 5) 3 books[2].title true 3 3 3 true 3 October2021 true true 0 true RED false true

GqlErrorList

struct GqlErrorList
A list of errors.
NameTypeDescription
itemsVectorThe errors.

The example for this item is shown with the ones above: graphql-Document.salam

Vx

struct Vx
The internal state of validation.
NameTypeDescription
schSchemaThe schema.
docDocumentThe document.
errorsGqlErrorListThe errors.
usedFragmentsVectorThe fragments that were used.
usedVarsVectorThe variables that were used.

The example for this item is shown with the ones above: graphql-Document.salam

FieldGroup

struct FieldGroup
The group of selections for one response key.
NameTypeDescription
keystr = ""The key.
selsVectorThe selections.
graphql-Execute.salam
import graphql
import encoding.value

func book(id: str, title: str, year: i64): value.Value:
    mut b := value.NewValueObject()
    value.ObjectSet(b, "id", value.ValueString(id))
    value.ObjectSet(b, "title", value.ValueString(title))
    value.ObjectSet(b, "year", value.ValueInt(year))
    ret b
end

func hello(slot: i64):
    graphql.ResolveStr(slot, "Hello " + graphql.ArgStr(slot, "name"))
end

func books(slot: i64):
    mut list := value.NewValueArray()
    value.ArrayPush(list, book("1", "The Blind Owl", 1936))
    value.ArrayPush(list, book("2", "Savushun", 1969))
    graphql.Resolve(slot, list)
end

func one_book(slot: i64):
    if graphql.ArgInt(slot, "id") == 2:
        graphql.Resolve(slot, book("2", "Savushun", 1969))
    else:
        graphql.ResolveNull(slot)
    end
end

func age(slot: i64):
    year := value.AsInt(graphql.ParentField(slot, "year"))
    graphql.ResolveInt(slot, 2026 - year)
end

func score(slot: i64):
    graphql.ResolveFloat(slot, graphql.ArgFloat(slot, "base") * 2.0)
end

func in_stock(slot: i64):
    graphql.ResolveBool(slot, graphql.ArgBool(slot, "only") or graphql.HasArg(slot, "x"))
end

func broken(slot: i64):
    graphql.Fail(slot, "service unavailable")
end

func main:
    mut err := graphql.NewError(graphql.ERR_SYNTAX, "")
    mut s := graphql.ParseSchema(`
type Query {
  hello(name: String = "world"): String!
  books: [Book!]!
  book(id: Int!): Book
  score(base: Float!): Float!
  inStock(only: Boolean!): Boolean!
  broken: String
}
type Book {
  id: ID!
  title: String!
  year: Int!
  age: Int!
}`, err)
    _ := graphql.SetResolver(s, "Query", "hello", hello)
    _ := graphql.SetResolver(s, "Query", "books", books)
    _ := graphql.SetResolver(s, "Query", "book", one_book)
    _ := graphql.SetResolver(s, "Query", "score", score)
    _ := graphql.SetResolver(s, "Query", "inStock", in_stock)
    _ := graphql.SetResolver(s, "Query", "broken", broken)
    _ := graphql.SetResolver(s, "Book", "age", age)
    println graphql.HasResolver(s, "Book", "age"), graphql.HasResolver(s, "Book", "title")

    mut r := graphql.Run(s, `{ hello books { title year age } }`)
    println graphql.ResultOk(r)
    println graphql.ResultToJSONStable(r)
    graphql.FreeResult(r)

    mut vars := value.NewValueObject()
    value.ObjectSet(vars, "id", value.ValueInt(2))
    mut r2 := graphql.ExecuteSource(s, `query One($id: Int!) { book(id: $id) { title } missing: book(id: 9) { title } score(base: 1.5) inStock(only: true) hello(name: "Maryam") }`, "One", vars, value.ValueNull(), value.ValueNull())
    println graphql.ResultToJSONStable(r2)
    graphql.FreeResult(r2)

    mut r3 := graphql.Run(s, `{ broken hello }`)
    println graphql.ResultOk(r3), graphql.ResultErrorMessage(r3)
    println graphql.ResultToJSONStable(r3)
    graphql.FreeResult(r3)

    mut r4 := graphql.Run(s, `{ nope }`)
    println graphql.ResultErrorMessage(r4)
    graphql.FreeResult(r4)
    graphql.ResetSlots()
    graphql.FreeSchema(s)
end
Outputtrue false true {"data": {"books": [{"age": 90, "title": "The Blind Owl", "year": 1936}, {"age": 57, "title": "Savushun", "year": 1969}], "hello": "Hello world"}} {"data": {"book": {"title": "Savushun"}, "hello": "Hello Maryam", "inStock": true, "missing": null, "score": 3}} false service unavailable (line 1, column 3) at broken {"data": {"broken": null, "hello": "Hello world"}, "errors": [{"locations": [{"column": 3, "line": 1}], "message": "service unavailable", "path": ["broken"]}]} cannot query field "nope" on type "Query" (line 1, column 3)

FieldGroups

struct FieldGroups
The groups.
NameTypeDescription
itemsVectorThe groups.
graphql-Internals.salam
import graphql
import encoding.value
import encoding.json

func names(slot: i64):
    graphql.ResolveStr(slot, json.EncodeDefault(graphql.Args(slot)))
end

func main:
    mut ok := false
    stream := graphql.Tokenize(`query Q($v: [Int!]! = [1]) @x { ...F a: b(c: 2.5, d: """text""") | & ? }`, ok)
    mut kinds := ""
    each t in stream.toks:
        if kinds.len() > 0:
            kinds += " "
        end
        kinds += graphql.TokenKindName(t.kind)
    end
    println ok, kinds
    println graphql.TOK_EOF, graphql.TOK_NAME, graphql.TOK_INT, graphql.TOK_FLOAT, graphql.TOK_BLOCK_STRING, graphql.TOK_BANG, graphql.TOK_DOLLAR
    println graphql.TOK_AMP, graphql.TOK_LPAREN, graphql.TOK_RPAREN, graphql.TOK_SPREAD, graphql.TOK_COLON, graphql.TOK_EQUALS, graphql.TOK_AT
    println graphql.TOK_LBRACKET, graphql.TOK_RBRACKET, graphql.TOK_RBRACE, graphql.TOK_PIPE, graphql.TOK_ERROR

    mut err := graphql.NewError(graphql.ERR_SYNTAX, "")
    mut s := graphql.ParseSchema(`
type Query { names(a: Boolean, b: Float, o: In, v: Int): String! book: Book }
input In { x: Int! }
type Book { id: ID! title: String! }`, err)
    _ := graphql.SetResolver(s, "Query", "names", names)

    mut doc := graphql.Parse(`query ($v: Int, $l: [Int!]) { names(a: true, b: 1.5, o: { x: 3 }, v: $v) book { id ...F ... on Book { title } } }
fragment F on Book { title }`, err)
    op := doc.ops.get(0)
    println op.optype == graphql.OP_QUERY
    sel := graphql.SelectionAt(doc, op.selections.get(0))
    mut vars := value.NewValueObject()
    value.ObjectSet(vars, "v", value.ValueInt(42))
    each a in sel.args:
        v := graphql.ValueAt(doc, a.value)
        lit := graphql.LiteralToValue(s, doc, a.value, vars)
        println a.name, v.kind == graphql.VAL_BOOL, v.kind == graphql.VAL_FLOAT, v.kind == graphql.VAL_OBJECT, v.kind == graphql.VAL_VARIABLE, lit.ok, json.EncodeDefault(lit.value)
    end

    lref := op.varDefs.get(1).typeRef
    elem := graphql.TypeRefElement(doc, lref)
    println graphql.PrintTypeRef(doc, lref), graphql.PrintTypeRef(doc, elem), graphql.TypeRefAt(doc, elem).kind == graphql.TREF_NAMED
    mut list := value.NewValueArray()
    value.ArrayPush(list, value.ValueInt(1))
    value.ArrayPush(list, value.ValueString("two"))
    c := graphql.CoerceInput(s, doc, lref, list)
    println c.ok, c.message.len() > 0

    bk := graphql.SelectionAt(doc, op.selections.get(1))
    println graphql.SelectionAt(doc, bk.selections.get(1)).kind == graphql.SEL_FRAGMENT_SPREAD, graphql.SelectionAt(doc, bk.selections.get(2)).kind == graphql.SEL_INLINE_FRAGMENT
    mut groups := graphql.CollectFields(s, doc, bk.selections, "Book", vars)
    each g in groups.items:
        println g.key, g.sels.len(), graphql.MergeSelections(doc, g).len()
    end
    graphql.FreeFieldGroups(groups)

    mut r := graphql.Execute(s, doc, "", vars, value.ValueNull(), value.ValueNull())
    mut ext := value.NewValueObject()
    value.ObjectSet(ext, "ms", value.ValueInt(3))
    graphql.SetExtensions(r, ext)
    println value.IsObject(graphql.ResultToValue(r))
    println graphql.ResultToJSONIndent(r)
    graphql.FreeResult(r)
    graphql.FreeDocument(doc)
    graphql.FreeSchema(s)
    graphql.FreeError(err)
end
Outputfalse Name Name ( $ Name : [ Name ! ] ! = [ Int ] ) @ Name { ... Name Name : Name ( Name : Float Name : BlockString ) | & <error> } <EOF> 0 1 2 3 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 true a true false false false true true b false true false false true 1.5 o false false true false true {"x": 3} v false false false true true 42 [Int!] Int! true false true true true id 1 0 title 2 0 true { "extensions": { "ms": 3 }, "data": { "book": null, "names": "{\"a\": true, \"b\": 1.5, \"v\": 42, \"o\": {\"x\": 3}}" } }

CoerceResult

struct CoerceResult
The result of converting one value.
NameTypeDescription
okbool = trueThe conversion worked.
messagestr = ""The error message.
valuevalue.ValueThe value.

The example for this item is shown with the ones above: graphql-Document.salam

AstValue

struct AstValue
A value in the document.
NameTypeDescription
kindintThe kind, one of the VAL_... constants.
bbool = falseThe boolean value.
ii64 = 0The integer value.
ff64 = 0The float value.
sstr = ""The string, the enum name or the variable name.
itemsVectorThe list elements or the object values.
keysVectorThe object keys.
lineint = 0The line.

The example for this item is shown with the ones above: graphql-Document.salam

AstTypeRef

struct AstTypeRef
A type reference.
NameTypeDescription
kindintNamed or list.
namestr = ""The type name.
innerint = -1The inner reference of a list.
nonNullbool = falseNon null, with a !.
graphql-Schema.salam
import graphql

func main:
    mut s := graphql.NewSchema()
    graphql.AddScalarType(s, "Date", "A date as YYYY-MM-DD")
    graphql.AddInterfaceType(s, "Node", "")
    _ := graphql.AddField(s, "Node", "id", "ID!")
    graphql.AddObjectType(s, "Author", "An author")
    graphql.AddInterfaceTo(s, "Author", "Node")
    _ := graphql.AddField(s, "Author", "id", "ID!")
    _ := graphql.AddField(s, "Author", "name", "String!")
    _ := graphql.AddField(s, "Author", "born", "Date")
    mut genres := Vector {} as Vector<str>
    genres.push("NOVEL")
    genres.push("POETRY")
    graphql.AddEnumType(s, "Genre", genres)
    mut members := Vector {} as Vector<str>
    members.push("Author")
    graphql.AddUnionType(s, "SearchResult", members)
    graphql.AddInputObjectType(s, "AuthorInput", "")
    _ := graphql.AddInputField(s, "AuthorInput", "name", "String!")
    graphql.AddObjectType(s, "Query", "")
    _ := graphql.AddField(s, "Query", "authors", "[Author!]!")
    _ := graphql.AddField(s, "Query", "search", "[SearchResult!]!")
    _ := graphql.AddFieldArg(s, "Query", "search", "text", "String!")
    _ := graphql.AddFieldArg(s, "Query", "search", "genre", "Genre")
    graphql.AddObjectType(s, "Mutation", "")
    _ := graphql.AddField(s, "Mutation", "addAuthor", "Author!")
    _ := graphql.AddFieldArg(s, "Mutation", "addAuthor", "input", "AuthorInput!")
    graphql.SetRootTypes(s, "Query", "Mutation", "")
    print graphql.PrintSchema(s)
    println "---"
    println graphql.PrintType(s, "Genre")

    println graphql.HasType(s, "Author"), graphql.TypeIndex(s, "Author") >= 0, graphql.TypeCount(s) > 5
    t := graphql.FindType(s, "Author")
    println t.name, t.kind == graphql.TYPE_OBJECT, t.description, graphql.HasField(t, "born")
    f := graphql.FindField(graphql.FindType(s, "Query"), "search")
    println f.name, graphql.FindArg(f, "genre").name, graphql.FindArg(f, "genre").hasDefault
    println graphql.FindInputField(graphql.FindType(s, "AuthorInput"), "name").name
    println graphql.HasEnumValue(graphql.FindType(s, "Genre"), "POETRY")
    println graphql.IsInputType(s, "AuthorInput"), graphql.IsOutputType(s, "AuthorInput"), graphql.IsLeafType(s, "Genre")
    println graphql.IsAbstractType(s, "SearchResult"), graphql.IsPossibleType(s, "Node", "Author"), graphql.PossibleTypes(s, "Node").len()
    println graphql.RootTypeName(s, graphql.OP_MUTATION), graphql.RootTypeName(s, graphql.OP_SUBSCRIPTION).len()
    println graphql.FindDirectiveDef(s, "deprecated").name
    println graphql.TypeAt(s, 0).name.len() > 0
    println graphql.IsIntrospectionType("__Schema"), graphql.IsIntrospectionType("Author")
    graphql.AddIntrospectionTypes(s)
    println graphql.HasType(s, "__Type"), graphql.PrintSchemaFull(s).len() > graphql.PrintSchema(s).len()
    println graphql.TypeRefText(s, "[Int!]") >= 0

    println graphql.ParseSchemaOk("type Query { a: Int }"), graphql.ParseSchemaOk("type {")
    mut err := graphql.NewError(graphql.ERR_SYNTAX, "")
    graphql.ParseSchemaInto(s, "extend type Author { alias: String }", err)
    println graphql.HasField(graphql.FindType(s, "Author"), "alias"), err.message.len()
    println graphql.TYPE_SCALAR, graphql.TYPE_INTERFACE, graphql.TYPE_UNION, graphql.TYPE_ENUM, graphql.TYPE_INPUT_OBJECT
    graphql.FreeSchema(s)
end
Output"A date as YYYY-MM-DD" scalar Date interface Node { id: ID! } "An author" type Author implements Node { id: ID! name: String! born: Date } enum Genre { NOVEL POETRY } union SearchResult = Author input AuthorInput { name: String! } type Query { authors: [Author!]! search(text: String!, genre: Genre): [SearchResult!]! } type Mutation { addAuthor(input: AuthorInput!): Author! } --- enum Genre { NOVEL POETRY } true true true Author true An author true search genre false name true true false true true true 1 Mutation 0 deprecated true true false true true true true false true 0 0 2 3 4 5

AstArgument

struct AstArgument
One argument.
NameTypeDescription
namestr = ""The name.
valueint = -1The number of the value.
lineint = 0The line.

The example for this item is shown with the ones above: graphql-Document.salam

AstDirective

struct AstDirective
One directive, such as @include.
NameTypeDescription
namestr = ""The name.
argsVectorThe arguments.
lineint = 0The line.

The example for this item is shown with the ones above: graphql-Document.salam

AstSelection

struct AstSelection
One selection: a field, a fragment spread or an inline fragment.
NameTypeDescription
kindintThe kind, one of the SEL_... constants.
namestr = ""The name of the field or fragment.
aliasstr = ""Another name for the field in the response.
typeConditionstr = ""The type of an inline fragment.
hasTypeConditionbool = falseIt has a type.
argsVectorThe arguments.
directivesVectorThe directives.
selectionsVectorThe sub selections.
lineint = 0The line.
colint = 0The column.

The example for this item is shown with the ones above: graphql-Document.salam

AstVariableDef

struct AstVariableDef
The definition of a variable.
NameTypeDescription
namestr = ""The name without the $.
typeRefint = -1The type reference.
defaultValueint = -1The number of the default value.
hasDefaultbool = falseIt has a default.
directivesVectorThe directives.
lineint = 0The line.

The example for this item is shown with the ones above: graphql-Document.salam

AstOperation

struct AstOperation
One operation.
NameTypeDescription
optypeintThe type, one of the OP_... constants.
namestr = ""The name; empty for a shorthand query.
varDefsVectorThe variable definitions.
directivesVectorThe directives.
selectionsVectorThe numbers of the root selections.
shorthandbool = falseIt was written in the short { ... } form.
lineint = 0The line.

The example for this item is shown with the ones above: graphql-Document.salam

AstFragment

struct AstFragment
One fragment.
NameTypeDescription
namestr = ""The name.
typeConditionstr = ""The type the fragment applies to.
directivesVectorThe directives.
selectionsVectorThe selections.
lineint = 0The line.

The example for this item is shown with the ones above: graphql-Document.salam

Document

struct Document
A parsed document: operations and fragments; selections, values and type references are kept by number in the lists of the document.
NameTypeDescription
opsVectorThe operations.
fragsVectorThe fragments.
selsVectorThe selections.
valsVectorThe values.
trefsVectorThe type references.

The example for this item is shown with the ones above: graphql-Document.salam

ResolverSlot

struct ResolverSlot
The state of one resolver call.
NameTypeDescription
busybool = falseIn use.
parentvalue.ValueThe parent.
argsvalue.ValueThe arguments.
ctxvalue.ValueThe context.
fieldNamestr = ""The field name.
parentTypestr = ""The parent type.
resultvalue.ValueThe result.
resolvedbool = falseThe result was set.
failedbool = falseIt failed.
messagestr = ""The error message.

The example for this item is shown with the ones above: graphql-Execute.salam

GqlSlotTable

struct GqlSlotTable
The table of slots.
NameTypeDescription
itemsVectorThe slots.

The example for this item is shown with the ones above: graphql-Execute.salam

Ex

struct Ex
The internal state of execution.
NameTypeDescription
schSchemaThe schema.
docDocumentThe document.
varsvalue.ValueThe variables.
ctxvalue.ValueThe context.
errorsGqlErrorListThe errors.
pathKeysVectorThe current path.
pathIdxVectorThe indexes of the path.
depthint = 0The depth.
maxDepthint = 512The greatest depth allowed.

The example for this item is shown with the ones above: graphql-Execute.salam

ClientResponse

struct ClientResponse
A response the client got from the server.
NameTypeDescription
datavalue.ValueThe data.
hasDatabool = falseIt has data.
errorsGqlErrorListThe errors.
extensionsvalue.ValueThe extensions.
hasExtensionsbool = falseIt has extensions.

The example for this item is shown with the ones above: graphql-Http.salam

GqlToken

struct GqlToken
One token.
NameTypeDescription
kindintThe kind, one of the TOK_... constants.
lexemestr = ""The text.
svalstr = ""The string value.
ivali64 = 0The integer value.
fvalf64 = 0The float value.
lineint = 0The line.
colint = 0The column.
posint = 0Where it starts in the text.

The example for this item is shown with the ones above: graphql-Document.salam

GqlTokenStream

struct GqlTokenStream
A list of tokens.
NameTypeDescription
toksVectorThe tokens.

The example for this item is shown with the ones above: graphql-Document.salam

ExecutionResult

struct ExecutionResult
The result of an execution.
NameTypeDescription
datavalue.ValueThe data.
hasDatabool = falseIt has data; not when the request never ran at all.
errorsGqlErrorListThe errors.
extensionsvalue.ValueThe extensions.
hasExtensionsbool = falseIt has extensions.

The example for this item is shown with the ones above: graphql-Execute.salam

InputValueDef

struct InputValueDef
The definition of an argument or input field.
NameTypeDescription
namestr = ""The name.
descriptionstr = ""The description.
typeRefint = -1The type reference.
defaultValueint = -1The default value in the document.
hasDefaultbool = falseIt has a default value.
is_deprecatedbool = falseIt is deprecated.
deprecationReasonstr = ""Why it was deprecated.

The example for this item is shown with the ones above: graphql-Schema.salam

FieldDef

struct FieldDef
The definition of one field.
NameTypeDescription
namestr = ""The name.
descriptionstr = ""The description.
typeRefint = -1The type reference.
argsVectorThe arguments.
is_deprecatedbool = falseIt is deprecated.
deprecationReasonstr = ""Why it was deprecated.
resolveri64 = 0The registered resolver.

The example for this item is shown with the ones above: graphql-Schema.salam

EnumValueDef

struct EnumValueDef
One enum value.
NameTypeDescription
namestr = ""The name.
descriptionstr = ""The description.
is_deprecatedbool = falseIt is deprecated.
deprecationReasonstr = ""Why it was deprecated.

The example for this item is shown with the ones above: graphql-Schema.salam

TypeDef

struct TypeDef
The definition of one type.
NameTypeDescription
kindintThe kind, one of the TYPE_... constants.
namestr = ""The name.
descriptionstr = ""The description.
fieldsVectorThe fields, for objects and interfaces.
inputFieldsVectorThe fields of an input type.
interfacesVectorThe interfaces it implements.
unionMembersVectorThe members of a union.
enumValuesVectorThe enum values.
specifiedByURLstr = ""The specification URL of a scalar type.

The example for this item is shown with the ones above: graphql-Schema.salam

DirectiveDef

struct DirectiveDef
The definition of a directive.
NameTypeDescription
namestr = ""The name.
descriptionstr = ""The description.
argsVectorThe arguments.
locationsVectorWhere it can be used.
repeatablebool = falseIt may appear more than once in the same place.

The example for this item is shown with the ones above: graphql-Schema.salam

Schema

struct Schema
A schema: every type, directive and root type.
NameTypeDescription
docDocumentThe internal document that holds the type references.
typesVectorThe types.
directivesVectorThe directives.
queryTypestr = "Query"The name of the query root type.
mutationTypestr = ""The name of the mutation root type.
subscriptionTypestr = ""The name of the subscription root type.
descriptionstr = ""The schema description.
hasSchemaDefbool = falseIt had an explicit schema { ... } block.

The example for this item is shown with the ones above: graphql-Schema.salam

Constants and variables

SpecEdition

const SpecEdition: str = "October2021"
The edition of the GraphQL specification that is implemented.

The example for this item is shown with the ones above: graphql-Document.salam

ERR_SYNTAX

const ERR_SYNTAX: i32 = 0
Error category: syntax.

The example for this item is shown with the ones above: graphql-Schema.salam

ERR_VALIDATION

const ERR_VALIDATION: i32 = 1
Error category: validation.

The example for this item is shown with the ones above: graphql-Document.salam

ERR_EXECUTION

const ERR_EXECUTION: i32 = 2
Error category: execution, a failed resolver for instance.

The example for this item is shown with the ones above: graphql-Document.salam

ERR_REQUEST

const ERR_REQUEST: i32 = 3
Error category: a bad HTTP request.

The example for this item is shown with the ones above: graphql-Document.salam

VAL_NULL

const VAL_NULL: i32 = 0
Value kind: null.

The example for this item is shown with the ones above: graphql-Execute.salam

VAL_BOOL

const VAL_BOOL: i32 = 1
Value kind: boolean.

The example for this item is shown with the ones above: graphql-Internals.salam

VAL_INT

const VAL_INT: i32 = 2
Value kind: integer.

The example for this item is shown with the ones above: graphql-Execute.salam

VAL_FLOAT

const VAL_FLOAT: i32 = 3
Value kind: float.

The example for this item is shown with the ones above: graphql-Internals.salam

VAL_STRING

const VAL_STRING: i32 = 4
Value kind: string.

The example for this item is shown with the ones above: graphql-Execute.salam

VAL_ENUM

const VAL_ENUM: i32 = 5
Value kind: enum.

The example for this item is shown with the ones above: graphql-Schema.salam

VAL_LIST

const VAL_LIST: i32 = 6
Value kind: list.

The example for this item is shown with the ones above: graphql-Document.salam

VAL_OBJECT

const VAL_OBJECT: i32 = 7
Value kind: object.

The example for this item is shown with the ones above: graphql-Internals.salam

VAL_VARIABLE

const VAL_VARIABLE: i32 = 8
Value kind: variable.

The example for this item is shown with the ones above: graphql-Internals.salam

TREF_NAMED

const TREF_NAMED: i32 = 0
Type reference: named.

The example for this item is shown with the ones above: graphql-Internals.salam

TREF_LIST

const TREF_LIST: i32 = 1
Type reference: list.

The example for this item is shown with the ones above: graphql-Document.salam

SEL_FIELD

const SEL_FIELD: i32 = 0
Selection: a field.

The example for this item is shown with the ones above: graphql-Document.salam

SEL_FRAGMENT_SPREAD

const SEL_FRAGMENT_SPREAD: i32 = 1
Selection: a fragment spread, such as ...Info.

The example for this item is shown with the ones above: graphql-Internals.salam

SEL_INLINE_FRAGMENT

const SEL_INLINE_FRAGMENT: i32 = 2
Selection: an inline fragment, such as ... on Book.

The example for this item is shown with the ones above: graphql-Internals.salam

OP_QUERY

const OP_QUERY: i32 = 0
Operation: query.

The example for this item is shown with the ones above: graphql-Internals.salam

OP_MUTATION

const OP_MUTATION: i32 = 1
Operation: mutation.

The example for this item is shown with the ones above: graphql-Schema.salam

OP_SUBSCRIPTION

const OP_SUBSCRIPTION: i32 = 2
Operation: subscription.

The example for this item is shown with the ones above: graphql-Schema.salam

TOK_EOF

const TOK_EOF: i32 = 0
Token kind: end of the text.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_NAME

const TOK_NAME: i32 = 1
Token kind: a name.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_INT

const TOK_INT: i32 = 2
Token kind: an integer.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_FLOAT

const TOK_FLOAT: i32 = 3
Token kind: a float.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_STRING

const TOK_STRING: i32 = 4
Token kind: a string.

The example for this item is shown with the ones above: graphql-Document.salam

TOK_BLOCK_STRING

const TOK_BLOCK_STRING: i32 = 5
Token kind: a """ block string.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_BANG

const TOK_BANG: i32 = 6
Token kind: !.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_DOLLAR

const TOK_DOLLAR: i32 = 7
Token kind: $.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_AMP

const TOK_AMP: i32 = 8
Token kind: &.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_LPAREN

const TOK_LPAREN: i32 = 9
Token kind: (.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_RPAREN

const TOK_RPAREN: i32 = 10
Token kind: ).

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_SPREAD

const TOK_SPREAD: i32 = 11
Token kind: ....

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_COLON

const TOK_COLON: i32 = 12
Token kind: :.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_EQUALS

const TOK_EQUALS: i32 = 13
Token kind: =.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_AT

const TOK_AT: i32 = 14
Token kind: @.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_LBRACKET

const TOK_LBRACKET: i32 = 15
Token kind: [.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_RBRACKET

const TOK_RBRACKET: i32 = 16
Token kind: ].

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_LBRACE

const TOK_LBRACE: i32 = 17
Token kind: {.

The example for this item is shown with the ones above: graphql-Document.salam

TOK_RBRACE

const TOK_RBRACE: i32 = 18
Token kind: }.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_PIPE

const TOK_PIPE: i32 = 19
Token kind: |.

The example for this item is shown with the ones above: graphql-Internals.salam

TOK_ERROR

const TOK_ERROR: i32 = 20
Token kind: an invalid token.

The example for this item is shown with the ones above: graphql-Internals.salam

TYPE_SCALAR

const TYPE_SCALAR: i32 = 0
Type kind: scalar, such as Int or String.

The example for this item is shown with the ones above: graphql-Schema.salam

TYPE_OBJECT

const TYPE_OBJECT: i32 = 1
Type kind: object.

The example for this item is shown with the ones above: graphql-Schema.salam

TYPE_INTERFACE

const TYPE_INTERFACE: i32 = 2
Type kind: interface.

The example for this item is shown with the ones above: graphql-Schema.salam

TYPE_UNION

const TYPE_UNION: i32 = 3
Type kind: union.

The example for this item is shown with the ones above: graphql-Schema.salam

TYPE_ENUM

const TYPE_ENUM: i32 = 4
Type kind: enum.

The example for this item is shown with the ones above: graphql-Schema.salam

TYPE_INPUT_OBJECT

const TYPE_INPUT_OBJECT: i32 = 5
Type kind: input object.

The example for this item is shown with the ones above: graphql-Schema.salam

Functions

NewSchema

func NewSchema(): Schema
An empty schema with the standard scalar types and directives.

The example for this item is shown with the ones above: graphql-Schema.salam

TypeRefText

func TypeRefText(sch &: Schema, text: str): int
Registers type reference text, such as [Int!], in the schema and returns its number.

The example for this item is shown with the ones above: graphql-Schema.salam

AddScalarType

func AddScalarType(sch &: Schema, name: str, description: str)
Adds a scalar type.

The example for this item is shown with the ones above: graphql-Schema.salam

AddObjectType

func AddObjectType(sch &: Schema, name: str, description: str)
Adds an object type.

The example for this item is shown with the ones above: graphql-Schema.salam

AddInterfaceType

func AddInterfaceType(sch &: Schema, name: str, description: str)
Adds an interface.

The example for this item is shown with the ones above: graphql-Schema.salam

AddInputObjectType

func AddInputObjectType(sch &: Schema, name: str, description: str)
Adds an input type.

The example for this item is shown with the ones above: graphql-Schema.salam

AddEnumType

func AddEnumType(sch &: Schema, name: str, values: Vector<str>)
An enum type with its values.

The example for this item is shown with the ones above: graphql-Schema.salam

AddUnionType

func AddUnionType(sch &: Schema, name: str, members: Vector<str>)
A union with its members.

The example for this item is shown with the ones above: graphql-Schema.salam

AddInterfaceTo

func AddInterfaceTo(sch &: Schema, typeName: str, interfaceName: str)
Adds an interface to the interface list of a type.

The example for this item is shown with the ones above: graphql-Schema.salam

AddField

func AddField(sch &: Schema, typeName: str, fieldName: str, typeText: str): bool
Adds a field with type text such as [Book!]!.

The example for this item is shown with the ones above: graphql-Schema.salam

AddFieldArg

func AddFieldArg(sch &: Schema, typeName: str, fieldName: str, argName: str, typeText: str): bool
Adds an argument to a field.

The example for this item is shown with the ones above: graphql-Schema.salam

AddInputField

func AddInputField(sch &: Schema, typeName: str, fieldName: str, typeText: str): bool
Adds a field to an input type.

The example for this item is shown with the ones above: graphql-Schema.salam

SetRootTypes

func SetRootTypes(sch &: Schema, queryType: str, mutationType: str, subscriptionType: str)
Sets the root types; an empty string means there is none.

The example for this item is shown with the ones above: graphql-Schema.salam

FreeSchema

func FreeSchema(sch &: Schema)
Frees the schema.

The example for this item is shown with the ones above: graphql-Schema.salam

PrintStringValue

func PrintStringValue(s: str): str
Returns the string as an escaped GraphQL string.

The example for this item is shown with the ones above: graphql-Document.salam

PrintTypeRef

func PrintTypeRef(doc: Document, id: int): str
The text of one type reference.

The example for this item is shown with the ones above: graphql-Document.salam

PrintValue

func PrintValue(doc: Document, id: int): str
The text of one value of the document.

The example for this item is shown with the ones above: graphql-Document.salam

Print

func Print(doc: Document): str
Turns the document back into tidy text.

The example for this item is shown with the ones above: graphql-Schema.salam

ParseHttpRequest

func ParseHttpRequest(method: str, contentType: str, body: str, queryString: str): GqlHttpRequest
Reads the request from the method, the content type, the body and the query string; GET, and POST with JSON or application/graphql.

The example for this item is shown with the ones above: graphql-Http.salam

ParseHttpRequestJSON

func ParseHttpRequestJSON(body: str): GqlHttpRequest
Reads a JSON body.

The example for this item is shown with the ones above: graphql-Http.salam

HandleRequest

func HandleRequest(sch: Schema, req: GqlHttpRequest, rootValue: value.Value, ctx: value.Value): ExecutionResult
Runs a request that was already read.

The example for this item is shown with the ones above: graphql-Http.salam

HandleHttp

func HandleHttp(sch: Schema, method: str, contentType: str, body: str, queryString: str, rootValue: value.Value, ctx: value.Value): GqlHttpResponse
Handles an HTTP request from the raw input to the finished response, with a root value and a context.

The example for this item is shown with the ones above: graphql-Http.salam

HandleHttpSimple

func HandleHttpSimple(sch: Schema, method: str, contentType: str, body: str, queryString: str): GqlHttpResponse
Like the function above, without a root value or a context.

The example for this item is shown with the ones above: graphql-Http.salam

FreeHttpRequest

func FreeHttpRequest(req &: GqlHttpRequest)
Frees the request.

The example for this item is shown with the ones above: graphql-Http.salam

NewError

func NewError(category: int, message: str): GqlError
An error with a category and a message.

The example for this item is shown with the ones above: graphql-Schema.salam

NewErrorAt

func NewErrorAt(category: int, message: str, line: int, col: int): GqlError
An error with a line and column.

The example for this item is shown with the ones above: graphql-Document.salam

SyntaxError

func SyntaxError(message: str, line: int, col: int): GqlError
A syntax error with a location.

The example for this item is shown with the ones above: graphql-Schema.salam

PathPushKey

func PathPushKey(e &: GqlError, key: str)
Adds a key to the path of the error.

The example for this item is shown with the ones above: graphql-Document.salam

PathPushIndex

func PathPushIndex(e &: GqlError, idx: int)
Adds an index to the path.

The example for this item is shown with the ones above: graphql-Document.salam

PathLen

func PathLen(e: GqlError): int
The length of the path.

The example for this item is shown with the ones above: graphql-Document.salam

PathString

func PathString(e: GqlError): str
The path in the form books[2].title.

The example for this item is shown with the ones above: graphql-Document.salam

AddError

func AddError(list &: GqlErrorList, e: GqlError)
Adds an error to the list; the list owns the error from then on, so do not free it separately.

The example for this item is shown with the ones above: graphql-Document.salam

HasErrors

func HasErrors(list: GqlErrorList): bool
The list has errors.

The example for this item is shown with the ones above: graphql-Document.salam

ErrorCount

func ErrorCount(list: GqlErrorList): int
How many errors there are.

The example for this item is shown with the ones above: graphql-Document.salam

ErrorAt

func ErrorAt(list: GqlErrorList, i: int): GqlError
Error number n.

The example for this item is shown with the ones above: graphql-Document.salam

ErrorString

func ErrorString(e: GqlError): str
The text of the error with its location and path.

The example for this item is shown with the ones above: graphql-Document.salam

ErrorToValue

func ErrorToValue(e: GqlError): value.Value
The error as a value for a JSON response.

The example for this item is shown with the ones above: graphql-Document.salam

ErrorsToValue

func ErrorsToValue(list: GqlErrorList): value.Value
The list of errors as an array.

The example for this item is shown with the ones above: graphql-Document.salam

FreeError

func FreeError(e &: GqlError)
Frees the error.

The example for this item is shown with the ones above: graphql-Document.salam

FreeErrorList

func FreeErrorList(list &: GqlErrorList)
Frees the list and all its errors.

The example for this item is shown with the ones above: graphql-Document.salam

Parse

func Parse(source: str, err &: GqlError): Document
Parses a query document; when the syntax is wrong, the error is filled in.

The example for this item is shown with the ones above: graphql-Schema.salam

ParseOk

func ParseOk(source: str): bool
The query text is valid.

The example for this item is shown with the ones above: graphql-Document.salam

ParseSchema

func ParseSchema(source: str, err &: GqlError): Schema
Builds a schema from SDL text.

The example for this item is shown with the ones above: graphql-Schema.salam

ParseSchemaInto

func ParseSchemaInto(sch &: Schema, source: str, err &: GqlError)
Adds SDL text, extend type included, to an existing schema.

The example for this item is shown with the ones above: graphql-Schema.salam

ParseSchemaOk

func ParseSchemaOk(source: str): bool
The SDL text is valid.

The example for this item is shown with the ones above: graphql-Schema.salam

IsIntrospectionType

func IsIntrospectionType(name: str): bool
The name is one of the introspection types, such as __Type.

The example for this item is shown with the ones above: graphql-Schema.salam

AddIntrospectionTypes

func AddIntrospectionTypes(sch &: Schema)
Adds the introspection types to the schema so that __schema queries work.

The example for this item is shown with the ones above: graphql-Schema.salam

Validate

func Validate(sch: Schema, doc: Document): GqlErrorList
Validates the document against the schema: missing fields, argument types, undefined variables and the like.

The example for this item is shown with the ones above: graphql-Document.salam

ValidateOk

func ValidateOk(sch: Schema, doc: Document): bool
The document is valid.

The example for this item is shown with the ones above: graphql-Document.salam

ValidateSource

func ValidateSource(sch: Schema, source: str): GqlErrorList
Parses and validates the text.

The example for this item is shown with the ones above: graphql-Document.salam

CollectFields

func CollectFields(sch: Schema, doc: Document, sels: Vector<int>, objectType: str, vars: value.Value): FieldGroups
Turns selections into groups by response key, following fragments and the include and skip directives.

The example for this item is shown with the ones above: graphql-Internals.salam

MergeSelections

func MergeSelections(doc: Document, g: FieldGroup): Vector<int>
Merges the sub selections of a group into one.

The example for this item is shown with the ones above: graphql-Internals.salam

FreeFieldGroups

func FreeFieldGroups(gs &: FieldGroups)
Frees the groups.

The example for this item is shown with the ones above: graphql-Internals.salam

PrintSchema

func PrintSchema(sch: Schema): str
Turns the schema back into SDL, without the built in types.

The example for this item is shown with the ones above: graphql-Schema.salam

PrintSchemaFull

func PrintSchemaFull(sch: Schema): str
Turns the schema into SDL with the built in types.

The example for this item is shown with the ones above: graphql-Schema.salam

PrintType

func PrintType(sch: Schema, name: str): str
The SDL of one type.

The example for this item is shown with the ones above: graphql-Schema.salam

LiteralToValue

func LiteralToValue(sch: Schema, doc: Document, valueId: int, vars: value.Value): CoerceResult
Turns a value of the document into an encoding value, filling in the variables.

The example for this item is shown with the ones above: graphql-Internals.salam

CoerceInput

func CoerceInput(sch: Schema, refDoc: Document, typeRef: int, v: value.Value): CoerceResult
Makes an input value fit the given type.

The example for this item is shown with the ones above: graphql-Internals.salam

CoerceLeafResult

func CoerceLeafResult(sch: Schema, typeName: str, v: value.Value): CoerceResult
Makes the output of a resolver fit a leaf type, such as Int or an enum.

The example for this item is shown with the ones above: graphql-Document.salam

SelectionAt

func SelectionAt(doc: Document, id: int): AstSelection
The selection with this number.

The example for this item is shown with the ones above: graphql-Document.salam

ValueAt

func ValueAt(doc: Document, id: int): AstValue
The value with this number.

The example for this item is shown with the ones above: graphql-Document.salam

TypeRefAt

func TypeRefAt(doc: Document, id: int): AstTypeRef
The type reference with this number.

The example for this item is shown with the ones above: graphql-Document.salam

FindOperation

func FindOperation(doc: Document, name: str): int
The number of the operation with this name; an empty name means the only operation. -1 when there is none.

The example for this item is shown with the ones above: graphql-Document.salam

FindFragment

func FindFragment(doc: Document, name: str): int
The number of the fragment with this name.

The example for this item is shown with the ones above: graphql-Document.salam

OperationTypeName

func OperationTypeName(optype: int): str
The name of the operation: query, mutation or subscription.

The example for this item is shown with the ones above: graphql-Document.salam

ResponseKey

func ResponseKey(sel: AstSelection): str
The key of a selection in the response: the alias, or the field name when there is none.

The example for this item is shown with the ones above: graphql-Document.salam

FreeDocument

func FreeDocument(doc &: Document)
Frees the document.

The example for this item is shown with the ones above: graphql-Document.salam

Tokenize

func Tokenize(source: str, ok &: bool): GqlTokenStream
Breaks the text into tokens.

The example for this item is shown with the ones above: graphql-Document.salam

LexOk

func LexOk(source: str): bool
The text has no lexical errors.

The example for this item is shown with the ones above: graphql-Document.salam

BuildRequestBody

func BuildRequestBody(queryText: str, operationName: str, variables: value.Value): str
The JSON body of a POST request.

The example for this item is shown with the ones above: graphql-Http.salam

BuildQueryBody

func BuildQueryBody(queryText: str): str
A JSON body with only the query.

The example for this item is shown with the ones above: graphql-Http.salam

BuildRequestQueryString

func BuildRequestQueryString(queryText: str, operationName: str, variables: value.Value): str
The query string for a GET request.

The example for this item is shown with the ones above: graphql-Http.salam

ParseResponse

func ParseResponse(body: str): ClientResponse
Reads the JSON response of the server.

The example for this item is shown with the ones above: graphql-Http.salam

ResponseField

func ResponseField(r: ClientResponse, name: str): value.Value
A field of the response data.

The example for this item is shown with the ones above: graphql-Http.salam

ResponseOk

func ResponseOk(r: ClientResponse): bool
The response has no errors.

The example for this item is shown with the ones above: graphql-Http.salam

ResponseErrorMessage

func ResponseErrorMessage(r: ClientResponse): str
The message of the first error.

The example for this item is shown with the ones above: graphql-Http.salam

FreeClientResponse

func FreeClientResponse(r &: ClientResponse)
Frees the response.

The example for this item is shown with the ones above: graphql-Http.salam

SetResolver

func SetResolver(sch &: Schema, typeName: str, fieldName: str, fn: i64): bool
Registers a function for a field of a type; the function takes the slot number. A field without a resolver returns the value of the same name from the parent object.

The example for this item is shown with the ones above: graphql-Execute.salam

HasResolver

func HasResolver(sch: Schema, typeName: str, fieldName: str): bool
The field has a resolver.

The example for this item is shown with the ones above: graphql-Execute.salam

Parent

func Parent(slot: i64): value.Value
The parent object.

The example for this item is shown with the ones above: graphql-Execute.salam

Args

func Args(slot: i64): value.Value
The arguments as an object.

The example for this item is shown with the ones above: graphql-Internals.salam

Context

func Context(slot: i64): value.Value
The context given to the execution; the signed in user, for instance.

The example for this item is shown with the ones above: graphql-Http.salam

FieldName

func FieldName(slot: i64): str
The field name.

The example for this item is shown with the ones above: graphql-Http.salam

ParentTypeName

func ParentTypeName(slot: i64): str
The name of the parent type.

The example for this item is shown with the ones above: graphql-Http.salam

HasArg

func HasArg(slot: i64, name: str): bool
The argument was given.

The example for this item is shown with the ones above: graphql-Execute.salam

Arg

func Arg(slot: i64, name: str): value.Value
The argument as a value.

The example for this item is shown with the ones above: graphql-Schema.salam

ArgInt

func ArgInt(slot: i64, name: str): i64
An integer argument.

The example for this item is shown with the ones above: graphql-Execute.salam

ArgFloat

func ArgFloat(slot: i64, name: str): f64
A float argument.

The example for this item is shown with the ones above: graphql-Execute.salam

ArgStr

func ArgStr(slot: i64, name: str): str
A string argument.

The example for this item is shown with the ones above: graphql-Execute.salam

ArgBool

func ArgBool(slot: i64, name: str): bool
A boolean argument.

The example for this item is shown with the ones above: graphql-Execute.salam

ParentField

func ParentField(slot: i64, name: str): value.Value
A field of the parent object.

The example for this item is shown with the ones above: graphql-Execute.salam

Resolve

func Resolve(slot: i64, v: value.Value)
Sets the result to a value.

The example for this item is shown with the ones above: graphql-Execute.salam

ResolveInt

func ResolveInt(slot: i64, n: i64)
An integer result.

The example for this item is shown with the ones above: graphql-Execute.salam

ResolveFloat

func ResolveFloat(slot: i64, f: f64)
A float result.

The example for this item is shown with the ones above: graphql-Execute.salam

ResolveStr

func ResolveStr(slot: i64, s: str)
A string result.

The example for this item is shown with the ones above: graphql-Execute.salam

ResolveBool

func ResolveBool(slot: i64, b: bool)
A boolean result.

The example for this item is shown with the ones above: graphql-Execute.salam

ResolveNull

func ResolveNull(slot: i64)
A null result.

The example for this item is shown with the ones above: graphql-Execute.salam

Fail

func Fail(slot: i64, message: str)
Ends the field with an error; the field becomes null and the error comes back in the response with its path.

The example for this item is shown with the ones above: graphql-Execute.salam

ResetSlots

func ResetSlots()
Frees the resolver slots.

The example for this item is shown with the ones above: graphql-Execute.salam

TokenKindName

func TokenKindName(kind: int): str
The name of a token kind.

The example for this item is shown with the ones above: graphql-Document.salam

IsStringToken

func IsStringToken(kind: int): bool
The kind is a string or a block string.

The example for this item is shown with the ones above: graphql-Document.salam

Execute

func Execute(sch: Schema, doc: Document, operationName: str, variables: value.Value, rootValue: value.Value, ctx: value.Value): ExecutionResult
Runs a parsed document with an operation name, variables, a root value and a context.

The example for this item is shown with the ones above: graphql-Document.salam

ExecuteSource

func ExecuteSource(sch: Schema, source: str, operationName: str, variables: value.Value, rootValue: value.Value, ctx: value.Value): ExecutionResult
Like the function above, from text.

The example for this item is shown with the ones above: graphql-Execute.salam

Run

func Run(sch: Schema, source: str): ExecutionResult
Runs the text without variables.

The example for this item is shown with the ones above: graphql-Execute.salam

SetExtensions

func SetExtensions(r &: ExecutionResult, ext: value.Value)
Sets the extensions of the result.

The example for this item is shown with the ones above: graphql-Internals.salam

ResultToValue

func ResultToValue(r: ExecutionResult): value.Value
The result as a value.

The example for this item is shown with the ones above: graphql-Internals.salam

ResultToJSON

func ResultToJSON(r: ExecutionResult): str
The result as JSON.

The example for this item is shown with the ones above: graphql-Execute.salam

ResultToJSONIndent

func ResultToJSONIndent(r: ExecutionResult): str
Readable JSON with indentation.

The example for this item is shown with the ones above: graphql-Internals.salam

ResultToJSONStable

func ResultToJSONStable(r: ExecutionResult): str
JSON with sorted keys; for tests and comparisons.

The example for this item is shown with the ones above: graphql-Execute.salam

ResultOk

func ResultOk(r: ExecutionResult): bool
It ran without errors.

The example for this item is shown with the ones above: graphql-Execute.salam

ResultErrorMessage

func ResultErrorMessage(r: ExecutionResult): str
The message of the first error.

The example for this item is shown with the ones above: graphql-Execute.salam

FreeResult

func FreeResult(r &: ExecutionResult)
Frees the result.

The example for this item is shown with the ones above: graphql-Execute.salam

TypeRefIsNonNull

func TypeRefIsNonNull(doc: Document, id: int): bool
The reference is non null.

The example for this item is shown with the ones above: graphql-Document.salam

TypeRefIsList

func TypeRefIsList(doc: Document, id: int): bool
The reference is a list.

The example for this item is shown with the ones above: graphql-Document.salam

TypeRefElement

func TypeRefElement(doc: Document, id: int): int
The reference of the list element.

The example for this item is shown with the ones above: graphql-Internals.salam

TypeRefName

func TypeRefName(doc: Document, id: int): str
The name of the base type, without the list and the !.

The example for this item is shown with the ones above: graphql-Document.salam

FindType

func FindType(s: Schema, name: str): TypeDef
The definition of the type with this name.

The example for this item is shown with the ones above: graphql-Schema.salam

HasType

func HasType(s: Schema, name: str): bool
The type exists.

The example for this item is shown with the ones above: graphql-Schema.salam

TypeIndex

func TypeIndex(s: Schema, name: str): int
The number of the type; -1 when there is none.

The example for this item is shown with the ones above: graphql-Schema.salam

TypeCount

func TypeCount(s: Schema): int
How many types there are.

The example for this item is shown with the ones above: graphql-Schema.salam

TypeAt

func TypeAt(s: Schema, i: int): TypeDef
Type number n.

The example for this item is shown with the ones above: graphql-Schema.salam

FindField

func FindField(t: TypeDef, name: str): FieldDef
A field of a type.

The example for this item is shown with the ones above: graphql-Schema.salam

HasField

func HasField(t: TypeDef, name: str): bool
The type has this field.

The example for this item is shown with the ones above: graphql-Schema.salam

FindInputField

func FindInputField(t: TypeDef, name: str): InputValueDef
A field of an input type.

The example for this item is shown with the ones above: graphql-Schema.salam

FindArg

func FindArg(f: FieldDef, name: str): InputValueDef
An argument of a field.

The example for this item is shown with the ones above: graphql-Schema.salam

FindDirectiveDef

func FindDirectiveDef(s: Schema, name: str): DirectiveDef
The definition of a directive.

The example for this item is shown with the ones above: graphql-Schema.salam

HasEnumValue

func HasEnumValue(t: TypeDef, name: str): bool
The enum type has this value.

The example for this item is shown with the ones above: graphql-Schema.salam

IsInputType

func IsInputType(s: Schema, name: str): bool
The type is allowed in inputs.

The example for this item is shown with the ones above: graphql-Schema.salam

IsOutputType

func IsOutputType(s: Schema, name: str): bool
The type is allowed in outputs.

The example for this item is shown with the ones above: graphql-Schema.salam

IsAbstractType

func IsAbstractType(s: Schema, name: str): bool
It is an interface or a union.

The example for this item is shown with the ones above: graphql-Schema.salam

IsLeafType

func IsLeafType(s: Schema, name: str): bool
It is a scalar or an enum.

The example for this item is shown with the ones above: graphql-Schema.salam

IsPossibleType

func IsPossibleType(s: Schema, abstractName: str, objectName: str): bool
The object type can stand in for this interface or union.

The example for this item is shown with the ones above: graphql-Schema.salam

PossibleTypes

func PossibleTypes(s: Schema, name: str): Vector<str>
The object types that can stand in for an interface or union.

The example for this item is shown with the ones above: graphql-Schema.salam

RootTypeName

func RootTypeName(s: Schema, optype: int): str
The name of the root type of an operation.

The example for this item is shown with the ones above: graphql-Schema.salam