pokeapi icon indicating copy to clipboard operation
pokeapi copied to clipboard

Implement GraphQL

Open jonatasbaldin opened this issue 6 years ago • 7 comments

Hi there!

I was thinking about implementing GraphQL (with Graphene) in the PokeAPI, what do you think about that?

jonatasbaldin avatar Jul 25 '17 02:07 jonatasbaldin

Hi there,

Someone has done this already I believe! See https://github.com/pfaze/graphql-workshop. I haven't looked at it but you may want to check that out before starting on it yourself :)

You could also come join us in Slack to discuss if you like - see https://pokeapi-slack-invite.herokuapp.com/ for an invite.

tdmalone avatar Jul 25 '17 03:07 tdmalone

Implementing a GraphQL server would be awesome since you only request resources you actually need. Could be called, Pokeapi v3

Try to communicate with @pfaze, @jonatasbaldin

Naramsim avatar Jul 25 '17 10:07 Naramsim

@tdmalone I think this implementation is just an example, not implementing everything. Also, it's on nodejs, I think we could do it in Python.

@Naramsim would be awesome indeed, but don't need the v3, since GraphQL is another unique endpoint, we can keep both it and v2 running side by side.

Anyways, will join the Slack and start de discussion there.

jonatasbaldin avatar Jul 25 '17 12:07 jonatasbaldin

Yeah, for sure, right now we are running v1 and v2 versions

Naramsim avatar Jul 25 '17 15:07 Naramsim

Hi!

My implementation was meant as an introduction into GraphQL as well as building apps with nodejs. Wanted something nicer then a hello world example so I used pokeapi as a backend for it :). So not a full implementation of the api :). I might add some more features to it in the future as I am using it in some of the workshops I give at my job.

Having a dedicated GraphQL api for pokeapi would be great! Would support it if help is wanted/needed :).

pfaze avatar Jul 26 '17 08:07 pfaze

Hi all, @phalt,

I recently started working on a GraphQL endpoint for the PokéAPI. I am using Graphene and DataLoader to batch-fetch data from the database (so a large query with many nested fields might make only a few db requests, rather than hundreds). I aim to make it fully-Relay compliant so that it works with the two major client libraries (Relay and Apollo).

Here is my code. Currently, the schema only includes a subset of all the PokéAPI data, but all of it is fully tested. I've pretty much dialled-in how I want to do it all, so it's mostly a matter of adding more types to the schema, then adding the documentation pages to the website. The schema types I have finished include:

  • Generation
  • Version
  • VersionGroup
  • Location
  • LocationArea
  • Region
  • Language
  • EncounterMethod
  • and other associated types.

The schema code is organised in a fractal-style manner, rather than in one 5000 line file. This should make it easier to write tests for and generally find your way around the code. It's all written in Python2 like everything else, but @SiddharthaMishra is apparently working on updating to Python3, so if that gets done I'll convert my code too.

I welcome your feedback.


In my first attempt (which can be found in this branch), I went full steam ahead without writing any tests or figuring out what exactly I need to do, so the code is a steamy hot mess (though the schema includes pretty much every type and field). I decided to step back and get a subset of the full schema working how I want it first, so I don't have to go back and modify several thousand lines of code when I realise I've done something wrong.

This turned out to be a much greater challenge than I thought it would be when I started out, because I'm new to Python and GraphQL, and because Graphene's documentation is close to non-existent, but I'm getting there.

cmmartti avatar Jun 02 '18 23:06 cmmartti

After looking for an implementation I decided to try to provide one by myself. This effort can be found at https://github.com/jotatoledo/PokeGraphQL which is an implementation in .NET Core

~~ATM the query type fields for list resources with pagination are missing, but its the next feature in my TODO :)~~

jotatoledo avatar Jul 14 '19 23:07 jotatoledo