This package assist with a basic SDK for developing applications on top of Alpaca Travel GraphQL API via urql.
Via NPM:
npm install urql graphql graphql-tag @alpaca-travel/graph-sdk-react-urql --save
Via Yarn:
yarn add urql graphql graphql-tag @alpaca-travel/graph-sdk-react-urql
In order to configure your application for development with urql
, you'll need
to refer to the
the urql basics. You'll
learn how to setup urql with React/Preact, Vue, Svelte or other.
// Obtain your Alpaca Access Token
const alpacaAccessToken = "pk.xxx";
// Create a urql
const client = createClient({
url: `https://withalpaca.com/api/graphql?accessToken={alpacaAccessToken}`,
});
The capabilities of the API are documented using typedoc.
You can leverage the tool graphql-codegen
in order to generate additional
hooks and capability for your application.
Install graphql-codegen and the related libraries to your project
npm install -D @graphql-codegen/cli @graphql-codegen/fragment-matcher @graphql-codegen/introspection @graphql-codegen/jsdoc @graphql-codegen/typescript @graphql-codegen/typescript-operations @graphql-codegen/typescript-urql
See the graphql-codegen configuration for an example of the configuration used for generating out the SDK.
- Copy the
codegen-typescript-example.yml
file ascodegen.yml
in your workspace - Create the folder in
src/graphql
and place in your graphql operations - Add the script
"graphql-codegen": "graphql-codegen --config codegen.yml"
to your package.json "scripts" section - Run
npm run graphql-codegen
to generate your ownsrc/graphql/index.ts
file
The benefit of using graphql-codegen is that your Typescript types will be created, as well as providing the API surface for you to call without embedding your GraphQL queries/mutations within the component.