• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extensive Pokémon GraphQL API

ArchAngel

GraphQL-Pokemon

Extensive Pokémon GraphQL API!

GitHub

npm

Support Server


Table of Contents


About

GraphQL-Pokemon is a GraphQL API that provides extensive Pokémon data. Unlike contemporary APIs this API focusses on speed, accuracy and data quality. New game data is added within relatively short time after release, and Smogon tier data is automatically updated after tier shifts. Data used for this API is pulled from the Pokemon Showdown GitHub, Serebii, and Bulbapedia.

Key Features

  • Fully generated client-side TypeScript typings published to
  • Docker images of the API for private hosting published to
  • Provides information about various assets in Pokémon
    • Pokédex
    • Items
    • Abilities
    • Moves
    • Learnsets
    • Type matchups

Installation

Note: This is only needed if you are writing TypeScript, or if you're using a GraphQL schema validator. If you're using neither of these, you do not need to install this package. The package does NOT include the actual API, ONLY type information.

Install client side typings from yarn or npm:

yarn add -D @favware/graphql-pokemon
npm install -D @favware/graphql-pokemon

API Documentation

There are two ways to consume the documentation that this API offers. They are as follows.

Autogenerated text based documentation

For those who want purely text based documentation about all the GraphQL Queries and Types that are in this API, including a documentation search for those symbols, please see the autogenerated GraphQL Docs powered by magidoc.

Interactive playground with documentation embedded

For those who want an interactive playground where they can directly test their queries and read about each query as they select them, please use the GraphQL Playground on the API.

Usage

These examples are written as based on TypeScript. For JavaScript simply change out the imports to require syntax and remove any type information.

Using Fetch

note: for a working example see dragonite

import type { Query } from '@favware/graphql-pokemon';

interface GraphQLPokemonResponse<K extends keyof Omit<Query, '__typename'>> {
  data: Record<K, Omit<Query[K], '__typename'>>;
}

fetch('https://graphqlpokemon.favware.tech/v7', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    query: `
      {
        getPokemon(pokemon: dragonite) {
            sprite
            num
            species
            color
        }
      }
    `
  })
})
  .then((res) => res.json() as Promise<GraphQLPokemonResponse<'getPokemon'>>)
  .then((json) => console.log(json.data));

Using Apollo Boost

note: for a working example see dexa

import type { Query, QueryGetFuzzyPokemonArgs } from '@favware/graphql-pokemon';
import ApolloClient from 'apollo-boost';
import fetch from 'cross-fetch';
import gql from 'graphql-tag';

type GraphQLPokemonResponse<K extends keyof Omit<Query, '__typename'>> = Record<
  K,
  Omit<Query[K], '__typename'>
>;

const getFuzzyPokemon = gql`
  query getFuzzyPokemon($pokemon: String!) {
    getFuzzyPokemon(pokemon: $pokemon) {
      sprite
      num
      species
      color
    }
  }
`;

const apolloClient = new ApolloClient({
  uri: 'https://graphqlpokemon.favware.tech/v7',
  fetch
});

const {
  data: { getFuzzyPokemon: pokemonData }
} = await apolloClient.query<
  GraphQLPokemonResponse<'getFuzzyPokemon'>,
  QueryGetFuzzyPokemonArgs
>({
  query: getFuzzyPokemon,
  variables: { pokemon: 'dragonite' }
});

console.log(pokemonData);

Using Apollo Client React

// ApolloClient setup
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';

// Instantiate required constructor fields
const cache = new InMemoryCache();
const link = new HttpLink({
  uri: 'https://graphqlpokemon.favware.tech/v7'
});

export const client = new ApolloClient({
  // Provide required constructor fields
  cache: cache,
  link: link,

  // Provide some optional constructor fields
  name: 'graphql-pokemon-client',
  version: '1.0',
  queryDeduplication: false,
  defaultOptions: {
    watchQuery: {
      fetchPolicy: 'cache-and-network'
    }
  }
});
// Component
import React from 'react';
import gql from 'graphql-tag';
import { useQuery } from '@apollo/react-hooks';
import type { Query } from '@favware/graphql-pokemon';
import { client } from './ApolloClient';

interface GraphQLPokemonResponse<K extends keyof Omit<Query, '__typename'>> {
  data: Record<K, Omit<Query[K], '__typename'>>;
}

const GET_POKEMON_DETAILS = gql`
  {
    getPokemon(pokemon: dragonite) {
      sprite
      num
      species
      color
    }
  }
`;

export const Pokemon: React.FC = () => {
  const { loading, error, data } = useQuery<
    GraphQLPokemonResponse<'getPokemon'>
  >(GET_POKEMON_DETAILS, {
    client: client
  });

  if (loading) return 'Loading...';
  if (error) return `Error! ${error.message}`;

  return <div> Insert how you want to display the data here </div>;
};

Meta

License

Copyright © 2019, Favware. Released under the MIT License.

Buy us some doughnuts

Favware projects is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Ko-fi, Paypal, Patreon, GitHub Sponsorships, and various crypto currencies. You can use the buttons below to donate through your method of choice.

Donate With Address
Ko-fi Click Here
Patreon Click Here
PayPal Click Here
GitHub Sponsors Click Here
Bitcoin 1E643TNif2MTh75rugepmXuq35Tck4TnE5
Ethereum 0xF653F666903cd8739030D2721bF01095896F5D6E
LiteCoin LZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6

Contributors

Please make sure to read the Contributing Guide before making a pull request.

Thank you to all the people who already contributed to GraphQL-Pokemon!

More Repositories

1

cliff-jumper

CLI tool to create a semantic release, git-cliff powered Changelog, and releases to GitHub all in one
TypeScript
43
star
2

dragonite

A Pokémon information Discord bot built around Discord Interactions
TypeScript
21
star
3

esbuild-plugin-file-path-extensions

An esbuild plugin to automatically insert file extensions in your built JavaScript files based on the specified target
TypeScript
21
star
4

skip-dependency

Skip pesky NodeJS dependencies with ease
JavaScript
20
star
5

npm-deprecate

Programmatically deprecate your NPM published packages matching specified criteria
TypeScript
13
star
6

rollup-type-bundler

A small CLI tool to bundle types with rollup
TypeScript
10
star
7

esbuild-plugin-version-injector

An esbuild plugin to inject your application's version number or today's date into your files
TypeScript
9
star
8

colorette-spinner

A super tiny and efficient terminal spinner based on nanospinner
TypeScript
7
star
9

node-packages

Node packages by Favware, all in one convenient monorepo.
TypeScript
6
star
10

discord-application-emojis-manager

A NodeJS CLI to manage emojis for Discord Applications
TypeScript
6
star
11

ssh-remote-action

A GitHub action for executing a SSH command on a remote server
Shell
6
star
12

zsh-lerna

Autocompletion ZSH plugin for Lerna
Shell
5
star
13

archangel

Custom Discord Bot for Populous Gaming
TypeScript
5
star
14

codespaces-containers

Zero-Config Docker containers designed for GitHub Codespaces
Dockerfile
4
star
15

create-djsbot

⚡Bootstrapping CLI tool for quickly setting up a Discord bot project
TypeScript
3
star
16

zsh-git-enhanced

Enhanced Git aliases for oh-my-zsh
Shell
3
star
17

java-result

A Java implementation of a Result monad inspired by Rust's Result struct.
Java
1
star
18

yarnts-template

Template repository for Yarn and TypeScript based Node libraries
TypeScript
1
star