Did you know ... | Search Documentation: |
graphql.pl -- GraphQL interface |
This module provides predicates for working with GraphQL, a query language for HTTP-based APIs.
Document is a Prolog term representing the abstract syntax tree of the GraphQL document, as obtained from e.g. graphql_read_document/3 or graphql/4 quasi-quotation. Result is unified with a dict representing the JSON formatted response received from the server.
The following example shows how graphql_execute_document/4 can be used to expose a simple GraphQL interface to Prolog:
sourcehut_repository_description(Owner, Repo, Desc) :- graphql_execute_document("https://git.sr.ht/query", {| graphql(Owner, Repo) || { user(username: <Owner>) { repository(name: <Repo>) { description } } } |}, Dict, [token(...)]), Desc = Dict.get(data/user/repository/description). ?- sourcehut_repository_description("eshel", "sourcehut.pl", Desc). Desc = "SWI-Prolog package implementing a SourceHut GraphQL API client.".
Options is a list whose elemenets are one of the following:
$key
.
Variables is sent to the remote to the GraphQL endpoint in
JSON format for server-side interpolation.
For more information about GraphQL variables, see
https://spec.graphql.org/draft/#sec-Language.variable_names(+VarNames)
in graphql_read_document/3.
Result is a term representing the given GraphQL document in the same format as used by graphql_read_document/3.
Document is a list of terms representing GraphQL executable definitions, each being one of:
VariableDefinitions is a list of terms of the form
variable_definition(VarName, VarType, VarDefault, VarDirs)
where VarName is a string denoting the name of the variable,
VarType is a term denoting the GraphQL type of the defined
variable in the format described below, VarDefault is a term
denoting a default GraphQL value associated with the defined
variable, and VarDirs is a possibly empty list of GraphQL
directives, each of which a term DirName-DirArgs where DirName
is the string name of the directive and DirArgs is a Prolog
dict denoting the directive arguments.
Directives is a possibly empty list of GraphQL directives associated with the given GraphQL operation.
SelectionSet is a list of GraphQL selections, each selection
is one of field(FieldAlias, FieldName, FieldArgs, FieldDirs,
FieldSelection)
, in which case FieldAlias is either null or
a string denoting the alias of the field, FieldName is a
string denoting the name of the field, FieldArgs is a dict
denoting the field arguments, FieldDirs is a list of GraphQL
directives and FieldSelection is a list of GraphQL
selections nested below the given field. Otherwise, each
selection can have the from fragment_spread(FragName,
FragDirs)
where FragName is a string denoting the name of
the fragment and FragDirs is a possibly empty list of GraphQL
directives. Lastly, each selection can have the form
inline_fragment(IFragTypeCondition, IFragDirs,
IFragSelectionSet)
where IFragTypeCondition is a string
denoting a type condition associated with the inline fragment,
IFragDirs denotes GraphQL directives associated with it,
and IFragSelectionSet is a list of GraphQL selections
specified by the fragment.
A GraphQL type is represented as one of:
A GraphQL value is represented as one of:
true
value.false
value.null
value.Source can be one of:
codes(Codes, [])
.Options is a list whose elements can be one of:
Occurences of the special lexical construct "<Name>" (that is, ASCII 60, then the codes of the atom Name, then ASCII 62) in Source are expanded in Document to the GraphQL value Value. This option can be used to interpolate GraphQL documents with values given in Prolog representation.
Options are passed on to graphql_document_to_codes/3.
Options are a list whose elements are one of:
separator(`, `)
.