0.15.0 • Published 9 months ago

@liontari.ai/samarium v0.15.0

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

GitHub last commit NPM Version NPM Downloads

Nothing would be more convenient than just importing the API as Typescript SDK. Now you can.

Quickstart

1. Compile the API to Typescript

npx @liontari.ai/samarium # this will start the assistant ui

2. Import the API as Typescript SDK

import sdk from "./spacex"; // the file you created in the previous step

3. Use the SDK

const { first10Launches } = await sdk((op) =>
    op.query((q) => ({
        first10Launches: q.launches({ limit: 10 })(({ id }) => ({ id })),
    })),
);

Documentation & Examples

Documentation is available here. Additonally, you can take a look at the examples in the examples folder.

If you are interested in the technical details, you can take a look at the tests. They are commented and cover all the features.

Also, feel free to open an issue if you need more examples or have questions.

Try it in the browser

In the playground you can compile your own GraphQL API by providing the introspection endpoint. It will fetch the schema, generate the sdk and load an editor with typescript.

You can execute the code and see console.log outputs, as well as the network requests.

Note: Right now the playground does not support authentication or headers. The CLI will prompt you for the authentication if needed and allows for more customization.

Online Playground is available here.

Features

Implemented GraphQL features:

FeatureSupportedDescription
QueriesQueries are fully typed functions.
MutationsAll mutations are fully typed functions just like queries.
VariablesAll arguments used in queries and mutations are collected and hoisted to the top level as variables.
AliasesAliases are supported for all fields.
Multiple operationsMultiple operations in a single query are supported. You can even mix queries and mutations. Just make sure to name them. They are sent in the order they are defined.
... on TypeInline fragments on Union types. (see https://github.com/liontariai/samarium/pull/5 for an example)
FragmentsFragments are supported. As implicit and explicit fragments, also parameterized fragments (see https://github.com/graphql/graphql-spec/issues/204) are supported. ( see https://github.com/liontariai/samarium/pull/6 for more information)
Directives(Client) Directives are supported. Use the $directives helper functions and wrap your selected field.

Not yet implemented GraphQL features:

FeatureSupportedDescription
SubscriptionsSubscriptions are not supported right now, because no websocket client has been chosen yet. The query text itself could be generated, but executing it would require a websocket client and a nice way to execute it. If you are interested in this, please open an issue.

Utility features:

FeatureSupportedDescription
AuthenticationProvide a way to authenticate the requests.
Custom scalar typesSupport for custom scalar types, like Date, so that these scalars are deserialized upon using them in the code. (see https://github.com/liontariai/samarium/pull/3 for more info)
Lazy QueriesQueries can be lazified into async functions, so that they are only executed when awaited. Just use the .$lazy property. Also, you can pass arguments to the lazy function. See https://github.com/liontariai/samarium/pull/10
Lazy MutationsMutations can be lazified into async functions, so that they are only executed when awaited. Just use the .$lazy property. Also, you can pass arguments to the lazy function. See https://github.com/liontariai/samarium/pull/10
Shortcuts for selectionsProvide helper functions to select all or specific fields of a type without writing them all out in the selection.

Support the project

If you like the project, please consider giving it a star on GitHub. This helps to get the word out and to get more contributors on board. You can also reach me on x.com/liontariai for any questions or feedback.

Feedback

Feedback is highly appreciated. Please open an issue if you have questions or suggestions!

0.15.0

9 months ago

0.15.0-beta.2

9 months ago

0.15.0-beta.1

9 months ago

0.14.0

9 months ago

0.12.0

10 months ago

0.13.0

10 months ago

0.13.1

9 months ago

0.11.3

10 months ago

0.11.4

10 months ago

0.11.2

10 months ago

0.11.0

10 months ago

0.11.1

10 months ago

0.10.1

11 months ago

0.10.0

12 months ago

0.9.1

1 year ago

0.9.0

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.11

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago