Skip to content

Commit b983084

Browse files
committed
Supporting files
0 parents  commit b983084

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/dist

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# GraphQL SOCK
2+
3+
SOCK: **Semantic Output Conversion Kit**
4+
5+
## What is it?
6+
7+
**Takes as input a GraphQL SDL and outputs a derived SDL wherein all
8+
semantic-non-null type modifiers have either been removed
9+
(`semantic-to-nullable`) or have been replaced with strict (traditional)
10+
non-null modifiers (`semantic-to-strict`).**
11+
12+
In the latest proposals around semantic nullability, we introduce a new
13+
"Semantic Non Null" type modifier that means that the value is "null only on
14+
error". However, not all tools support this yet, so this library contains tools
15+
to convert a modern SDL into a more traditional one, to be used for code
16+
generation and other such functionality.
17+
18+
Which command you use will depend on your setup; if you're using `graphql-toe`
19+
then you'll want `semantic-to-strict` to really capitalize on the benefits of
20+
semantic nullability. If you just want to use a semantic nullability SDL with
21+
traditional tools that don't yet understand it, then `semantic-to-nullable`
22+
will just strip out the semantic-non-null types for you.
23+
24+
## Installation
25+
26+
Pick the line that relates to your package manager:
27+
28+
```bash
29+
npm install --save graphql-sock
30+
yarn add graphql-sock
31+
pnpm install --save graphql-sock
32+
```
33+
34+
## Usage
35+
36+
### `semantic-to-nullable`
37+
38+
If a value is "null only on error" then it can be null. This conversion strips
39+
all semantic-non-null type wrappers from the SDL, making a schema that appears
40+
as it traditionally would. This means that you won't reap any of the benefits
41+
of semantic nullability, but you can support existing tools.
42+
43+
```
44+
semantic-to-nullable -i input.graphql -o output.graphql
45+
```
46+
47+
### `semantic-to-strict`
48+
49+
If you're using [graphql-toe](https://github.com/graphile/graphql-toe) or a
50+
similar technique that means that when you read from an errored field the error
51+
will be thrown, then it will not be possible for you to read a `null` from a
52+
"null only on error" position. As such, this position becomes equivalent to a
53+
traditional non-null for you, so this conversion converts all semantic-non-null
54+
type wrappers into traditional non-null wrappers. Your type generators can
55+
therefore generate fewer nullables, and your frontend engineers have to do
56+
fewer null checks and are therefore happier.
57+
58+
```
59+
semantic-to-strict -i input.graphql -o output.graphql
60+
```

package.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "graphql-sock",
3+
"version": "0.0.0",
4+
"description": "GraphQL Semantic Output Conversion Kit - converts a cutting edge SDL file that supports semantic nullability into a more traditional SDL file legacy tools can support.",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"test": "node --test"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https+git://github.com/graphile/graphql-sock.git"
12+
},
13+
"bugs": {
14+
"url": "https://github.com/graphile/graphql-sock/issues"
15+
},
16+
"homepage": "https://github.com/graphile/graphql-sock",
17+
"keywords": [
18+
"graphql",
19+
"throw",
20+
"error",
21+
"errors",
22+
"raise",
23+
"exception",
24+
"semantic",
25+
"null",
26+
"non-null",
27+
"nullability",
28+
"null",
29+
"only",
30+
"on",
31+
"error",
32+
"sdl",
33+
"schema",
34+
"convert",
35+
"strip"
36+
],
37+
"author": "Benjie Gillam <[email protected]>",
38+
"license": "MIT",
39+
"dependencies": {
40+
"graphql": "^16.9.0-canary.pr.4192.1813397076f44a55e5798478e7321db9877de97a"
41+
},
42+
"devDependencies": {
43+
"@tsconfig/recommended": "^1.0.7",
44+
"@types/node": "^22.5.4",
45+
"prettier": "^3.3.3",
46+
"typescript": "^5.6.2"
47+
},
48+
"prettier": {
49+
"proseWrap": "always"
50+
},
51+
"files": [
52+
"dist"
53+
]
54+
}

tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@tsconfig/recommended/tsconfig.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"rootDir": "src",
6+
"declarationDir": "./dist",
7+
"outDir": "./dist"
8+
}
9+
}

yarn.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@tsconfig/recommended@^1.0.7":
6+
version "1.0.7"
7+
resolved "https://registry.yarnpkg.com/@tsconfig/recommended/-/recommended-1.0.7.tgz#fdd95fc2c8d643c8b4a8ca45fd68eea248512407"
8+
integrity sha512-xiNMgCuoy4mCL4JTywk9XFs5xpRUcKxtWEcMR6FNMtsgewYTIgIR+nvlP4A4iRCAzRsHMnPhvTRrzp4AGcRTEA==
9+
10+
"@types/node@^22.5.4":
11+
version "22.5.5"
12+
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.5.tgz#52f939dd0f65fc552a4ad0b392f3c466cc5d7a44"
13+
integrity sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==
14+
dependencies:
15+
undici-types "~6.19.2"
16+
17+
graphql@^16.9.0-canary.pr.4192.1813397076f44a55e5798478e7321db9877de97a:
18+
version "16.9.0"
19+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.9.0.tgz#1c310e63f16a49ce1fbb230bd0a000e99f6f115f"
20+
integrity sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==
21+
22+
prettier@^3.3.3:
23+
version "3.3.3"
24+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.3.tgz#30c54fe0be0d8d12e6ae61dbb10109ea00d53105"
25+
integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==
26+
27+
typescript@^5.6.2:
28+
version "5.6.2"
29+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0"
30+
integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==
31+
32+
undici-types@~6.19.2:
33+
version "6.19.8"
34+
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
35+
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==

0 commit comments

Comments
 (0)