-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(document-builder): strip $ on enum-typed variables (#1288)
- Loading branch information
1 parent
4e8b69c
commit 04d98c6
Showing
24 changed files
with
892 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* This example shows how to work with the selection set types generated by Graffle. Selection set types reflect your GraphQL schema. | ||
*/ | ||
|
||
import { Graffle } from '../$/graffle/__.js' | ||
import { showJson } from '../$/helpers.js' | ||
|
||
type _ = [ | ||
// | ||
// ======================== | ||
// Primary TypeScript Types | ||
// ======================== | ||
// | ||
// | ||
// 1. GraphQL Types | ||
// -------------- | ||
// The SelectionSets namespace contains a TypeScript type for each GraphQL type. | ||
// | ||
Graffle.SelectionSets.Query, | ||
Graffle.SelectionSets.Mutation, | ||
Graffle.SelectionSets.Battle, | ||
// ... | ||
// | ||
// Each type contains the selection set for that type. | ||
// | ||
Graffle.SelectionSets.Query['pokemons'], | ||
Graffle.SelectionSets.Query['trainers'], | ||
Graffle.SelectionSets.Mutation['addPokemon'], | ||
Graffle.SelectionSets.Battle['___on_BattleRoyale'], | ||
|
||
// 2. GraphQL Type Fields | ||
// ------------------- | ||
// Each name is also overloaded with a namespace. Within it, you will find more TypeScript types. | ||
// One per selection set field in the respective GraphQL type. | ||
// | ||
Graffle.SelectionSets.Query.pokemons, | ||
Graffle.SelectionSets.Query.trainers, | ||
Graffle.SelectionSets.Mutation.addPokemon, | ||
// ... | ||
// | ||
// Each GraphQL type field type has properties about the selection set set for that field. | ||
// | ||
Graffle.SelectionSets.Query.pokemons['$'], | ||
Graffle.SelectionSets.Query.trainers['$skip'], | ||
Graffle.SelectionSets.Mutation.addPokemon['id'], | ||
// ... | ||
// | ||
// You may have already noticed but there is a relationship between these two things: | ||
// - The GraphQL Type type properties | ||
// - The GraphQL Type Field types. | ||
// | ||
// Use the kind of type that suites your use case. | ||
// | ||
Graffle.SelectionSets.Query['pokemons'], | ||
Graffle.SelectionSets.Query.pokemons, | ||
// | ||
// 3. TypeScript Types for Arguments | ||
// ------------------------------ | ||
// There are type definitions for GraphQL Type Field Arguments | ||
// | ||
Graffle.SelectionSets.Query.pokemons$Arguments, | ||
Graffle.SelectionSets.Query.trainerByName$Arguments, | ||
Graffle.SelectionSets.Mutation.addPokemon$Arguments, | ||
// ... | ||
// | ||
// | ||
// ====================== | ||
// Niche TypeScript Types | ||
// ====================== | ||
// | ||
// | ||
// 4. "Expanded" Variants | ||
// ------------------- | ||
// You will find various type definitions with the suffix `$Expanded`. | ||
// From a type-checking point of view they are identical to their non-expanded form. | ||
// They differ in how they will be displayed in tooling, namely IDEs. | ||
// You can leverage them to improve DX in your use-cases. | ||
// For more details, refer to their JSDoc. | ||
// | ||
Graffle.SelectionSets.Query.pokemons$Expanded, | ||
Graffle.SelectionSets.Mutation.addPokemon$Expanded, | ||
// ... | ||
// | ||
// 5. Inline Fragments | ||
// ---------------- | ||
// | ||
Graffle.SelectionSets.Query$FragmentInline, | ||
Graffle.SelectionSets.Battle$FragmentInline, | ||
// ... | ||
// | ||
// 6. Selection Sets Sans Union with Indicators | ||
// ----------------------------------------- | ||
// If the GraphQL field is a non-scalar OR scalar-with-arguments, then its type will be synonymous | ||
// with its explicit selection set type. For example: | ||
// | ||
Graffle.SelectionSets.Query.beings, | ||
Graffle.SelectionSets.Query.beings$SelectionSet, | ||
// However, if the GraphQL field IS a scalar-without-arguments, then its type will become an | ||
// indicator unioned with the "meta" selection set (meaning stuff like field directives). | ||
// | ||
// Meanwhile, the explicit selection set type will _only_ have those meta things, not the | ||
// indicator. For example: | ||
// | ||
Graffle.SelectionSets.Pokemon.name, | ||
Graffle.SelectionSets.Pokemon.name$SelectionSet, | ||
] | ||
|
||
const graffle = Graffle.create() | ||
|
||
const getPokemonsLike = async (filter: Graffle.SelectionSets.Query.pokemons$Arguments['filter']) => | ||
graffle.query.pokemons({ | ||
$: { filter }, | ||
hp: true, | ||
name: true, | ||
}) | ||
|
||
// todo add test coverage for $ stripping on arguments. | ||
const pokemons = await getPokemonsLike({ $type: `water` }) | ||
|
||
// We don't lose any type safety. :) | ||
showJson(pokemons) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
---------------------------------------- SHOW ---------------------------------------- | ||
[ | ||
{ | ||
"hp": 44, | ||
"name": "Squirtle" | ||
} | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.