Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 1.02 KB

File metadata and controls

32 lines (24 loc) · 1.02 KB

dataloader-codegen Example: Star Wars API (SWAPI)

Shows an example of a GraphQL Server using dataloader-codegen. Prints data from https://swapi.dev.

Try it out locally!

Clone dataloader-codegen and build locally:

$ git clone git@github.com:Yelp/dataloader-codegen.git
$ cd dataloader-codegen
$ make build
$ yarn link

Build the example:

$ cd examples/swapi
$ yarn
$ yarn link dataloader-codegen
$ make swapi-loaders.ts
$ make build
# Prints out a GraphQL query result:
$ node build/swapi-server.js

File Layout:

  • swapi-loaders.js: An autogenerated file by dataloader-codegen. Contains the codegen'd dataloaders. (Checked in to git so folks can easily see an example of the generated code).
  • swapi.js: A set of functions to fetch data from https://swapi.dev/. This is analogous to a library generated by openapi-generator/swagger-codegen.
  • swapi-server.js: The dummy GraphQL server! This imports the dataloaders from swapi-loaders.js. At present, it just prints the result of a query to stdout.