Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic reference docs for createHttpClient #918

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
95 changes: 95 additions & 0 deletions docs/reference.rst
Expand Up @@ -114,6 +114,101 @@ Client
main();


.. js:function:: createHttpClient(options?: string | ConnectOptions | null): Client

Creates an HTTP client for interacting with an EdgeDB instance from a browser or edge runtime environment. This function returns an instance of :js:class:`Client` configured to communicate over HTTP using the Fetch API.

:param options:
This is an optional parameter. When it is not specified the client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is an optional parameter. When it is not specified the client
This is an optional parameter. When it is not specified, the client

will connect to the current EdgeDB Project instance.

If this parameter is a string it can represent either a
Comment on lines +123 to +125
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newlines here get collapsed. In the rendered output, "If" is directly against the preceding period with nothing between. I've started a thread about it on Slack. Seems like a bug in the docs.

DSN or an instance name:

* when the string does not start with ``edgedb://`` it is a
:ref:`name of an instance <ref_reference_connection_instance_name>`;

* otherwise it specifies a single string in the connection URI format:
``edgedb://user:password@host:port/database?option=value``.

See the :ref:`Connection Parameters <ref_reference_connection>`
docs for full details.

Alternatively the parameter can be a ``ConnectOptions`` config;
see the documentation of valid options below.

:param string options.dsn:
Specifies the DSN of the instance.

:param string options.credentialsFile:
Path to a file containing credentials.

:param string options.host:
Database host address as either an IP address or a domain name.

:param number options.port:
Port number to connect to at the server host.

:param string options.user:
The name of the database role used for authentication.

:param string options.database:
The name of the database to connect to.

:param string options.password:
Password to be used for authentication, if the server requires one.

:param string options.tlsCAFile:
Path to a file containing the root certificate of the server.

:param boolean options.tlsSecurity:
Determines whether certificate and hostname verification is enabled.
Valid values are ``'strict'`` (certificate will be fully validated),
``'no_host_verification'`` (certificate will be validated, but
hostname may not match), ``'insecure'`` (certificate not validated,
self-signed certificates will be trusted), or ``'default'`` (acts as
``strict`` by default, or ``no_host_verification`` if ``tlsCAFile``
is set).

The above connection options can also be specified by their corresponding
environment variable. If none of ``dsn``, ``credentialsFile``, ``host`` or
``port`` are explicitly specified, the client will connect to your
linked project instance, if it exists. For full details, see the
:ref:`Connection Parameters <ref_reference_connection>` docs.


:param number options.timeout:
Connection timeout in milliseconds.
Comment on lines +164 to +181
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this got rendered as you intended, but I'm not sure if I'd call this a bug in the docs site, or if we just need to rework the documentation.

CleanShot 2024-03-25 at 11 12 33@2x

We get another "Arguments" heading before options.timeout. I think we would just want to continue the arguments list after the paragraph about connection options without another heading. I can't think of a case where we would want the current behavior, but I wanted to check in with you and see what you think. I guess if there's an easy fix we can make here we should do that. I'm not sure there is though.

The easy "fix" would be indenting it, maybe as a note inside the description of one of the params, but it's relevant to multiple params so I don't think that really works here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, all of this is copied wholesale from the createClient docs, so any issues here are also issues there, I'd imagine. Definitely good with taking the time to update these docs both in layout and content though!


:param number options.waitUntilAvailable:
If first connection fails, the number of milliseconds to keep retrying
to connect (Defaults to 30 seconds). Useful if your development
instance and app are started together, to allow the server time to
be ready.

:param number options.concurrency:
The maximum number of connection the ``Client`` will create in it's
connection pool. If not specified the concurrency will be controlled
by the server. This is recommended as it allows the server to better
manage the number of client connections based on it's own available
resources.

:returns:
Returns an instance of :js:class:`Client`.

Example:

.. code-block:: js

const client = edgedb.createHttpClient();

async function main() {
const data = await client.querySingle("select 1 + 1");
console.log(data); // Outputs: 2
}

main();

.. js:class:: Client

A ``Client`` allows you to run queries on an EdgeDB instance.
Expand Down