Giter Site home page Giter Site logo

linecode / tql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timkendall/tql

0.0 1.0 0.0 2.96 MB

A GraphQL query builder for TypeScript. Avoid the pain of codegen.

Home Page: https://tql.dev

License: MIT License

JavaScript 11.90% TypeScript 86.00% CSS 2.09%

tql's Introduction

TQL

๐Ÿšง We are getting close to 1.0 but this is still pre-production software at this point, see the current limitations.

tql is a TypeScript GraphQL query builder.

  • ๐Ÿ”’ Fully Type-safe - Operation results and variables are fully type-safe thanks to TypeScript's advanced type-system.
  • ๐Ÿ”Œ Backendless: - Integrate with any GraphQL client to execute queries.
  • ๐Ÿ”ฎ Automatic Variables: - Variable definitions are automatically derived based on usage.
  • ๐Ÿ“ Inline Documentation: JSDoc comments provide descriptions and deprecation warnings for fields directly in your editor.
  • โšก Single Dependency: graphql-js is our single runtime (peer) dependency.

Try it Out

Try out our pre-compiled Star Wars GraphQL SDK on CodeSandbox!

Installation

  1. npm install @timkendall/tql@beta

  2. Generate an SDK with npx @timkendall/tql-gen <schema> > sdk.ts

Usage

Import selector functions to start defining queries ๐ŸŽ‰

import { useQuery } from '@apollo/client'

// SDK generated in previous setup
import { character, query, $ } from './starwars'

// define reusable selections
const CHARECTER = character(t => [
  t.id(),
  t.name(),
  t.appearsIn(),
])

const QUERY = query((t) => [
  t.reviews({ episode: Episode.EMPIRE }, (t) => [
    t.stars(),
    t.commentary(),
  ]),

  t.human({ id: $('id') }, (t) => [
    t.__typename(),
    t.id(),
    t.name(),
    t.appearsIn(),
    t.homePlanet(),

    // deprecated field should be properly picked-up by your editor
    t.mass(),

    t.friends((t) => <const>[
      t.__typename(),
      
      ...CHARECTER,
      // or
      CHARECTER.toInlineFragment(),

      t.on("Human", (t) => [t.homePlanet()]),
      t.on("Droid", (t) => [t.primaryFunction()]),
    ]),

    t.starships((t) => [t.id(), t.name()]),
  ]),
]).toQuery({ name: 'Example' })

// type-safe result and variables ๐Ÿ‘
const { data } = useQuery(QUERY, { variables: { id: '1011' }})

Inspiration

I was inspired by the features and DSL's of graphql-nexus, graphql_ppx, gqless, and caliban.

License

MIT

tql's People

Watchers

 avatar

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.