Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Ast rewrite (#88)
Browse files Browse the repository at this point in the history
* Star rewriting on standard graphql-js AST

* Add result 3

* Use Node 16

* Add pnpm-lock.yaml

* Fix intelliscence nullability

* Fix Result type nullability

* Rename type tests

* Refactor Result type

* Fix example add critical comment

* Helpful comment

* Implement fragment support idea

* Simplify inline fragment implementation

* Fix simple-scalar type test

* Actually implement SpreadFragments correctly

* Fix union test

* Add a little complexity to union test

* Get deep Variables working

* Add variables in fragments test

* Patch type tests

* Implement Selection runtime class

* Add simple parameterized schema type test

* Remove unneeded comments

* Re-implement most of codegen

* Implement codegen extends

* Pass through variable type parameters

* Update .gitignore

* Support ReadonlyArray in schemas

* Remove unneeded files

* Generate inline fragment selectior fns

* Use TypedDocumentNode from @apollo/client

* Comment out codegen test

* Update readme and docs

* Split codegen into seperate package

* Uncomment Variables tests

* Remove codegen prepublish and prepush cmds

* Set tql-gen to 1.0.0-rc.1

* Add description to tql-gen

* Remove prepublish and prepush cmds

* Add sideEffects false to package.json

* Update README and limitations doc
  • Loading branch information
timkendall committed Nov 25, 2021
1 parent 0409e72 commit fe1a113
Show file tree
Hide file tree
Showing 79 changed files with 6,703 additions and 154,265 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '14'
node-version: '16'

- name: 'Cache node_modules'
uses: actions/cache@v2
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/manual.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '14'
node-version: '16'

- name: 'Cache node_modules'
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '14'
node-version: '16'

- uses: olegtarasov/get-tag@v2.1
id: tagName
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,7 @@ dist

notes.txt

failing-examples
failing-examples

sdk.ts
*_test.ts
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.15.0
v16
14 changes: 9 additions & 5 deletions CURRENT_LIMITATIONS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Current Limitations

## required for 1.0
## Required for 1.0
- [x] Interface type support
- [x] Nested input object support
- [x] Union type support
- [x] `mutation` or `subscription` operation support
- [x] Nullable field support
- [ ] Variable definition support

## perhaps in 1.x
- [x] Variable definition support
- [x] Rewrite `Result` and `Variable` types
- [x] Type-level testing
- [x] Default unknown scalars to `string`'s
- [ ] Restricing `Selection`'s in selector function returns
- [ ] Finish rewriting unit tests
- [ ] Field alias support
- [ ] Directive support
- [ ] Custom scalar support yet (e.g no `Date` objects), limited to JS built-ins (custom scalars default to `string`'s)
- [ ] Named fragments
- [ ] Custom scalar support yet (e.g no `Date` objects), limited to JS built-ins.
- [ ] Documentation
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
# TQL

> Note: this is **pre-production software** at this point, see the **[current limitations](./CURRENT_LIMITATIONS.md)**.
> 🚧 We are getting close to `1.0` but this is still **pre-production software** at this point, see the **[current limitations](./CURRENT_LIMITATIONS.md)**.
**tql** is a TypeScript GraphQL query builder.

- **Codegen once** - regenerate your GraphQL API client only when your schema changes.
- **Fully type-safe** - take advantage of the full power of TypeScript's advanced type-system.
- **Backendless** - integrate with any existing GraphQL client.

## [Try it Out](https://repl.it/@timkendall/TQL-Starwars)
## [Try it Out](https://codesandbox.io/s/tql-starwars-wlfg9?file=/src/index.ts&runonclick=1)

Try out our pre-compiled Star Wars GraphQL client on [Repl.it](https://repl.it/)!
Try out our pre-compiled Star Wars GraphQL SDK on [CodeSandbox](https://codesandbox.io/s/tql-starwars-wlfg9?file=/src/index.ts&runonclick=1)!

## Installation

`npm install @timkendall/tql` or `yarn add @timkendall/tql`
1. `npm install @timkendall/tql@beta`

* **TypeScript 4.1+** is required for [Recursive Conditional Type](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#recursive-conditional-types) support
* **TypeScript 4.1+** is required for [Recursive Conditional Type](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#recursive-conditional-types) support

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

## Usage

You will need to compile a type-safe client one time before using. Do this with the provided CLI:

`yarn --silent tql <schema> > example.api.ts`.
## Usage

Import selector functions to start defining queries 🎉

```typescript
import { query } from './example.api'
import { useQuery } from '@apollo/client'

const operation = query("Example", (t) => [
// SDK generated in previous setup
import { query, $ } from './starwars'

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

t.human({ id: "1002" }, (t) => [
t.human({ id: $('id') }, (t) => [
t.__typename(),
t.id(),
t.name(),
Expand All @@ -45,7 +47,7 @@ const operation = query("Example", (t) => [
// @note Deprecated field should be properly picked-up by VSCode!
t.mass(),

t.friends((t) => [
t.friends((t) => <const>[
t.__typename(),
t.id(),
t.name(),
Expand All @@ -57,7 +59,11 @@ const operation = query("Example", (t) => [

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

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

```

## Inspiration
Expand Down
7 changes: 7 additions & 0 deletions __tests__/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Integration Tests

We use the canonical [graphql/swapi-graphql](https://github.com/graphql/swapi-graphql) API as our top-level integration tests. You can configure the test suite to run against your own schema by following the instructions below. If you find a bug please [open an issue](https://github.com/timkendall/tql/issues/new)!.

## Running

`yarn test:int <schema>` (defaults to the Starwars schema defined here)
174 changes: 0 additions & 174 deletions __tests__/__snapshots__/schemas.test.ts.snap

This file was deleted.

Loading

0 comments on commit fe1a113

Please sign in to comment.