|
| 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 | +``` |
0 commit comments