npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alpaca-travel/graph-sdk-graphql-request

v2.1.5

Published

> This package assist with a basic SDK for developing applications on top of > Alpaca Travel GraphQL API via graphql-request.

Downloads

8

Readme

Alpaca Travel GraphQL SDK for graphql-request

This package assist with a basic SDK for developing applications on top of Alpaca Travel GraphQL API via graphql-request.

Installation

Via NPM:

npm install graphql-request graphql graphql-tag @alpaca-travel/graph-sdk-graphql-request --save

Via Yarn:

yarn add graphql-request graphql graphql-tag @alpaca-travel/graph-sdk-graphql-request

Typescript Types

The SDK includes typescript types to assist you in working with data responses.

Getting Started

The below shows a way to create a SDK instance with a configured graphql-request client.

import { GraphQLClient } from 'graphql-request';
import { getSdk } from '@alpaca-travel/graph-sdk-graphql-request';

// Create a graphql-client
// Note: Substitute your API Access Token
const client = new GraphQLClient(`https://withalpaca.com/api/graphql?accessToken=xxx`);

// Initialise the SDK
const sdk = getSdk(client);

Example call

// Call in an itinerary
const data = await sdk.getItinerary({ id: 'itinerary/123' });

// Console log the total count
console.log(data.itinerary.locations.totalCount);

API Documentation

See API Docs

Extending Functionality

The SDK is driven by a number of GraphQL documents. You can fork this project if you wish to extend your own queries and mutations as documented on the GraphQL Documentation and consider self-hosting for your use case or submitting a pull-request.

GraphQL Calls via graphql-request

You can craft your own GraphQL queries following the documentation available for Alpaca GraphQL.

Using graphql-request, you can make your requests as needed;

/**
 * Make a GraphQL request using the graphql-request client outside of the SDK
 * capabilities. Needed if you want to extend the SDK capabilities or perform
 * a specific GraphQL call.
 */

const query = gql`
  # My custom Alpaca GraphQL call
  query getAuthorizedProfiles {
    query
    authorizedProfiles(first: 1) {
      nodes {
        id
        name
      }
    }
  }
`;
// Perform a query
client.request(query).then((data) => console.log(data));

Using graphql-codegen

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-graphql-request

See the graphql-codegen configuration for an example of the configuration used for generating out the SDK.

  1. Copy the codegen-typescript-example.yml file as codegen.yml in your workspace
  2. Create the folder in src/graphql and place in your graphql operations
  3. Add the script "graphql-codegen": "graphql-codegen --config codegen.yml" to your package.json "scripts" section
  4. Run npm run graphql-codegen to generate your own src/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.

Further Reading