Norse Polytheistic Mythology
    Have ideas to improve npm?Join in the discussion! »

    github-apiv4
    TypeScript icon, indicating that this package has built-in type declarations

    2.2.0 • Public • Published

    Github-APIv4

    travis build npm version

    API | Contribute | FAQ

    Github-APIv4 is a Node library that provides a list of Github graphql (APIv4) queries and their respective return types.

    Getting Started

    Installation

    To use Github-APIv4, run:

    npm i github-apiv4
    # or "yarn add github-apiv4" 

    Usage

    Javascript Example - query Viewer:

    Save file as exampleJS.js

    const githubApiv4 = require('github-apiv4');
    const fetch = require('isomorphic-fetch');
    const accessCode = 'YOUR_GITHUB_ACCESS_CODE';
     
    fetch('https://api.github.com/graphql', {
      method: 'POST',
      headers: { 
          'Content-Type': 'application/json',
          'Authorization': `bearer ${accessCode}`
      },
      body: JSON.stringify({ query: githubApiv4.queries.Viewer }),
    })
      .then(res => res.json())
      .then(res => console.log(res.data));

    Github API response (res.data is) of type githubApiv4.types.Viewer

    Execute script on the command line

    node exampleJS.js

    Typescript Example - query Viewer:

    Save file as exampleTS.ts

    import * as githubApiv4 from 'github-apiv4';
    import * as fetch from 'isomorphic-fetch';
     
    const accessCode = 'YOUR_GITHUB_ACCESS_CODE';
     
    fetch('https://api.github.com/graphql', {
      method: 'POST',
      headers: { 
          'Content-Type': 'application/json',
          'Authorization': `bearer ${accessCode}`
      },
      body: JSON.stringify({ query: githubApiv4.queries.Viewer }),
    })
      .then(res => res.json())
      .then(res => {
          if((res.data as githubApiv4.types.Viewer).viewer){
            console.log(res.data)
          }else{
            console.log('Type Mismatch!');
          }
      })

    Github API response (res.data is) of type githubApiv4.types.Viewer

    Execute script on the command line

    tsc exampleTS.ts
    node exampleTS.js

    Apollo Client Example - query Repository:

    Save file as apolloClient.ts

    import * as githubApiV4 from 'github-apiv4';
    import { HttpLink } from 'apollo-link-http';
    import ApolloClient from 'apollo-client';
    import { InMemoryCache, IntrospectionFragmentMatcher, NormalizedCacheObject } from 'apollo-cache-inmemory';
    import { fetch } from 'cross-fetch';
    import gql from "graphql-tag";
     
    const accessCode = 'YOUR_GITHUB_ACCESS_CODE';
    const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
        link: new HttpLink({ uri: 'https://api.github.com/graphql', fetch }),
        cache: new InMemoryCache({
            fragmentMatcher: new IntrospectionFragmentMatcher({
              introspectionQueryResultData: {
                __schema: {
                  types: [],
                },
              },
            }),
          }),
    });
     
    // query variables used in repository query (githubApiV4.queryVariables.Repository)
    const queryVariables: githubApiV4.queryVariables.Repository = {
        repositoryName: 'github-apiv4',
        repositoryOwner: 'community'
    };
     
    // query with apollo-client
    client.query({
        query: gql`${githubApiV4.queries.Repository}`,
        variables: queryVariables,
        context: {
            headers: {
                Authorization: `bearer ${accessCode}`
            }
        }
    }).then(res=>{
        if(res.data as githubApiV4.types.Repository){
            console.log(res.data);
        }else{
            console.log('Type Mismatch!');
        }
    });

    Github API response (res.data is) of type githubApiv4.types.Repository

    Execute script on the command line

    tsc apolloClient.ts
    node apolloClient.js

    Resources

    Contribute

    Contributing to Github-APIv4

    Check out contributing guide to get an overview of github-apiv4 development.

    FAQ

    Questions?

    Install

    npm i github-apiv4

    DownloadsWeekly Downloads

    2

    Version

    2.2.0

    License

    MIT

    Unpacked Size

    816 kB

    Total Files

    65

    Last publish

    Collaborators

    • avatar