gql.tada 0.0.0 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,21 +1,115 @@
1
1
  <div align="center">
2
- <h2>gql.tada 🎉</h2>
3
- <strong>The spec-compliant & magical GraphQL query language engine in the TypeScript type system</strong>
2
+ <h2>gql.tada 🪄</h2>
3
+ <strong>Magical GraphQL query engine for TypeScript</strong>
4
4
  <br />
5
5
  <br />
6
- <a href="https://github.com/0no-co/gql.tada/actions/workflows/release.yml">
7
- <img alt="CI Status" src="https://github.com/0no-co/gql.tada/actions/workflows/release.yml/badge.svg?branch=main" />
8
- </a>
9
- <a href="https://urql.dev/discord">
10
- <img alt="Discord" src="https://img.shields.io/discord/1082378892523864074?color=7389D8&label&logo=discord&logoColor=ffffff" />
11
- </a>
6
+ <a href="https://github.com/0no-co/gql.tada/actions/workflows/release.yml"><img alt="CI Status" src="https://github.com/0no-co/gql.tada/actions/workflows/release.yml/badge.svg?branch=main" /></a>
7
+ <a href="https://urql.dev/discord"><img alt="Discord" src="https://img.shields.io/discord/1082378892523864074?color=7389D8&label&logo=discord&logoColor=ffffff" /></a>
12
8
  <br />
13
9
  <br />
14
10
  </div>
15
11
 
16
- **Work in Progress**
12
+ `gql.tada` is a GraphQL document authoring library, inferring the result and variables types
13
+ of GraphQL queries and fragments in the TypeScript type system. It derives the types for your
14
+ GraphQL queries on the fly allowing you to write type-safe GraphQL documents quickly.
17
15
 
18
- ## Shortcomings
16
+ In short, `gql.tada`,
19
17
 
20
- - [ ] support having parsed parts in a document, like a fragment reference
21
- - [ ] support defining custom scalars
18
+ - parses your GraphQL documents in the TypeScript type system
19
+ - uses your introspected schema and scalar configuration to derive a schema
20
+ - maps your GraphQL queries and fragments with the schema to result and variables types
21
+ - creates fragment masks and enforces unwrapping fragments gradually
22
+
23
+ Since this is all done in the TypeScript type system and type checker, this all happens
24
+ while you edit your GraphQL front-end code and is always accurate.
25
+
26
+ ### Let’s take a look!
27
+
28
+ ```ts
29
+ import { graphql } from 'gql.tada';
30
+ import { myIntrospectionQuery } from './fixtures/introspection';
31
+
32
+ // We can declare our introspected schema once globally
33
+ declare module 'gql.tada' {
34
+ interface setupSchema {
35
+ introspection: typeof myIntrospectionQuery;
36
+ }
37
+ }
38
+
39
+ // Creates fragment documents
40
+ const fragment = graphql(`
41
+ fragment HelloWorld extends Query {
42
+ hello
43
+ world
44
+ }
45
+ `);
46
+
47
+ // Creates queries, optionally accepting a list of fragments for fragment spreads
48
+ const query = graphql(
49
+ `
50
+ {
51
+ hello
52
+ ...HelloWorld
53
+ }
54
+ `,
55
+ [fragment]
56
+ );
57
+ ```
58
+
59
+ ## 💾 Setup
60
+
61
+ Install `gql.tada` using your project’s package manager,
62
+
63
+ ```sh
64
+ npm i gql.tada
65
+ pnpm add graphql
66
+ yarn add gql.tada
67
+ bun add graphql
68
+ ```
69
+
70
+ `gql.tada` infers the types of your queries. However, it can’t provide you with editor feedback,
71
+ like autocompletion, diagnostics & errors, and hover information inside GraphQL queries.
72
+ For the best experience, it’s recommended to install [GraphQLSP](https://github.com/0no-co/graphqlsp)
73
+ to supplement these features.
74
+
75
+ Install `@0no-co/graphqlsp` as a dev dependency,
76
+
77
+ ```sh
78
+ npm i -D gql.tada
79
+ pnpm add -D graphql
80
+ yarn add --dev gql.tada
81
+ bun add --dev graphql
82
+ ```
83
+
84
+ Then, update your `tsconfig.json` to enable the `graphqlsp` plugin in your TypeScript server,
85
+
86
+ **tsconfig.json**
87
+
88
+ ```diff
89
+ {
90
+ "compilerOptions": {
91
+ + "plugins": [
92
+ + {
93
+ + "name": "@0no-co/graphqlsp",
94
+ + "schema": "./schema.graphql"
95
+ + }
96
+ + ]
97
+ }
98
+ }
99
+ ```
100
+
101
+ > **Note:**
102
+ > If you are using VSCode, you may want to update your `.vscode/config.json` file to use the
103
+ > [use the **workspace version** of TypeScript](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript)
104
+ > automatically.
105
+ >
106
+ > **.vscode/config.json**
107
+ >
108
+ > ```diff
109
+ > {
110
+ > + "typescript.tsdk": "node_modules/typescript/lib",
111
+ > + "typescript.enablePromptUseWorkspaceTsdk": true
112
+ > }
113
+ > ```
114
+
115
+ <!-- TODO -->