0.1.6 • Published 3 years ago

nuxt-github-api v0.1.6

Weekly downloads
11
License
MIT
Repository
github
Last release
3 years ago

nuxt-github-api

npm version npm downloads Github Actions CI Codecov License

Source plugin for pulling data into Nuxt from the official GitHub v4 GraphQL API. Data is fetched at build time, and can be used to create static assets.

📖 Release Notes

Setup

  1. Follow GitHub's guide to generate a token.
  2. Add this token to your environment variables (PLEASE don't commit this token!!!)
  3. Add nuxt-github-api dependency to your project
yarn add nuxt-github-api -D # or npm install nuxt-github-api --save-dev
  1. Add the following configuration to your nuxt.config.js file:
{
  privateRuntimeConfig: {
    // githubApiToken: required by the GitHub API
    githubApiToken: process.env.GITHUB_TOKEN
  },
  buildModules: [
    'nuxt-github-api',
  ],
  githubApi: {
    // graphQLQuery: defaults to a search query
    graphQLQuery: `
      query GetUser($login: String!) {
        user(login: $login) {
          name
          avatarUrl
          bio
          isHireable
        }
      }
    `,
    
    // variables: Object which includes any GraphQL variables required by your query.
    variables: {
      login: 'lindsaykwardell'
    }
  }
}

In your Vue components, you can now access this data on this.$github. For example:

<template>
  <div>
    <div>
      <img :src="$github.user.avatarUrl" />
      <h2>{{ $github.user.name }}</h2>
      <h4>{{ $github.user.bio }}</h4>
      <p>{{ lookingForAJob }}</p>
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    lookingForAJob() {
      return this.$github.user.isHireable
        ? 'Looking for a great place to work!'
        : 'Not currently looking for a job'
    }
  }
}
</script>

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Create .env file at the root of the project.
  4. Add variable: GITHUB_TOKEN
  5. Start development server using npm run dev

License

MIT License

Copyright (c) Lindsay Wardell

Tips and Tricks

You'll probably want to use valid GraphQL queries. To help you, GitHub has a Query Explorer with auto-completion.

Query Explorer