Giter Club home page Giter Club logo

genql's Introduction





Type safe Graphql query builder

Write Graphql queries with type validation and auto completion



Read the quick start guide to generate your client and start writing queries.

You can stay up to date with the latest changes subscribing to the Genql changelog.

Features

Example

First generate your client with the genql cli.

You can find other cli options here

npm i -D @genql/cli # cli to generate the client code
genql --schema ./schema.graphql --output ./generated

Then you can use your client as follow

import { createClient, everything } from './generated'
const client = createClient()

client
    .query({
        countries: {
            // pass arguments to the query
            __args: {
                filter: {
                    currency: {
                        eq: 'EUR',
                    },
                },
            },
            name: true,
            code: true,
            nestedField: {
                // fetch all scalar fields
                __scalar: true,
            },
        },
    })
    .then(console.log)

The code above will fetch the graphql query below

query {
    countries(filter: { currency: { eq: "EUR" } }) {
        name
        code
        nestedField {
            scalarField1
            scalarField2
        }
    }
}

Why

Genql has a lot of benefits over writing graphql queries by hand:

  • Writing queries is faster thanks to TypeScript auto completion
  • You can safely update your schema and be sure your queries are still valid
  • You can fetch all scalar fields in a type with __scalar: true
  • No graphql package dependency, no runtime parsing of queries
  • You have to generate the client only after your schema changes, not after every query change

Sponsors

Notaku

Notaku

Vercel


Licensed under MIT.

genql's People

Contributors

remorses avatar bump-version avatar wellguimaraes avatar boredland avatar julien-r44 avatar ruheni avatar benjaminbradley avatar danielrose avatar dhmacs avatar

Watchers

 avatar

Forkers

rematter

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.