Code Monkey home page Code Monkey logo

graphql-samples's Introduction

Use quicktype to make statically typed GraphQL queries

The samples in this repository demonstrate how to use quicktype to do statically typed GraphQL queries to the GitHub API.

With traditional REST APIs, you have to make multiple queries to collect the data needed by your app. For example, to get the followers for all of a user’s GitHub repos, you’d first query for a list of the user’s repos, then perform a query for each repo to get the followers. For a user with n repos, that’s n+1 queries, which means your app will be slow and will need a cumbersome UI (e.g. loading spinners, lazy lists).

With GraphQL, on the other hand, you specify exactly what information you want up front, so you get all the data your app needs in a single query. Given a bunch of those queries, quicktype can generate the exact static types for the responses from the server.

Folders

  • schema contains all the input files for quicktype. Most importantly, there's the GraphQL query. The setup script will also download the GraphQL schema into this folder. The file request.schema contains a JSON Schema definition of the very simple JSON that's used to send the GraphQL query to the server.

  • csharp and typescript contain the code and project files for the C# and TypeScript samples, respectively. The setup script will also invoke quicktype to generate code into those folders.

MacOS and Linux

Install quicktype

First, make sure you have quicktype installed. On MacOS you can install it via Homebrew like this:

brew install quicktype

If you're on Linux, or you prefer NPM:

npm install -g quicktype

Get an authentication token

Follow these steps to generate an authentication token and write it into the file auth-token:

echo TOKEN >auth-token

Run the setup script

./setup.sh

You should see it downloading the GraphQL schema and then generating code.

Try the samples

To run the C# sample with .NET Core, do

cd csharp
dotnet run

For the TypeScript sample, do

cd typescript
npm install
npm start

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.