Grapher v0.6.0 Grapher.Document.Store View Source
Manages Saving, Updating and Lookup of GraphQL Documents. The Document Store uses an :ets
table to store all documents. From the perspective of the Store a Document is a combination of a name
and a Grapher.Document.t
struct. The name is typically either an atom
or a String.t
.
Link to this section Summary
Functions
Adds a new query document to the store under the given name. If a document already exists with that name then :document_exists
is returned and nothing changes in the store
Retrieves a document from the Store by name, if there is no document with that name then :no_such_document
will be returned
Updates an existing query document in the Store. If the given name is not associated with a document this function returns :no_such_document
Link to this section Functions
add_document(Grapher.name(), Grapher.Document.t()) :: :ok | :document_exists
Adds a new query document to the store under the given name. If a document already exists with that name then :document_exists
is returned and nothing changes in the store.
Parameters
name
: An atom that should be used to refer to the given documentdocument
: The actual query document
Examples
iex> Store.add_document(:add_test, "query testQuery($id: ID!) { testQuery(id: $id) { id }}")
:ok
iex> Store.add_document(:add_test2, "query {}")
iex> Store.add_document(:add_test2, "query {}")
:document_exists
get(Grapher.name()) :: Grapher.Document.t() | :no_such_document
Retrieves a document from the Store by name, if there is no document with that name then :no_such_document
will be returned.
Parameters
name
: the name of the query which should be returned
Examples
iex> Store.get(:missing)
:no_such_document
iex> Store.add_document(:get, "query {}")
iex> Store.get(:get)
"query {}"
update_document(Grapher.name(), Grapher.Document.t()) :: :ok | :no_such_document
Updates an existing query document in the Store. If the given name is not associated with a document this function returns :no_such_document
Parameters
name
: An atom refering to the document to be updateddocument
: The new document that should be stored undername
Examples
iex> Store.update_document(:missing, "query {}")
:no_such_document
iex> Store.add_document(:update, "query {}")
iex> Store.update_document(:update, "query { query() {}}")
:ok